Skip to content

Commit

Permalink
Add some Morph events for cancellation by other mods.
Browse files Browse the repository at this point in the history
  • Loading branch information
iChun committed Aug 6, 2014
1 parent c67db89 commit 7e5012b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/main/java/morph/api/MorphAcquiredEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions src/main/java/morph/api/MorphEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 0 additions & 4 deletions src/main/java/morph/client/core/TickHandlerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/morph/common/core/EntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/morph/common/packet/PacketGuiInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7e5012b

Please sign in to comment.