Posted July 21, 20205 yr So it has come to my attention that I have no idea what I am doing when it comes to events. I have one event, injectPotion, that is supposed to: Use the LivingHurtEvent to check if the true damage source is a player. Get the item in their hand. Check to see if that item is my custom potion item, which extends PotionItem. Then search that item for its effects And then apply those effects to the victim of the damage. However, this does not happen and I don't think the current issue is with how I am applying the effects, because I tried to replace the potion effect code with code that clears the player entity's inventory, and it still didn't work. So in short, how to I fix this event and is there a way to improve the quality of the code in my main class? Main Class: package com.oberonpuck.minormagicks; //All of imports are here but I commented them out for ease of reading // The value here should match an entry in the META-INF/mods.toml file @Mod("minormagicks") public class MinorMagicks { public static MinorMagicks instance; private static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "minormagicks"; public MinorMagicks() { instance = this; final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(this::setup); modEventBus.addListener(this::doClientStuff); modEventBus.addListener(this::injectPotion); ItemRegistryHandler.ITEMS.register(modEventBus); PotionRegistryHandler.POTIONS.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { PotionRegistryHandler.removeRecipes(); MagicksPotionBrewing.init(); } private void doClientStuff(final FMLClientSetupEvent event) { } private void injectPotion (LivingHurtEvent event) { if(event.getSource().getTrueSource() instanceof PlayerEntity) { PlayerEntity playerentity = (PlayerEntity) event.getSource().getTrueSource(); LivingEntity entityLiving = event.getEntityLiving(); ItemStack stack = playerentity.getHeldItemMainhand(); World world = playerentity.getEntityWorld(); if(stack.getItem() instanceof GelledPotionItem) { if (playerentity instanceof ServerPlayerEntity) { CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayerEntity)playerentity, stack); } if (!world.isRemote) { for(EffectInstance effectinstance : PotionUtils.getEffectsFromStack(stack)) { if (effectinstance.getPotion().isInstant()) { effectinstance.getPotion().affectEntity(playerentity, playerentity, entityLiving, effectinstance.getAmplifier(), 1.0D); } else { entityLiving.addPotionEffect(new EffectInstance(effectinstance)); } } } if (playerentity != null) { playerentity.addStat(Stats.ITEM_USED.get(ItemRegistryHandler.GELLED_POTION.get())); if (!playerentity.abilities.isCreativeMode) { stack.shrink(1); } } if (playerentity == null || !playerentity.abilities.isCreativeMode) { if (stack.isEmpty()) { playerentity.inventory.storeItemStack(new ItemStack(Items.GLASS_BOTTLE)); } if (playerentity != null) { playerentity.inventory.storeItemStack(new ItemStack(Items.GLASS_BOTTLE)); } } } } } }
July 21, 20205 yr Learn the difference between the forge and mod event bus. Hint: LivingHurtEvent is not called on the mod event bus. 8 minutes ago, OberonPuck said: !world.isRemote 9 minutes ago, OberonPuck said: playerentity instanceof ServerPlayerEntity These two also do the exact same thing. Edited July 21, 20205 yr by ChampionAsh5357
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.