diff --git a/src/main/java/morph/api/MorphAcquiredEvent.java b/src/main/java/morph/api/MorphAcquiredEvent.java new file mode 100644 index 00000000..b8fbdcfb --- /dev/null +++ b/src/main/java/morph/api/MorphAcquiredEvent.java @@ -0,0 +1,18 @@ +package morph.api; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.event.entity.player.PlayerEvent; + +@Cancelable +public class MorphAcquiredEvent extends PlayerEvent +{ + public final EntityLivingBase acquiredMorph; + + public MorphAcquiredEvent(EntityPlayer player, EntityLivingBase acquired) + { + super(player); + acquiredMorph = acquired; + } +} diff --git a/src/main/java/morph/api/MorphEvent.java b/src/main/java/morph/api/MorphEvent.java new file mode 100644 index 00000000..ce6aa4b6 --- /dev/null +++ b/src/main/java/morph/api/MorphEvent.java @@ -0,0 +1,23 @@ +package morph.api; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.entity.EntityLivingBase; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraft.entity.player.EntityPlayer; + +@Cancelable +public class MorphEvent extends PlayerEvent +{ + //Can be null + public final EntityLivingBase prevMorph; + + //Will never be null + public final EntityLivingBase morph; + + public MorphEvent(EntityPlayer player, EntityLivingBase prevMorph, EntityLivingBase morph) + { + super(player); + this.prevMorph = prevMorph; + this.morph = morph; + } +} diff --git a/src/main/java/morph/client/core/TickHandlerClient.java b/src/main/java/morph/client/core/TickHandlerClient.java index 44013fe5..03c17d3e 100644 --- a/src/main/java/morph/client/core/TickHandlerClient.java +++ b/src/main/java/morph/client/core/TickHandlerClient.java @@ -695,10 +695,6 @@ public void worldTick(TickEvent.ClientTickEvent event) if(info.getMorphing()) { -// System.out.println(info.morphProgress); -// System.out.println(info.prevState); -// System.out.println(info.player); -// System.out.println(world.playerEntities.size()); info.morphProgress++; if(info.morphProgress > 80) { diff --git a/src/main/java/morph/common/core/EntityHelper.java b/src/main/java/morph/common/core/EntityHelper.java index 6579e845..24dbb40b 100644 --- a/src/main/java/morph/common/core/EntityHelper.java +++ b/src/main/java/morph/common/core/EntityHelper.java @@ -2,6 +2,8 @@ import ichun.common.core.EntityHelperBase; import ichun.common.core.network.PacketHandler; +import morph.api.MorphAcquiredEvent; +import morph.api.MorphEvent; import morph.common.Morph; import morph.common.morph.MorphHandler; import morph.common.morph.MorphInfo; @@ -13,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.FakePlayer; public class EntityHelper extends EntityHelperBase @@ -81,7 +84,7 @@ else if(info.getMorphing() || info.nextState.entInstance == living) MorphState prevState = new MorphState(player.worldObj, player.getCommandSenderName(), username1, prevTag, false); MorphState nextState = new MorphState(player.worldObj, player.getCommandSenderName(), username2, nextTag, false); - if(Morph.proxy.tickHandlerServer.hasMorphState(player, nextState)) + if(Morph.proxy.tickHandlerServer.hasMorphState(player, nextState) || !forced && MinecraftForge.EVENT_BUS.post(new MorphAcquiredEvent(player, nextState.entInstance))) { return false; } @@ -108,12 +111,15 @@ else if(info.getMorphing() || info.nextState.entInstance == living) info2.morphAbilities = info3.morphAbilities; info2.healthOffset = info3.healthOffset; } - - Morph.proxy.tickHandlerServer.setPlayerMorphInfo(player, info2); - PacketHandler.sendToAll(Morph.channels, info2.getMorphInfoAsPacket()); + if(!MinecraftForge.EVENT_BUS.post(new MorphEvent(player, info2.prevState.entInstance, info2.nextState.entInstance))) + { + Morph.proxy.tickHandlerServer.setPlayerMorphInfo(player, info2); - player.worldObj.playSoundAtEntity(player, "morph:morph", 1.0F, 1.0F); + PacketHandler.sendToAll(Morph.channels, info2.getMorphInfoAsPacket()); + + player.worldObj.playSoundAtEntity(player, "morph:morph", 1.0F, 1.0F); + } } if(kill) diff --git a/src/main/java/morph/common/packet/PacketGuiInput.java b/src/main/java/morph/common/packet/PacketGuiInput.java index e63743f2..b73cc07c 100644 --- a/src/main/java/morph/common/packet/PacketGuiInput.java +++ b/src/main/java/morph/common/packet/PacketGuiInput.java @@ -6,6 +6,7 @@ import ichun.common.core.network.PacketHandler; import io.netty.buffer.ByteBuf; import morph.api.Ability; +import morph.api.MorphEvent; import morph.common.Morph; import morph.common.ability.AbilityHandler; import morph.common.morph.MorphHandler; @@ -14,6 +15,7 @@ import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraftforge.common.MinecraftForge; import java.util.ArrayList; @@ -98,11 +100,15 @@ public void execute(Side side, EntityPlayer player) } } - Morph.proxy.tickHandlerServer.setPlayerMorphInfo(player, info2); + if(!MinecraftForge.EVENT_BUS.post(new MorphEvent(player, info2.prevState.entInstance, info2.nextState.entInstance))) + { + Morph.proxy.tickHandlerServer.setPlayerMorphInfo(player, info2); + + PacketHandler.sendToAll(Morph.channels, info2.getMorphInfoAsPacket()); - PacketHandler.sendToAll(Morph.channels, info2.getMorphInfoAsPacket()); + player.worldObj.playSoundAtEntity(player, "morph:morph", 1.0F, 1.0F); + } - player.worldObj.playSoundAtEntity(player, "morph:morph", 1.0F, 1.0F); break; } case 1: