103 lines
4.1 KiB
Java
103 lines
4.1 KiB
Java
package com.thebrokenrail.energonrelics.block.entity.infuser;
|
|
|
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
|
import net.minecraft.item.DyeItem;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.Items;
|
|
import net.minecraft.util.DyeColor;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.registry.Registry;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
public class InfuserRegistry {
|
|
private static final Map<Item, InfuserEntry> map = new HashMap<>();
|
|
|
|
static InfuserEntry get(Item item) {
|
|
return map.get(item);
|
|
}
|
|
|
|
private static void add(Item item, InfuserEntry entry) {
|
|
map.put(item, entry);
|
|
}
|
|
|
|
public static Set<Map.Entry<Item, InfuserEntry>> entrySet() {
|
|
return map.entrySet();
|
|
}
|
|
|
|
static String toString(InfuserEntry entry) {
|
|
Item item = null;
|
|
for (Map.Entry<Item, InfuserEntry> mapEntry : entrySet()) {
|
|
if (mapEntry.getValue() == entry) {
|
|
item = mapEntry.getKey();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (item != null) {
|
|
return Registry.ITEM.getId(item).toString();
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
static InfuserEntry fromString(String str) {
|
|
Item item = Registry.ITEM.get(new Identifier(str));
|
|
return map.getOrDefault(item, null);
|
|
}
|
|
|
|
static {
|
|
add(Items.SUGAR, new InfuserEntry(320, 0.4d, new InfuserAction[]{new InfuserAction.ItemAction(new ItemStack(Items.GLOWSTONE_DUST, 48))}, new InfuserAction[]{new InfuserAction.ItemAction(Items.SUGAR_CANE), new InfuserAction.ExplosionAction()}));
|
|
|
|
addTransform(getDyes(), 107, 0.4d);
|
|
addTransform(getWool(), 168, 0.3d);
|
|
|
|
add(Items.GOLDEN_APPLE, new InfuserEntry(510, 0.3d, new InfuserAction[]{new InfuserAction.ItemAction(Items.ENCHANTED_GOLDEN_APPLE)}, new InfuserAction[]{new InfuserAction.ExplosionAction()}));
|
|
add(Items.COAL, new InfuserEntry(340, 0.2d, new InfuserAction[]{new InfuserAction.ItemAction(Items.DIAMOND)}, new InfuserAction[]{new InfuserAction.ExplosionAction()}));
|
|
|
|
add(EnergonRelics.VERIDIUM_INGOT_ITEM, new InfuserEntry(240, 0.25d, new InfuserAction[]{new InfuserAction.ItemAction(EnergonRelics.VERIDIUM_ORB_ITEM)}, new InfuserAction[]{new InfuserAction.ParticleAction(), new InfuserAction.ParticleAction(), new InfuserAction.ExplosionAction()}));
|
|
|
|
add(Items.GOLD_NUGGET, new InfuserEntry(260, 0.3d, new InfuserAction[]{new InfuserAction.ItemAction(Items.GOLD_INGOT)}, new InfuserAction[]{new InfuserAction.ItemAction(Items.IRON_NUGGET), new InfuserAction.ParticleAction()}));
|
|
add(Items.IRON_NUGGET, new InfuserEntry(260, 0.3d, new InfuserAction[]{new InfuserAction.ItemAction(Items.IRON_INGOT)}, new InfuserAction[]{new InfuserAction.ParticleAction()}));
|
|
}
|
|
|
|
private static void addTransform(Item[] items, long cost, double successChance) {
|
|
for (Item item : items) {
|
|
InfuserAction[] success = new InfuserAction[items.length - 1];
|
|
int i = 0;
|
|
for (Item item2 : items) {
|
|
if (item != item2) {
|
|
success[i] = new InfuserAction.ItemAction(new ItemStack(item2, 8));
|
|
i++;
|
|
}
|
|
}
|
|
add(item, new InfuserEntry(cost, successChance, success, new InfuserAction[]{new InfuserAction.ParticleAction(), new InfuserAction.ItemAction(Items.STRING)}));
|
|
}
|
|
}
|
|
|
|
private static Item[] getWool() {
|
|
List<Item> wool = new ArrayList<>();
|
|
for (Item item : Registry.ITEM) {
|
|
Identifier id = Registry.ITEM.getId(item);
|
|
if (id.getNamespace().equals("minecraft") && id.getPath().endsWith("_wool")) {
|
|
wool.add(item);
|
|
}
|
|
}
|
|
return wool.toArray(new Item[0]);
|
|
}
|
|
|
|
private static Item[] getDyes() {
|
|
DyeColor[] colors = DyeColor.values();
|
|
Item[] dyes = new Item[colors.length];
|
|
for (int i = 0; i < colors.length; i++) {
|
|
dyes[i] = DyeItem.byColor(colors[i]);
|
|
}
|
|
return dyes;
|
|
}
|
|
}
|