Posted November 17, 20186 yr So I just joined the forums today because this problem has been bugging me for a while. When I go to milk a cow with a custom empty bottle, it works fine, and the bottle becomes "bottled milk". When I drink the milk, everything works as expected and I receive an empty bottle. But when I go to milk the cow again, the item becomes bottled milk and then reverts to an empty bottle after a few seconds, like it won't hold the milk. Not sure if it is running the code with the EnumAction.DRINK automatically or what. Below are my CustomBottledItem and MainEvents classes. Thanks. Spoiler public class CustomBottledItem extends Item implements IHasModel { public CustomBottledItem(String name) { super(); setMaxStackSize(1); setUnlocalizedName(name); setRegistryName(name); setCreativeTab(Main.creativeTabs); ModItems.ITEMS.add(this); } public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { super.onItemUseFinish(stack, worldIn, entityLiving); return new ItemStack(ModItems.EMPTY_BOTTLE); } @Override public int getMaxItemUseDuration(ItemStack stack) { return 32; } @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.DRINK; } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { playerIn.setActiveHand(handIn); return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); } } Spoiler public class MainEvents { @SubscribeEvent public void onEntityRightClicked(PlayerInteractEvent.EntityInteract event) { //Current item ItemStack itemstack = event.getEntityPlayer().inventory.getCurrentItem(); if (event.getTarget() instanceof EntityCow) { if (itemstack != null && itemstack.getItem() == ModItems.EMPTY_BOTTLE && !event.getEntityPlayer().capabilities.isCreativeMode) { event.getEntityPlayer().inventory.setInventorySlotContents(event.getEntityPlayer().inventory.currentItem, new ItemStack(ModItems.BOTTLED_MILK)); event.getEntityPlayer().playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F); } } } } Edited November 17, 20186 yr by Siqhter
November 18, 20186 yr try stepping through your code with the debugger. Also, don't use IHasModel About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
November 18, 20186 yr 10 hours ago, Siqhter said: itemstack != nul What version of the game are you modding for? The issue itself looks like a desync issue where the client thinks that it filled the bottle but the server disagrees. Make sure you are only "filling" the bottle on the server.
November 18, 20186 yr Author 10 hours ago, V0idWa1k3r said: What version of the game are you modding for? The issue itself looks like a desync issue where the client thinks that it filled the bottle but the server disagrees. Make sure you are only "filling" the bottle on the server. I think I understand what you are saying. I am currently modding on 1.12.2. And how would I check that it is only "filling" the bottle on the server? Edited November 18, 20186 yr by Siqhter
November 18, 20186 yr 2 hours ago, Siqhter said: I am currently modding on 1.12.2. Then this 22 hours ago, Siqhter said: itemstack != null will never be false since ItemStacks in 1.12.2 can't be null. Use ItemStack#isEmpty 2 hours ago, Siqhter said: how would I check that it is only "filling" the bottle on the server? The same way you check anything for the side it is performed on using World.isRemote
November 18, 20186 yr Author Ok, thanks for your help I think I'm getting it. Just to clarify I was looking through ItemMilkBucket's Class, and I found this. Is it basically just checking to make sure it's running on the server? if (!worldIn.isRemote) entityLiving.curePotionEffects(stack);
November 18, 20186 yr Yes. World.isRemote will be true for a client world and false for a server. You can read more about sides here.
November 18, 20186 yr Author Ok, I guess I got it figured out. Would it make sense to return if(world.isRemote)?
November 18, 20186 yr Yes About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
November 19, 20186 yr Author V0idWa1k3r and Cadiboo thanks it works now. Edited November 19, 20186 yr by Siqhter
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.