armor!
This commit is contained in:
@@ -11,8 +11,30 @@ import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraft.world.item.armortrim.TrimMaterial;
|
||||
import net.minecraft.world.item.armortrim.TrimMaterials;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class ModItemModelProvider extends ItemModelProvider {
|
||||
private static LinkedHashMap<ResourceKey<TrimMaterial>, Float> trimMaterials = new LinkedHashMap<>();
|
||||
static {
|
||||
trimMaterials.put(TrimMaterials.QUARTZ, 0.1F);
|
||||
trimMaterials.put(TrimMaterials.IRON, 0.2F);
|
||||
trimMaterials.put(TrimMaterials.NETHERITE, 0.3F);
|
||||
trimMaterials.put(TrimMaterials.REDSTONE, 0.4F);
|
||||
trimMaterials.put(TrimMaterials.COPPER, 0.5F);
|
||||
trimMaterials.put(TrimMaterials.GOLD, 0.6F);
|
||||
trimMaterials.put(TrimMaterials.EMERALD, 0.7F);
|
||||
trimMaterials.put(TrimMaterials.DIAMOND, 0.8F);
|
||||
trimMaterials.put(TrimMaterials.LAPIS, 0.9F);
|
||||
trimMaterials.put(TrimMaterials.AMETHYST, 1.0F);
|
||||
}
|
||||
|
||||
public ModItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
|
||||
super(output, NuggetMod.MOD_ID, existingFileHelper);
|
||||
}
|
||||
@@ -27,6 +49,49 @@ public class ModItemModelProvider extends ItemModelProvider {
|
||||
handheldItem(ModItems.NUGGET_SHOVEL);
|
||||
handheldItem(ModItems.NUGGET_AXE);
|
||||
handheldItem(ModItems.NUGGET_HOE);
|
||||
|
||||
trimmedArmorItem(ModItems.NUGGET_HELMET);
|
||||
trimmedArmorItem(ModItems.NUGGET_CHESTPLATE);
|
||||
trimmedArmorItem(ModItems.NUGGET_LEGGINGS);
|
||||
trimmedArmorItem(ModItems.NUGGET_BOOTS);
|
||||
}
|
||||
private void trimmedArmorItem(RegistryObject<Item> itemRegistryObject) {
|
||||
final String MOD_ID = NuggetMod.MOD_ID; // Change this to your mod id
|
||||
if (itemRegistryObject.get() instanceof ArmorItem armorItem) {
|
||||
trimMaterials.forEach((trimMaterial, value) -> {
|
||||
float trimValue = value;
|
||||
String armorType = switch (armorItem.getEquipmentSlot()) {
|
||||
case HEAD -> "helmet";
|
||||
case CHEST -> "chestplate";
|
||||
case LEGS -> "leggings";
|
||||
case FEET -> "boots";
|
||||
default -> "";
|
||||
};
|
||||
String armorItemPath = armorItem.toString();
|
||||
String trimPath = "trims/items/" + armorType + "_trim_" + trimMaterial.location().getPath();
|
||||
String currentTrimName = armorItemPath + "_" + trimMaterial.location().getPath() + "_trim";
|
||||
ResourceLocation armorItemResLoc = ResourceLocation.parse(armorItemPath);
|
||||
ResourceLocation trimResLoc = ResourceLocation.parse(trimPath); // minecraft namespace
|
||||
ResourceLocation trimNameResLoc = ResourceLocation.parse(currentTrimName);
|
||||
// This is used for making the ExistingFileHelper acknowledge that this texture exist, so this will
|
||||
// avoid an IllegalArgumentException
|
||||
existingFileHelper.trackGenerated(trimResLoc, PackType.CLIENT_RESOURCES, ".png", "textures");
|
||||
// Trimmed armorItem files
|
||||
getBuilder(currentTrimName)
|
||||
.parent(new ModelFile.UncheckedModelFile("item/generated"))
|
||||
.texture("layer0", armorItemResLoc.getNamespace() + ":item/" + armorItemResLoc.getPath())
|
||||
.texture("layer1", trimResLoc);
|
||||
// Non-trimmed armorItem file (normal variant)
|
||||
this.withExistingParent(itemRegistryObject.getId().getPath(),
|
||||
mcLoc("item/generated"))
|
||||
.override()
|
||||
.model(new ModelFile.UncheckedModelFile(trimNameResLoc.getNamespace() + ":item/" + trimNameResLoc.getPath()))
|
||||
.predicate(mcLoc("trim_type"), trimValue).end()
|
||||
.texture("layer0",
|
||||
ResourceLocation.fromNamespaceAndPath(MOD_ID,
|
||||
"item/" + itemRegistryObject.getId().getPath()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private ItemModelBuilder handheldItem(RegistryObject<Item> item) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import xyz.sillyangel.nugget.NuggetMod;
|
||||
import xyz.sillyangel.nugget.item.ModItems;
|
||||
import xyz.sillyangel.nugget.util.ModTags;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.world.item.Items;
|
||||
@@ -27,5 +28,11 @@ public class ModItemTagProvider extends ItemTagsProvider {
|
||||
.add(Items.COAL)
|
||||
.add(Items.STICK)
|
||||
.add(Items.COMPASS);
|
||||
|
||||
tag(ItemTags.TRIMMABLE_ARMOR)
|
||||
.add(ModItems.NUGGET_HELMET.get())
|
||||
.add(ModItems.NUGGET_CHESTPLATE.get())
|
||||
.add(ModItems.NUGGET_LEGGINGS.get())
|
||||
.add(ModItems.NUGGET_BOOTS.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package xyz.sillyangel.nugget.item;
|
||||
|
||||
import xyz.sillyangel.nugget.NuggetMod;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraft.world.item.ArmorMaterial;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ModArmorMaterials {
|
||||
public static final Holder<ArmorMaterial> NUGGET_ARMOR_MATERIAL = register("nugget", Util.make(new EnumMap<>(ArmorItem.Type.class),
|
||||
attribute -> {
|
||||
attribute.put(ArmorItem.Type.BOOTS, 5);
|
||||
attribute.put(ArmorItem.Type.LEGGINGS, 7);
|
||||
attribute.put(ArmorItem.Type.CHESTPLATE, 9);
|
||||
attribute.put(ArmorItem.Type.HELMET, 5);
|
||||
attribute.put(ArmorItem.Type.BODY, 11);
|
||||
}), 20, 4.5f, 0.5f, () -> ModItems.NUGGET.get());
|
||||
|
||||
private static Holder<ArmorMaterial> register(String name, EnumMap<ArmorItem.Type, Integer> typeProtection,
|
||||
int enchantability, float toughness, float knockbackResistance,
|
||||
Supplier<Item> ingredientItem) {
|
||||
ResourceLocation location = ResourceLocation.fromNamespaceAndPath(NuggetMod.MOD_ID, name);
|
||||
Holder<SoundEvent> equipSound = SoundEvents.ARMOR_EQUIP_NETHERITE;
|
||||
Supplier<Ingredient> ingredient = () -> Ingredient.of(ingredientItem.get());
|
||||
List<ArmorMaterial.Layer> layers = List.of(new ArmorMaterial.Layer(location));
|
||||
|
||||
EnumMap<ArmorItem.Type, Integer> typeMap = new EnumMap<>(ArmorItem.Type.class);
|
||||
for (ArmorItem.Type type : ArmorItem.Type.values()) {
|
||||
typeMap.put(type, typeProtection.get(type));
|
||||
}
|
||||
|
||||
return Registry.registerForHolder(BuiltInRegistries.ARMOR_MATERIAL, location,
|
||||
new ArmorMaterial(typeProtection, enchantability, equipSound, ingredient, layers, toughness, knockbackResistance));
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,11 @@ public class ModCreativeModeTabs {
|
||||
output.accept(ModItems.NUGGET_AXE.get());
|
||||
output.accept(ModItems.NUGGET_HOE.get());
|
||||
|
||||
output.accept(ModItems.NUGGET_HELMET.get());
|
||||
output.accept(ModItems.NUGGET_CHESTPLATE.get());
|
||||
output.accept(ModItems.NUGGET_LEGGINGS.get());
|
||||
output.accept(ModItems.NUGGET_BOOTS.get());
|
||||
|
||||
}).build());
|
||||
|
||||
public static final RegistryObject<CreativeModeTab> NUGGET_BLOCKS_TAB = CREATIVE_MODE_TABS.register("nuggetmod_blocks_tab",
|
||||
|
||||
@@ -41,6 +41,22 @@ public class ModItems {
|
||||
() -> new HoeItem(ModToolTiers.NUGGET, new Item.Properties()
|
||||
.attributes(HoeItem.createAttributes(ModToolTiers.NUGGET, 0, -3.0f))));
|
||||
|
||||
// armor things
|
||||
|
||||
public static final RegistryObject<Item> NUGGET_HELMET = ITEMS.register("nugget_helmet",
|
||||
() -> new ArmorItem(ModArmorMaterials.NUGGET_ARMOR_MATERIAL, ArmorItem.Type.HELMET,
|
||||
new Item.Properties().durability(ArmorItem.Type.HELMET.getDurability(25))));
|
||||
public static final RegistryObject<Item> NUGGET_CHESTPLATE = ITEMS.register("nugget_chestplate",
|
||||
() -> new ArmorItem(ModArmorMaterials.NUGGET_ARMOR_MATERIAL, ArmorItem.Type.CHESTPLATE,
|
||||
new Item.Properties().durability(ArmorItem.Type.CHESTPLATE.getDurability(25))));
|
||||
public static final RegistryObject<Item> NUGGET_LEGGINGS = ITEMS.register("nugget_leggings",
|
||||
() -> new ArmorItem(ModArmorMaterials.NUGGET_ARMOR_MATERIAL, ArmorItem.Type.LEGGINGS,
|
||||
new Item.Properties().durability(ArmorItem.Type.LEGGINGS.getDurability(25))));
|
||||
public static final RegistryObject<Item> NUGGET_BOOTS = ITEMS.register("nugget_boots",
|
||||
() -> new ArmorItem(ModArmorMaterials.NUGGET_ARMOR_MATERIAL, ArmorItem.Type.BOOTS,
|
||||
new Item.Properties().durability(ArmorItem.Type.BOOTS.getDurability(25))));
|
||||
|
||||
|
||||
public static void register(IEventBus eventBus) {
|
||||
ITEMS.register(eventBus);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
"item.nuggetmod.nugget_axe": "Nugget Axe",
|
||||
"item.nuggetmod.nugget_hoe": "Nugget Hoe",
|
||||
|
||||
"item.nuggetmod.nugget_helmet": "Nugget Helmet",
|
||||
"item.nuggetmod.nugget_chestplate": "Nugget Chestplate",
|
||||
"item.nuggetmod.nugget_leggings": "Nugget Leggings",
|
||||
"item.nuggetmod.nugget_boots": "Nugget Boots",
|
||||
|
||||
"creativetab.nuggetmod.nugget_items": "Nugget Mod Items",
|
||||
"creativetab.nuggetmod.nugget_blocks": "Nugget Mod Blocks",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user