Jump to content

Recommended Posts

Posted (edited)

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 by Siqhter
Posted

try stepping through your code with the debugger. Also, don't use IHasModel

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Posted
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.

Posted (edited)
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 by Siqhter
Posted
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

Posted

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);
Posted

Yes

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.