Posted February 9, 20187 yr Hello, I am fairly new to modding I am following someone's tutorial series but I am now ahead of where he is. I am trying to create a custom bucket I have the items all set up i just do not know how to make them function as a normal bucket. I want to be able to only pick up water with it and nothing else. I will and another bucket soon that will be the same but can pick up lava although I can just copy/paste and change the code to lava. I have done a few attempts but to no avail any ideas? Also, i am wanting to have sticks have a 50% chance of dropping from trees, unable to break logs with hand, and wood/stone tools disabled. 2nd to the last thing is only having something spawn only near a waterbed on the surface like sugar cane as a singular block, not in a cluster. The last thing is that I have a crafting table set up I just don't know how to make it a crafting table because at the moment it is just a block. If you can solve any of these things please respond. Thanks!
February 9, 20187 yr Author If you want me to tell you any information about the code of my mod, I will just tell me.
February 9, 20187 yr Choonster creates wooden buckets and stone buckets in his TestMod3 example code. https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/099f84747156ce8d01f1276954e047d5ec6ce800/src/main/java/choonster/testmod3/item/ItemBucketTestMod3.java Check out my tutorials here: http://jabelarminecraft.blogspot.com/
February 9, 20187 yr Author 10 hours ago, jabelar said: Choonster creates wooden buckets and stone buckets in his TestMod3 example code. https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/099f84747156ce8d01f1276954e047d5ec6ce800/src/main/java/choonster/testmod3/item/ItemBucketTestMod3.java I looked through the code and that picks up any fluid and changes the type, I am using a custom model for my item and I want the bucket to only pick up water, also I have 2 items so I just need to check to see if the water is the block clicked with the empty bucket and then remove it then switch the item, my code is not working, I am doing the picking up fluids first. I will post the java file I have for the item once I get the chance. The code you sent picks up any fluid and changes the texture but that wouldn't work because I want to use my custom model.
February 9, 20187 yr Author also just out of curiosity, is there any way I could allow the player to put the empty bucket item on his head? I have the model and thing set up I just don't know how to program that in.
February 9, 20187 yr Author package com.posidon.startertech.items; import net.minecraft.world.World; import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumActionResult; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraft.init.Blocks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.block.state.IBlockState; import com.posidon.startertech.init.ModItems; import net.minecraft.block.Block; import net.minecraft.block.material.Material; public class WoodBucketEmpty extends ItemBase { public WoodBucketEmpty(String name) { super(name); setMaxDamage(1); maxStackSize = 16; } @Override public float getDestroySpeed(ItemStack par1ItemStack, IBlockState par2Block) { return 0.5F; } @Override public EnumActionResult onItemUseFirst(EntityPlayer entity, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { float var4 = 1.0F; int i = pos.getX(); int j = pos.getY(); int k = pos.getZ(); if (world.getBlockState(new BlockPos(i, j, k)).getBlock() == Blocks.WATER) { world.setBlockToAir(new BlockPos(i, j, k)); if (entity instanceof EntityPlayer) { ((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(ModItems.WOOD_BUCKET_FULL_ITEM, 1)); ((EntityPlayer) entity).inventory.clearMatchingItems(ModItems.WOOD_BUCKET_ITEM, -1, 1, null); } } return EnumActionResult.PASS; } } that's the code in my items java file, here is where I put them into an array to be registered: package com.posidon.startertech.init; import java.util.ArrayList; import java.util.List; import com.posidon.startertech.items.ItemBase; import com.posidon.startertech.items.WoodBucketEmpty; import net.minecraft.item.Item; public class ModItems { public static final List<Item> ITEMS = new ArrayList<Item>(); public static final Item SULFUR = new ItemBase("sulfur"); public static final Item CINNABAR = new ItemBase("cinnabar"); public static final Item SULFUR_CRYSTAL = new ItemBase("sulfur_crystal"); public static final Item WOOD_BUCKET_ITEM = new WoodBucketEmpty("wood_bucket_item"); public static final Item WOOD_BUCKET_FULL_ITEM = new ItemBase("wood_bucket_full_item"); } Here is where I take the Item list and register it package com.posidon.startertech.items; import com.posidon.startertech.Main; import com.posidon.startertech.init.ModItems; import com.posidon.startertech.util.IHasModel; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; public class ItemBase extends Item implements IHasModel { public ItemBase(String name) { setUnlocalizedName(name); setRegistryName(name); setCreativeTab(CreativeTabs.MATERIALS); ModItems.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); } } If you need any other information tell me.
February 10, 20187 yr 14 minutes ago, WaffleKing26 said: Still unsolved! cant figure it out Maybe look up custom armor tutorial. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
February 10, 20187 yr 5 hours ago, WaffleKing26 said: I meant the picking up water in the bucket You need two states. One if the bucket is full and one if not. I'd suggest using PropertyBool to create a BlockProperty. Then you override the methods that are provided by the Item class your Item is extended from. I don't know the exact name, but I think it is onItemUse(Use the one were a blockstate is given that is Right-Clicked on). Then perform checks. Like, if the bucket is full, empty it. If not, check if the player clicked water and in that case, fill the bucket. That is all there is to it.
February 11, 20187 yr Author 18 minutes ago, ArmamentHaki said: You need two states. One if the bucket is full and one if not. I'd suggest using PropertyBool to create a BlockProperty. Then you override the methods that are provided by the Item class your Item is extended from. I don't know the exact name, but I think it is onItemUse(Use the one were a blockstate is given that is Right-Clicked on). Then perform checks. Like, if the bucket is full, empty it. If not, check if the player clicked water and in that case, fill the bucket. That is all there is to it. i have 2 custom buckets and in the empty one it has the code i talked about above. im doing empty before i code the full one so i know it works first
February 11, 20187 yr 22 minutes ago, WaffleKing26 said: i have 2 custom buckets and in the empty one it has the code i talked about above. im doing empty before i code the full one so i know it works first My fault, I forget we were talking about an item. In that case, I have some points: if(entity instanceof EntityPlayer) will always be true use onItemUse(), not onItemUseFirst /** * Called when a Block is right-clicked with this Item */ public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { return EnumActionResult.PASS; } The casts are unnessecary Try using entity.inventory.deleteStack(entity.inventory.getCurrentItem()); entity.inventory.add(entity.inventory.currentItem, new ItemStack(Items.WATER_BUCKET)); You need to change the bucket back, otherwise, this will only work in one direction Edited February 11, 20187 yr by ArmamentHaki
February 11, 20187 yr Author I'm starting to think that it was just the way I called the java file wrong cause i changed all the things you said to didnt work so i changed the water to stone and still didnt work. here is the code where i create the item: package com.posidon.startertech.init; import java.util.ArrayList; import java.util.List; import com.posidon.startertech.items.ItemBase; import com.posidon.startertech.items.WoodBucketEmpty; import net.minecraft.item.Item; public class ModItems { public static final List<Item> ITEMS = new ArrayList<Item>(); public static final Item SULFUR = new ItemBase("sulfur"); public static final Item CINNABAR = new ItemBase("cinnabar"); public static final Item SULFUR_CRYSTAL = new ItemBase("sulfur_crystal"); public static final Item WOOD_BUCKET_ITEM = new WoodBucketEmpty("wood_bucket_item"); public static final Item WOOD_BUCKET_FULL_ITEM = new ItemBase("wood_bucket_full_item"); }
February 11, 20187 yr Author here is item java file and where I register the item. package com.posidon.startertech.items; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumActionResult; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraft.init.Blocks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.block.state.IBlockState; import com.posidon.startertech.init.ModItems; import net.minecraft.block.Block; import net.minecraft.block.material.Material; public class WoodBucketEmpty extends ItemBase { public WoodBucketEmpty(String name) { super(name); setMaxDamage(1); maxStackSize = 16; } @Override public float getDestroySpeed(ItemStack par1ItemStack, IBlockState par2Block) { return 0.5F; } @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){ BlockPos hitLocation = new BlockPos(hitX, hitY, hitZ); if (worldIn.getBlockState(new BlockPos(hitLocation)).getBlock() == Blocks.WATER) { worldIn.setBlockToAir(new BlockPos(hitLocation)); player.inventory.deleteStack(player.inventory.getCurrentItem()); player.inventory.add(player.inventory.currentItem, new ItemStack(ModItems.WOOD_BUCKET_FULL_ITEM)); } return EnumActionResult.PASS; } } package com.posidon.startertech.util.handlers; import com.posidon.startertech.init.ModBlocks; import com.posidon.startertech.init.ModItems; import com.posidon.startertech.util.IHasModel; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @EventBusSubscriber public class RegistryHandler { @SubscribeEvent public static void onItemRegister(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0])); } @SubscribeEvent public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); } @SubscribeEvent public static void onModelRegister(ModelRegistryEvent event) { for (Item item : ModItems.ITEMS) { if (item instanceof IHasModel) { ((IHasModel)item).registerModels(); } } for (Block block : ModBlocks.BLOCKS) { if (block instanceof IHasModel) { ((IHasModel)block).registerModels(); } } } } package com.posidon.startertech.items; import com.posidon.startertech.Main; import com.posidon.startertech.init.ModItems; import com.posidon.startertech.util.IHasModel; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; public class ItemBase extends Item implements IHasModel { public ItemBase(String name) { setUnlocalizedName(name); setRegistryName(name); setCreativeTab(CreativeTabs.MATERIALS); ModItems.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); } }
March 27, 20187 yr after the line: if (worldIn.getBlockState(new BlockPos(hitLocation)).getBlock() == Blocks.WATER) try adding a trace call (output a string into a console). keep the trace call there until you get the condition right. use the trace call to see the values of method parameters. Spoiler i should just leave it at that, but here: 1) try using use the "pos" thingy. it's nice. 2) instead of comparing block instances, i'd check material and the value of level property.
March 27, 20187 yr Author ok will do once i get the chance a little busy atm but ill get back once i do
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.