mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 13:10:13 +00:00
#1668 Fix attractor obelisk behavior with endermen
This commit is contained in:
1 parent
d98be8dd86
commit
4fa83c1114
3 files changed
+49
-14
No files matched your search
@@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
@@ -15,6 +16,7 @@ public class BlockAttractor extends BlockObeliskAbstract<TileAttractor> {
|
||||
public static BlockAttractor create() {
|
||||
BlockAttractor res = new BlockAttractor();
|
||||
res.init();
|
||||
MinecraftForge.EVENT_BUS.register(new EndermanFixer());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package crazypants.enderio.machine.obelisk.attractor;
|
||||
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class EndermanFixer {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEndermanTeleport(EnderTeleportEvent event) {
|
||||
if (event.entityLiving instanceof EntityEnderman && event.entityLiving.getEntityData().getBoolean("EIO:tracked")) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.Set;
|
||||
import net.minecraft.entity.EntityCreature;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.ai.EntityAIBase;
|
||||
import net.minecraft.entity.ai.EntityAITasks;
|
||||
import net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry;
|
||||
@@ -25,6 +26,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSettings.GameType;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -35,6 +37,7 @@ import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.AbstractPowerConsumerEntity;
|
||||
import crazypants.enderio.machine.FakePlayerEIO;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.ranged.IRanged;
|
||||
import crazypants.enderio.machine.ranged.RangeEntity;
|
||||
@@ -166,13 +169,31 @@ public class TileAttractor extends AbstractPowerConsumerEntity implements IRange
|
||||
onEntityTick(ent);
|
||||
} else if(tracking.size() < maxMobsAttracted && trackMob(ent)) {
|
||||
trackingThisTick.add(ent);
|
||||
onTracked(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (EntityLiving e : tracking) {
|
||||
if (!trackingThisTick.contains(e)) {
|
||||
onUntracked(e);
|
||||
}
|
||||
}
|
||||
tracking.clear();
|
||||
tracking = trackingThisTick;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onUntracked(EntityLiving e) {
|
||||
if (e instanceof EntityEnderman) {
|
||||
e.getEntityData().setBoolean("EIO:tracked", false);
|
||||
}
|
||||
}
|
||||
|
||||
private void onTracked(EntityLiving e) {
|
||||
if (e instanceof EntityEnderman) {
|
||||
e.getEntityData().setBoolean("EIO:tracked", true);
|
||||
}
|
||||
}
|
||||
|
||||
protected double usePower() {
|
||||
return usePower(getPowerUsePerTick());
|
||||
@@ -281,10 +302,6 @@ public class TileAttractor extends AbstractPowerConsumerEntity implements IRange
|
||||
}
|
||||
|
||||
private boolean applySpecialCase(EntityLiving ent) {
|
||||
return ent instanceof EntitySlime || ent instanceof EntitySilverfish || ent instanceof EntityBlaze;
|
||||
}
|
||||
|
||||
private boolean useSpecialCase(EntityLiving ent) {
|
||||
if(ent instanceof EntitySlime) {
|
||||
ent.faceEntity(getTarget(), 10.0F, 20.0F);
|
||||
return true;
|
||||
@@ -298,6 +315,10 @@ public class TileAttractor extends AbstractPowerConsumerEntity implements IRange
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean useSpecialCase(EntityLiving ent) {
|
||||
return ent instanceof EntitySlime || ent instanceof EntitySilverfish || ent instanceof EntityBlaze;
|
||||
}
|
||||
|
||||
private void onEntityTick(EntityLiving ent) {
|
||||
if(ent instanceof EntitySlime) {
|
||||
ent.faceEntity(getTarget(), 10.0F, 20.0F);
|
||||
@@ -325,7 +346,9 @@ public class TileAttractor extends AbstractPowerConsumerEntity implements IRange
|
||||
}
|
||||
} else if(ent instanceof EntityPigZombie || ent instanceof EntitySpider) {
|
||||
forceMove(ent);
|
||||
}
|
||||
} else if(ent instanceof EntityEnderman) {
|
||||
((EntityEnderman) ent).setTarget(getTarget());
|
||||
}
|
||||
}
|
||||
|
||||
private void forceMove(EntityLiving ent) {
|
||||
@@ -346,19 +369,14 @@ public class TileAttractor extends AbstractPowerConsumerEntity implements IRange
|
||||
}
|
||||
|
||||
private boolean useSetTarget(EntityLiving ent) {
|
||||
return ent instanceof EntityEnderman || ent instanceof EntityPigZombie || ent instanceof EntitySpider || ent instanceof EntitySilverfish;
|
||||
return ent instanceof EntityPigZombie || ent instanceof EntitySpider || ent instanceof EntitySilverfish;
|
||||
}
|
||||
|
||||
private class Target extends FakePlayer {
|
||||
|
||||
ItemStack prevWeapon;
|
||||
private class Target extends FakePlayerEIO {
|
||||
|
||||
public Target() {
|
||||
super(MinecraftServer.getServer().worldServerForDimension(getWorldObj().provider.dimensionId), new GameProfile(null,
|
||||
ModObject.blockAttractor.unlocalisedName + ":" + getLocation()));
|
||||
posX = xCoord + 0.5;
|
||||
posY = yCoord + 1.5;
|
||||
posZ = zCoord + 0.5;
|
||||
super(getWorldObj(), getLocation(), new GameProfile(null, ModObject.blockAttractor.unlocalisedName + ":" + getLocation()));
|
||||
posY += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user