[Features] Equipment Sets
This commit is contained in:
parent
fde244965c
commit
e5da06a1e1
2 changed files with 141 additions and 0 deletions
|
@ -0,0 +1,81 @@
|
|||
package org.betterx.bclib.items.complex;
|
||||
|
||||
import org.betterx.bclib.items.BaseArmorItem;
|
||||
import org.betterx.bclib.recipes.GridRecipe;
|
||||
import org.betterx.bclib.registry.ItemRegistry;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EquipmentDescription<I extends Item> {
|
||||
private final Function<Tier, I> creator;
|
||||
private I item;
|
||||
|
||||
public EquipmentDescription(Function<Tier, I> creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public void init(ResourceLocation id, ItemRegistry itemsRegistry, Tier material, ItemLike stick) {
|
||||
item = creator.apply(material);
|
||||
itemsRegistry.registerTool(id, item);
|
||||
|
||||
addRecipe(id, item, material, stick);
|
||||
}
|
||||
|
||||
public void addRecipe(ResourceLocation id, Item tool, Tier material, ItemLike stick) {
|
||||
if (material == null) return;
|
||||
var repair = material.getRepairIngredient();
|
||||
if (repair == null) return;
|
||||
var repairItems = repair.getItems();
|
||||
if (repairItems == null || repairItems.length == 0) return;
|
||||
final ItemLike ingot = repairItems[0].getItem();
|
||||
|
||||
var builder = GridRecipe
|
||||
.make(id, tool)
|
||||
.addMaterial('#', ingot);
|
||||
|
||||
if (buildRecipe(tool, stick, builder)) return;
|
||||
builder
|
||||
.setGroup(id.getPath())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
protected boolean buildRecipe(Item tool, ItemLike stick, GridRecipe builder) {
|
||||
if (tool instanceof ShearsItem) {
|
||||
builder.setShape(" #", "# ");
|
||||
} else if (tool instanceof BaseArmorItem bai) {
|
||||
if (bai.getSlot() == EquipmentSlot.FEET) {
|
||||
builder.setShape("# #", "# #");
|
||||
} else if (bai.getSlot() == EquipmentSlot.HEAD) {
|
||||
builder.setShape("###", "# #");
|
||||
} else if (bai.getSlot() == EquipmentSlot.CHEST) {
|
||||
builder.setShape("# #", "###", "###");
|
||||
} else if (bai.getSlot() == EquipmentSlot.LEGS) {
|
||||
builder.setShape("###", "# #", "# #");
|
||||
} else return true;
|
||||
} else {
|
||||
builder.addMaterial('I', stick);
|
||||
if (tool instanceof PickaxeItem) {
|
||||
builder.setShape("###", " I ", " I ");
|
||||
} else if (tool instanceof AxeItem) {
|
||||
builder.setShape("##", "#I", " I");
|
||||
} else if (tool instanceof HoeItem) {
|
||||
builder.setShape("##", " I", " I");
|
||||
} else if (tool instanceof ShovelItem) {
|
||||
builder.setShape("#", "I", "I");
|
||||
} else if (tool instanceof SwordItem) {
|
||||
builder.setShape("#", "#", "I");
|
||||
} else return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public I getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.betterx.bclib.items.complex;
|
||||
|
||||
import org.betterx.bclib.registry.ItemRegistry;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class EquipmentSet {
|
||||
public final Tier material;
|
||||
public final String prefix;
|
||||
public final String modID;
|
||||
public final ItemLike stick;
|
||||
|
||||
public static final String PICKAXE_SLOT = "pickaxe";
|
||||
public static final String AXE_SLOT = "axe";
|
||||
public static final String SHOVEL_SLOT = "shovel";
|
||||
public static final String SWORD_SLOT = "sword";
|
||||
public static final String HOE_SLOT = "hoe";
|
||||
public static final String SHEARS_SLOT = "shears";
|
||||
public static final String HELMET_SLOT = "helmet";
|
||||
public static final String CHESTPLATE_SLOT = "chestplate";
|
||||
public static final String LEGGINS_SLOT = "leggings";
|
||||
public static final String BOOTS_SLOT = "boots";
|
||||
|
||||
private final Map<String, EquipmentDescription<?>> descriptions = new HashMap<>();
|
||||
|
||||
public EquipmentSet(Tier material, String modID, String prefix, ItemLike stick) {
|
||||
this.material = material;
|
||||
this.prefix = prefix;
|
||||
this.modID = modID;
|
||||
this.stick = stick;
|
||||
}
|
||||
|
||||
protected <I extends Item> void add(String slot, EquipmentDescription<I> desc) {
|
||||
descriptions.put(slot, desc);
|
||||
}
|
||||
|
||||
public EquipmentSet init(ItemRegistry itemsRegistry) {
|
||||
for (var desc : descriptions.entrySet()) {
|
||||
desc.getValue()
|
||||
.init(buildID(desc), itemsRegistry, material, stick);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ResourceLocation buildID(Map.Entry<String, EquipmentDescription<?>> desc) {
|
||||
return new ResourceLocation(modID, prefix + "_" + desc.getKey());
|
||||
}
|
||||
|
||||
public <I extends Item> I getSlot(String slot) {
|
||||
return (I) descriptions.get(slot).getItem();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue