diff --git a/build.gradle b/build.gradle index f8f39f5..68dcbe5 100644 --- a/build.gradle +++ b/build.gradle @@ -32,14 +32,6 @@ repositories { } metadataSources { artifact() } } - ivy { - url = "https://github.com/Turnip-Labs" - patternLayout { - artifact "[organisation]/releases/download/[revision]/[module]-bta-[revision].jar" - m2compatible = true - } - metadataSources { artifact() } - } ivy { url = "https://piston-data.mojang.com" patternLayout { @@ -75,7 +67,7 @@ dependencies { implementation 'com.google.guava:guava:30.0-jre' implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' - var log4jVersion = "2.20.0" + var log4jVersion = '2.23.1' implementation("org.apache.logging.log4j:log4j-core:${log4jVersion}") implementation("org.apache.logging.log4j:log4j-api:${log4jVersion}") implementation("org.apache.logging.log4j:log4j-1.2-api:${log4jVersion}") diff --git a/gradle.properties b/gradle.properties index 6987460..dc36fb3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ bta_version=7.2-pre1 loader_version=0.15.6-babric.6-bta # HalpLibe -halplibe_version=4.0.4 +halplibe_version=4.0.5 modmenu_version=2.0.6 # Mod diff --git a/src/main/java/turniplabs/examplemod/CustomItemModel.java b/src/main/java/turniplabs/examplemod/CustomItemModel.java new file mode 100644 index 0000000..e7661dd --- /dev/null +++ b/src/main/java/turniplabs/examplemod/CustomItemModel.java @@ -0,0 +1,18 @@ +package turniplabs.examplemod; + +import net.minecraft.client.render.item.model.ItemModelStandard; +import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemStack; + +import java.awt.*; + +public class CustomItemModel extends ItemModelStandard { + public CustomItemModel(Item item, String namespace) { + super(item, namespace); + } + @Override + public int getColor(ItemStack stack) { + // Slowly shift its color as time increases + return Color.HSBtoRGB((System.currentTimeMillis()%10000)/10000f, 1f, 1f); + } +} diff --git a/src/main/java/turniplabs/examplemod/ExampleMod.java b/src/main/java/turniplabs/examplemod/ExampleMod.java index e4423b5..45a4b79 100644 --- a/src/main/java/turniplabs/examplemod/ExampleMod.java +++ b/src/main/java/turniplabs/examplemod/ExampleMod.java @@ -8,17 +8,22 @@ import net.minecraft.core.item.ItemFood; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import turniplabs.examplemod.item.ItemCarrotStick; import turniplabs.halplibe.helper.ItemBuilder; +import turniplabs.halplibe.helper.RecipeBuilder; import turniplabs.halplibe.util.GameStartEntrypoint; +import turniplabs.halplibe.util.RecipeEntrypoint; -public class ExampleMod implements ModInitializer, GameStartEntrypoint { +public class ExampleMod implements ModInitializer, GameStartEntrypoint, RecipeEntrypoint { public static final String MOD_ID = "examplemod"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static Item bamboo; public static Item potato; + public static Item carrot; public static Item potatoBaked; public static Item carrotStick; + public static Item rgbChestplate; @Override public void onInitialize() { LOGGER.info("ExampleMod initialized."); @@ -33,16 +38,34 @@ public void beforeGameStart() { // is to make your ids user configurable int startingItemId = 20000; - bamboo = new ItemBuilder(MOD_ID).build(new Item("bamboo", startingItemId++)); - potato = new ItemBuilder(MOD_ID).build(new ItemFood("potato", startingItemId++, 2, 10, false, 64)); - potatoBaked = new ItemBuilder(MOD_ID).build(new ItemFood("baked.potato", startingItemId++, 6, 24, false, 8)); + // A very basic item with the translation key set to "bamboo" which will automatically get "item.." appended to the front turning this + // specific translation key to "item.examplemod.bamboo", you can then set the name and description of the item inside of "/lang//en_US.lang" + // in this example we set the name to "Bamboo" by setting "item.examplemod.bamboo.name=Bamboo" in the lang file + // By default the texture for the item uses its given key and our modId in this case since we set the key to "bamboo" and our modId is "examplemod" + // it uses the texture "/assets/examplemod/textures/item/bamboo.png" for its icon + bamboo = new ItemBuilder(MOD_ID) + .build(new Item("bamboo", startingItemId++)); + + // A custom items using the ItemFood food class making it edible, we can change the input parameters in order to change how much it heals + potato = new ItemBuilder(MOD_ID) + .build(new ItemFood("potato", startingItemId++, 2, 72, false, 64)); + carrot = new ItemBuilder(MOD_ID) + .build(new ItemFood("carrot", startingItemId++, 2, 40, false, 64)); + potatoBaked = new ItemBuilder(MOD_ID) + .build(new ItemFood("baked.potato", startingItemId++, 6, 30, false, 8)); + + // A custom item with custom properties carrotStick = new ItemBuilder(MOD_ID) - .setItemModel(item -> { - ItemModelStandard model = new ItemModelStandard(item, null); - model.icon = TextureRegistry.getTexture("examplemod:item/carrot_on_a_stick"); - return model; - }) - .build(new Item("stick.carrot", startingItemId++)); + .setItemModel(item -> new ItemModelStandard(item, null).setRotateWhenRendering().setFull3D()) // This sets the item to render likes tools do, where its rotated in the player's hand + .setIcon("examplemod:item/carrot_on_a_stick") // This sets a specific texture to use for the icon of them item, in this case it loads "/assets/examplemod/textures/item/carrot_on_a_stick.png" + .setStackSize(1) // Sets the max stack size to be 1 + .build(new ItemCarrotStick("stick.carrot", startingItemId++)); // We assign our custom item class to it to give it custom behavior + + // A custom item with a custom ItemModel + rgbChestplate = new ItemBuilder(MOD_ID) + .setItemModel(item -> new CustomItemModel(item, null)) // We set a custom item model to the item, this model just changes the item's color through time + .setIcon("examplemod:item/leather_chestplate") + .build(new Item("rgb.chest", startingItemId++)); } @Override @@ -50,4 +73,26 @@ public void afterGameStart() { } + @Override + public void onRecipesReady() { + // For more on adding recipes see the dedicated RecipeBuilder example mod here: https://github.com/Turnip-Labs/halplibe-examples-repo/tree/recipebuilder + + // Make the carrot on a stick craftable by crafting a carrot and fishing rod + RecipeBuilder.Shapeless(MOD_ID) + .addInput(Item.toolFishingrod) + .addInput(carrot) + .create("carrot_on_a_stick", carrotStick.getDefaultStack()); + + // Recipe to turn two bamboo into a stick + RecipeBuilder.Shapeless(MOD_ID) + .addInput(bamboo) + .addInput(bamboo) + .create("bamboo_to_stick", Item.stick.getDefaultStack()); + + } + + @Override + public void initNamespaces() { + RecipeBuilder.initNameSpace(MOD_ID); + } } diff --git a/src/main/java/turniplabs/examplemod/item/ItemCarrotStick.java b/src/main/java/turniplabs/examplemod/item/ItemCarrotStick.java new file mode 100644 index 0000000..faf0415 --- /dev/null +++ b/src/main/java/turniplabs/examplemod/item/ItemCarrotStick.java @@ -0,0 +1,29 @@ +package turniplabs.examplemod.item; + +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.animal.EntityPig; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.util.phys.Vec3d; +import net.minecraft.core.world.World; + +public class ItemCarrotStick extends Item { + public ItemCarrotStick(String name, int id) { + super(name, id); + } + @Override + public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) { + if (!(entity instanceof EntityPlayer)) return; + if (((EntityPlayer) entity).getHeldItem() == null) return; + if (((EntityPlayer) entity).getHeldItem().getItem() != this) return; + if (!(entity.vehicle instanceof EntityPig)) return; + EntityPig pig = (EntityPig) entity.vehicle; + Vec3d looking = entity.getLookAngle(); + int x = (int) (entity.x + looking.xCoord * 5); + int y = (int) (entity.y + looking.yCoord * 5); + int z = (int) (entity.z + looking.zCoord * 5); + pig.setPathToEntity(world.getEntityPathToXYZ(pig, x, y, z, 20)); + pig.yRot = entity.yRot; + } +} diff --git a/src/main/resources/assets/examplemod/textures/item/carrot.png b/src/main/resources/assets/examplemod/textures/item/carrot.png new file mode 100644 index 0000000..a0e4259 Binary files /dev/null and b/src/main/resources/assets/examplemod/textures/item/carrot.png differ diff --git a/src/main/resources/assets/examplemod/textures/item/leather_chestplate.png b/src/main/resources/assets/examplemod/textures/item/leather_chestplate.png new file mode 100644 index 0000000..104c1fe Binary files /dev/null and b/src/main/resources/assets/examplemod/textures/item/leather_chestplate.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cb14bb1..5c81a2a 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,6 +23,9 @@ ], "beforeGameStart": [ "turniplabs.examplemod.ExampleMod" + ], + "recipesReady": [ + "turniplabs.examplemod.ExampleMod" ] }, "mixins": [ diff --git a/src/main/resources/lang/examplemod/en_US.lang b/src/main/resources/lang/examplemod/en_US.lang index e69de29..c0eaab6 100644 --- a/src/main/resources/lang/examplemod/en_US.lang +++ b/src/main/resources/lang/examplemod/en_US.lang @@ -0,0 +1,12 @@ +item.examplemod.bamboo.name=Bamboo +item.examplemod.bamboo.desc=Its bamboo, half stick half green. +item.examplemod.potato.name=Potato +item.examplemod.potato.desc=Edible... but just barely. +item.examplemod.carrot.name=Carrot +item.examplemod.carrot.desc=Orange. +item.examplemod.baked.potato.name=Baked Potato +item.examplemod.baked.potato.desc=Ball of heated starch. +item.examplemod.stick.carrot.name=Carrot on a Stick +item.examplemod.stick.carrot.desc=Pigs may be interested in this. +item.examplemod.rgb.chest.name=RGB Chestplate +item.examplemod.rgb.chest.desc=Made by gamers for gamers