This commit is contained in:
Joshua7Perkins
2020-10-07 02:02:38 -05:00
parent dc3aef2218
commit c7da687185
34 changed files with 656 additions and 5 deletions

View File

@@ -1,14 +1,75 @@
package net.fabricmc.example;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class ExampleMod implements ModInitializer {
// This is a generic Item template
// public static final Item FabricItem = new Item(new FabricItemSettings().group(ItemGroup.MISC));
// VT Tutorial Book
// Implemented by Jerbyl
public static final TutorialBook TUTORIAL_BOOK = new TutorialBook(new FabricItemSettings().group(ItemGroup.MISC));
public static final RingOfFlight RING_OF_FLIGHT = new RingOfFlight(new FabricItemSettings().group(ItemGroup.MISC));
// Charcoal block
// Implemented by Jerbyl
public static final Block BLOCK_OF_CHARCOAL = new Block(FabricBlockSettings.of(Material.STONE).hardness(5.0f));
// Gold-plated diamond armor items
// Implemented by Jerbyl
public static final Item GOLD_DIAMOND_HELMET = new ArmorItem(GoldDiamond.GOLD_DIAMOND, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT)));
public static final Item GOLD_DIAMOND_CHESTPLATE = new ArmorItem(GoldDiamond.GOLD_DIAMOND, EquipmentSlot.CHEST, (new Item.Settings().group(ItemGroup.COMBAT)));
public static final Item GOLD_DIAMOND_LEGGINGS = new ArmorItem(GoldDiamond.GOLD_DIAMOND, EquipmentSlot.LEGS, (new Item.Settings().group(ItemGroup.COMBAT)));
public static final Item GOLD_DIAMOND_BOOTS = new ArmorItem(GoldDiamond.GOLD_DIAMOND, EquipmentSlot.FEET, (new Item.Settings().group(ItemGroup.COMBAT)));
// Gold-plated netherite armor items
// Implemented by Jerbyl
public static final Item GOLD_NETHERITE_HELMET = new ArmorItem(GoldNetherite.GOLD_NETHERITE, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT)));
public static final Item GOLD_NETHERITE_CHESTPLATE = new ArmorItem(GoldNetherite.GOLD_NETHERITE, EquipmentSlot.CHEST, (new Item.Settings().group(ItemGroup.COMBAT)));
public static final Item GOLD_NETHERITE_LEGGINGS = new ArmorItem(GoldNetherite.GOLD_NETHERITE, EquipmentSlot.LEGS, (new Item.Settings().group(ItemGroup.COMBAT)));
public static final Item GOLD_NETHERITE_BOOTS = new ArmorItem(GoldNetherite.GOLD_NETHERITE, EquipmentSlot.FEET, (new Item.Settings().group(ItemGroup.COMBAT)));
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
System.out.println("Hello Fabric world!");
// Adds registry entry for VT Tutorial Book
// Implemented by Jerbyl
Registry.register(Registry.ITEM, new Identifier("examplemod", "tutorial_book"), TUTORIAL_BOOK);
// Adds registry entry for Ring Of Flight
// Implemented by Jerbyl
Registry.register(Registry.ITEM, new Identifier("examplemod", "ring_of_flight"), RING_OF_FLIGHT);
// Adds registry entries for the Charcoal_Block item and block
// Implemented by Jerbyl
Registry.register(Registry.BLOCK, new Identifier("examplemod", "block_of_charcoal"), BLOCK_OF_CHARCOAL);
Registry.register(Registry.ITEM, new Identifier("examplemod", "block_of_charcoal"), new BlockItem(BLOCK_OF_CHARCOAL, new Item.Settings().group(ItemGroup.MISC)));
// Adds registry entries for gold-trimmed diamond and netherite armors.
// Implemented by Jerbyl
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_diamond_helmet"), GOLD_DIAMOND_HELMET);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_diamond_chestplate"), GOLD_DIAMOND_CHESTPLATE);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_diamond_leggings"), GOLD_DIAMOND_LEGGINGS);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_diamond_boots"), GOLD_DIAMOND_BOOTS);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_netherite_helmet"), GOLD_NETHERITE_HELMET);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_netherite_chestplate"), GOLD_NETHERITE_CHESTPLATE);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_netherite_leggings"), GOLD_NETHERITE_LEGGINGS);
Registry.register(Registry.ITEM,new Identifier("examplemod","gold_netherite_boots"), GOLD_NETHERITE_BOOTS);
}
}
}

View File

@@ -0,0 +1,75 @@
package net.fabricmc.example;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Lazy;
import java.util.function.Supplier;
public enum GoldDiamond implements ArmorMaterial {
GOLD_DIAMOND("gold_diamond", 33, new int[]{3, 8, 6, 3}, 20, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 2.0F, 0.0F, () -> {
return Ingredient.ofItems(Items.DIAMOND);
});
private static final int[] BASE_DURABILITY = {13, 15, 16, 11};
private final String name;
private final int durabilityMultiplier;
private final int[] armorValues;
private final int enchantability;
private final SoundEvent equipSound;
private final float toughness;
private final float knockbackResistance;
private final Lazy<Ingredient> repairIngredient;
GoldDiamond(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
this.name = name;
this.durabilityMultiplier = durabilityMultiplier;
this.armorValues = armorValueArr;
this.enchantability = enchantability;
this.equipSound = soundEvent;
this.toughness = toughness;
this.knockbackResistance = knockbackResistance;
this.repairIngredient = new Lazy(repairIngredient);
}
public int getDurability(EquipmentSlot equipmentSlot_1) {
return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier;
}
public int getProtectionAmount(EquipmentSlot equipmentSlot_1) {
return this.armorValues[equipmentSlot_1.getEntitySlotId()];
}
public int getEnchantability() {
return this.enchantability;
}
public SoundEvent getEquipSound() {
return this.equipSound;
}
public Ingredient getRepairIngredient() {
// We needed to make it a Lazy type so we can actually get the Ingredient from the Supplier.
return this.repairIngredient.get();
}
@Environment(EnvType.CLIENT)
public String getName() {
return this.name;
}
public float getToughness() {
return this.toughness;
}
public float getKnockbackResistance() {
return this.knockbackResistance;
}
}

View File

@@ -0,0 +1,75 @@
package net.fabricmc.example;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Lazy;
import java.util.function.Supplier;
public enum GoldNetherite implements ArmorMaterial {
GOLD_NETHERITE("gold_netherite", 37, new int[]{3, 8, 6, 3}, 25, SoundEvents.ITEM_ARMOR_EQUIP_NETHERITE, 3.0F, 1.0F, () -> {
return Ingredient.ofItems(Items.NETHERITE_INGOT);
});
private static final int[] BASE_DURABILITY = {13, 15, 16, 11};
private final String name;
private final int durabilityMultiplier;
private final int[] armorValues;
private final int enchantability;
private final SoundEvent equipSound;
private final float toughness;
private final float knockbackResistance;
private final Lazy<Ingredient> repairIngredient;
GoldNetherite(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
this.name = name;
this.durabilityMultiplier = durabilityMultiplier;
this.armorValues = armorValueArr;
this.enchantability = enchantability;
this.equipSound = soundEvent;
this.toughness = toughness;
this.knockbackResistance = knockbackResistance;
this.repairIngredient = new Lazy(repairIngredient);
}
public int getDurability(EquipmentSlot equipmentSlot_1) {
return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier;
}
public int getProtectionAmount(EquipmentSlot equipmentSlot_1) {
return this.armorValues[equipmentSlot_1.getEntitySlotId()];
}
public int getEnchantability() {
return this.enchantability;
}
public SoundEvent getEquipSound() {
return this.equipSound;
}
public Ingredient getRepairIngredient() {
// We needed to make it a Lazy type so we can actually get the Ingredient from the Supplier.
return this.repairIngredient.get();
}
@Environment(EnvType.CLIENT)
public String getName() {
return this.name;
}
public float getToughness() {
return this.toughness;
}
public float getKnockbackResistance() {
return this.knockbackResistance;
}
}

View File

@@ -0,0 +1,25 @@
package net.fabricmc.example;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class RingOfFlight extends Item {
public RingOfFlight(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
playerEntity.playSound(SoundEvents.ENTITY_ARROW_HIT_PLAYER, 1.0F, 1.0F);
return new TypedActionResult<>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand));
}
}

View File

@@ -0,0 +1,25 @@
package net.fabricmc.example;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class TutorialBook extends Item {
public TutorialBook(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
playerEntity.playSound(SoundEvents.ENTITY_PLAYER_HURT, 1.0F, 1.0F);
return new TypedActionResult<>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand));
}
}