Posted January 28, 20178 yr I want to make an event when player die's to he can't eat for specified time. I'm using PlayerEvent.Clone for the isWasDeath in IF so when player dies it does that to he can't eat for specified time. But I can't seem to find any kind of timer to make a player not eat in getEntityPlayer.
January 28, 20178 yr PlayerInteractEvent.RightClickItem is fired when a player right clicks with an item, you can cancel it to prevent Item#onItemRightClick from being called. ItemStack#getItemUseAction returns the Item 's use action, this will be EnumAction.EAT for food. PlayerInteractEvent.RightClickBlock is fired when a player right clicks a block, you can use this to detect the player right clicking a cake and cancel the event to prevent Block#onBlockActivated , Item#onItemUse and Item#onItemUseFirst from being called. To store the timer, you'll want to use the Capability system or a Potion / PotionEffect . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
January 28, 20178 yr Author I did this for now, but I cannot right click with anything anymore. Its probably because the EnumAction.EAT needs to be in the RightClickItem event but I don't know how to put it there, I can't find any event type for EnumAction in RightClickItem. And how do I merge RightClickItem and PlayerEvent.Clone together? I never placed 2 Events into SubscribeEvent. @SubscribeEvent public void InteractItem( PlayerInteractEvent.RightClickItem event) { if (ConfigHandler.noEating) event.setCanceled(true); } public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.EAT; } @SubscribeEvent public void FoodEat(PlayerEvent.Clone event) { if (ConfigHandler.noEating) { if (event.isWasDeath()) { event.getEntityPlayer().addPotionEffect(new PotionEffect(MainClass.appetiteEffect, ConfigHandler.noEatingTime)); } } } If I try to put event.getItemStack().getItemUseAction(EnumAction.EAT); into the RightClickItem event it gives me an error (It cannot be applied to EnumAction)
January 28, 20178 yr This @SubscribeEvent public void InteractItem( PlayerInteractEvent.RightClickItem event) { if (ConfigHandler.noEating) event.setCanceled(true); } In no way knows if the player's died recently. All it does is say "is the config option to disable eating after death enabled? yes? ok, no eating." public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.EAT; } And this doesn't go there. This is an ItemStack method you've thrown into your event handler because....why? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 28, 20178 yr You need to call ItemStack#getItemUseAction on the ItemStack from the event and check if the returned value is EnumAction.EAT . Don't create your own getItemUseAction method that always returns EnumAction.EAT , this makes no sense. You should also check if the player has your potion effect before you cancel the event. You don't merge the events together. A class can contain any number of @SubscribeEvent methods. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
January 28, 20178 yr Author This works perfectly... the problem is to I can't see the potion countdown in my inventory, I only see its particles even though I added the texture's for the potion. @SubscribeEvent public void applyEffect(PlayerEvent.Clone player) { if (player.isWasDeath()) if (ConfigHandler.noEating) player.getEntityPlayer().addPotionEffect(new PotionEffect(ModPotions.appetite, ConfigHandler.noEatingTime)); } @SubscribeEvent public void itemInteract(PlayerInteractEvent.RightClickItem event) { if (ConfigHandler.noEating) if (event.getItemStack().getItemUseAction() == EnumAction.EAT) if (event.getEntityPlayer().isPotionActive(ModPotions.appetite)) event.setCanceled(true); } PotionDefault Class public class PotionDefault extends Potion { private static final ResourceLocation POTIONS_LOCATION = new ResourceLocation("keephunger:textures/potions/inventory.png"); protected PotionDefault(boolean isBadEffectIn, int liquidColorIn, int x, int y) { super(isBadEffectIn, liquidColorIn); this.setIconIndex(x, y); } @Override @SideOnly(Side.CLIENT) public boolean hasStatusIcon() { Minecraft.getMinecraft().getTextureManager().bindTexture(POTIONS_LOCATION); return super.hasStatusIcon(); } } No Appetite Effect public class NoAppetiteEffect extends PotionDefault { public NoAppetiteEffect(int id) { super(true, 0x8DCDA3, 1,1); } } ModPotions Class public class ModPotions { public static Potion appetite; public static void init() { appetite = registerPotion("appetite", new NoAppetiteEffect(26).setPotionName("potion.appetite")); } public static Potion registerPotion(String name, Potion potion) { GameRegistry.register(potion, new ResourceLocation(MainClass.MODID, name)); return potion; } public static PotionType registerPotionType(String name, PotionType potionType) { GameRegistry.register(potionType, new ResourceLocation(MainClass.MODID, name)); return potionType; } }
January 29, 20178 yr Author I fixed everything and now I'm trying to get the RightClickBlock for cake's, I just cannot find anything to specify a block I right clicked.
January 29, 20178 yr Author Thank you! Everything works perfectly right now. Only problem was to the duration for the effect was in ticks so I just multiplied it by 20 to it goes back to 300 seconds instead of 15 seconds. I was just wondering is there a way to make the effect not disappear even when you drink milk, so if someone gets poison he drinks milk and gets rid of it but my effect still stays. For now I'm just using the RightClickItem event so you cannot right click milk.
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.