diff --git a/src/main/java/mchorse/metamorph/api/MorphHandler.java b/src/main/java/mchorse/metamorph/api/MorphHandler.java index fe117709..d0b41708 100644 --- a/src/main/java/mchorse/metamorph/api/MorphHandler.java +++ b/src/main/java/mchorse/metamorph/api/MorphHandler.java @@ -22,6 +22,7 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; @@ -246,6 +247,20 @@ public void onLivingSetAttackTarget(LivingSetAttackTargetEvent event) } } } + + /** + * Make sure the player dimension and morph dimension are synced + */ + @SubscribeEvent + public void onPlayerChangeDimension(PlayerChangedDimensionEvent event) + { + IMorphing capability = Morphing.get(event.player); + + if (capability != null && capability.getCurrentMorph() != null) + { + capability.getCurrentMorph().onChangeDimension(event.player, event.fromDim, event.toDim); + } + } /** * Run future tasks on both client and server. diff --git a/src/main/java/mchorse/metamorph/api/morphs/AbstractMorph.java b/src/main/java/mchorse/metamorph/api/morphs/AbstractMorph.java index 373f99db..e8db71c1 100644 --- a/src/main/java/mchorse/metamorph/api/morphs/AbstractMorph.java +++ b/src/main/java/mchorse/metamorph/api/morphs/AbstractMorph.java @@ -352,6 +352,11 @@ public void playStepSound(EntityLivingBase target) e.printStackTrace(); } } + + /** + * Called when the player just changed dimensions + */ + public void onChangeDimension(EntityPlayer player, int oldDim, int currentDim) { } /** * Check either if given object is the same as this morph diff --git a/src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java b/src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java index aa816f07..b5b92409 100644 --- a/src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java +++ b/src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java @@ -786,6 +786,15 @@ public void playStepSound(EntityLivingBase target) e.printStackTrace(); } } + + @Override + public void onChangeDimension(EntityPlayer player, int oldDim, int currentDim) + { + if (this.entity != null) + { + this.entity.worldObj = player.worldObj; + } + } @Override public void toNBT(NBTTagCompound tag)