The player will now be dismounted from any ridden entity when falling out of the Aether.

This commit is contained in:
bconlon 2020-06-18 23:11:11 -07:00
parent 5041a91109
commit 9605e5cb06
3 changed files with 92 additions and 7 deletions

View file

@ -1,5 +1,6 @@
package com.legacy.aether;
import com.legacy.aether.events.AetherEntityEvents;
import net.minecraft.util.ResourceLocation;
import com.legacy.aether.blocks.BlocksAether;
@ -54,6 +55,7 @@ public class Aether {
CommonProxy.registerEvent(new PlayerAetherEvents());
CommonProxy.registerEvent(new AetherEventHandler());
CommonProxy.registerEvent(new AetherEntityEvents());
}
public static ResourceLocation locate(String location) {

View file

@ -24,7 +24,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
public class EntityHook implements IExtendedEntityProperties {
private EntityLivingBase entity;
private Entity entity;
private boolean inPortal;
@ -32,7 +32,7 @@ public class EntityHook implements IExtendedEntityProperties {
@Override
public void init(Entity entity, World world) {
this.entity = (EntityLivingBase) entity;
this.entity = entity;
}
@Override
@ -50,7 +50,9 @@ public class EntityHook implements IExtendedEntityProperties {
if (this.entity.dimension == AetherConfig.getAetherDimensionID()) {
if (this.entity.posY < -2 && this.entity.riddenByEntity == null && this.entity.ridingEntity == null) {
this.teleportEntity(false);
if (!this.entity.worldObj.isRemote) {
this.teleportEntity(false);
}
}
}
@ -96,11 +98,16 @@ public class EntityHook implements IExtendedEntityProperties {
}
}
if (this.entity.getAITarget() instanceof EntityPlayer) {
PlayerAether playerAether = PlayerAether.get((EntityPlayer) this.entity.getAITarget());
if (this.entity instanceof EntityLivingBase)
{
EntityLivingBase living = (EntityLivingBase) this.entity;
if (playerAether.getAccessoryInventory().wearingAccessory(new ItemStack(ItemsAether.invisibility_cape))) {
this.entity.setRevengeTarget(null);
if (living.getAITarget() instanceof EntityPlayer) {
PlayerAether playerAether = PlayerAether.get((EntityPlayer) living.getAITarget());
if (playerAether.getAccessoryInventory().wearingAccessory(new ItemStack(ItemsAether.invisibility_cape))) {
living.setRevengeTarget(null);
}
}
}
}

View file

@ -0,0 +1,76 @@
package com.legacy.aether.events;
import com.legacy.aether.AetherConfig;
import com.legacy.aether.world.TeleporterAether;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import java.util.List;
public class AetherEntityEvents {
@SubscribeEvent
public void onEntityUpdate(TickEvent.WorldTickEvent event)
{
if (event.phase == TickEvent.Phase.END)
{
if (!event.world.isRemote)
{
List entityList = event.world.loadedEntityList;
for (int i = 0; i < entityList.size(); i++)
{
entityUpdateEvents((Entity) entityList.get(i));
}
}
}
}
private void entityUpdateEvents(Entity entity)
{
if (entity.riddenByEntity != null)
{
if (entity.riddenByEntity.isRiding())
{
if (entity.dimension == AetherConfig.getAetherDimensionID() && !entity.worldObj.isRemote)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
int previousDimension = entity.dimension;
int transferDimension = previousDimension == AetherConfig.getAetherDimensionID() ? 0 : AetherConfig.getAetherDimensionID();
if (entity.posY <= 0)
{
if (entity.riddenByEntity != null)
{
entity.riddenByEntity = null;
}
if (entity.ridingEntity != null)
{
entity.ridingEntity = null;
}
entity.timeUntilPortal = 300;
transferEntity(false, entity, server.worldServerForDimension(previousDimension), server.worldServerForDimension(transferDimension));
}
}
}
}
}
public static void transferEntity(boolean shouldSpawnPortal, Entity entity, WorldServer previousWorldIn, WorldServer newWorldIn)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
entity.dimension = newWorldIn.provider.dimensionId;
previousWorldIn.removePlayerEntityDangerously(entity);
entity.isDead = false;
server.getConfigurationManager().transferEntityToWorld(entity, previousWorldIn.provider.dimensionId, previousWorldIn, newWorldIn, new TeleporterAether(shouldSpawnPortal, newWorldIn));
}
}