mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 23:13:21 +00:00
Added 'special case' code to the Attractor Obelisk to deal with slimes, blazes and silver fish.
This commit is contained in:
1 parent
59fd28f0b7
commit
59ae19076f
1 file changed
+100
-23
@@ -1,27 +1,53 @@
|
||||
package crazypants.enderio.machine.attractor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.EntityCreature;
|
||||
import net.minecraft.entity.EntityLeashKnot;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.ai.EntityAIBase;
|
||||
import net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry;
|
||||
import net.minecraft.entity.monster.EntityBlaze;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.monster.EntityMagmaCube;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.monster.EntityPigZombie;
|
||||
import net.minecraft.entity.monster.EntitySilverfish;
|
||||
import net.minecraft.entity.monster.EntitySlime;
|
||||
import net.minecraft.entity.monster.EntitySpider;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.pathfinding.PathEntity;
|
||||
import net.minecraft.pathfinding.PathNavigate;
|
||||
import net.minecraft.profiler.Profiler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.ItemInWorldManager;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.storage.ISaveHandler;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.enderface.PacketOpenRemoteUi.PlayerProxy;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
@@ -40,7 +66,7 @@ public class TileAttractor extends AbstractMachineEntity {
|
||||
private int powerPerTick;
|
||||
private Set<EntityLiving> tracking = new HashSet<EntityLiving>();
|
||||
private int tickCounter = 0;
|
||||
private int maxMobsAttracted = 10;
|
||||
private int maxMobsAttracted = 20;
|
||||
|
||||
private ICapacitor capacitor;
|
||||
|
||||
@@ -59,9 +85,9 @@ public class TileAttractor extends AbstractMachineEntity {
|
||||
public ICapacitor getCapacitor() {
|
||||
return capacitor;
|
||||
}
|
||||
|
||||
|
||||
public int getRange() {
|
||||
return range;
|
||||
return range;
|
||||
}
|
||||
|
||||
private void setUpdrade(Capacitors capacitorType) {
|
||||
@@ -128,12 +154,14 @@ public class TileAttractor extends AbstractMachineEntity {
|
||||
}
|
||||
tickCounter++;
|
||||
if(tickCounter < 10) {
|
||||
for (EntityLiving ent : tracking) {
|
||||
onEntityTick(ent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
tickCounter = 0;
|
||||
|
||||
Set<EntityLiving> trackingThisTick = new HashSet<EntityLiving>();
|
||||
|
||||
List<EntityLiving> entsInBounds = worldObj.getEntitiesWithinAABB(EntityLiving.class, attractorBounds);
|
||||
|
||||
int candidates = 0;
|
||||
@@ -142,15 +170,14 @@ public class TileAttractor extends AbstractMachineEntity {
|
||||
candidates++;
|
||||
if(tracking.contains(ent)) {
|
||||
trackingThisTick.add(ent);
|
||||
} else if(tracking.size() < maxMobsAttracted && trackMob(ent)) {
|
||||
trackingThisTick.add(ent);
|
||||
onEntityTick(ent);
|
||||
} else if(tracking.size() < maxMobsAttracted && trackMob(ent)) {
|
||||
trackingThisTick.add(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tracking.clear();
|
||||
tracking = trackingThisTick;
|
||||
// System.out.println("TileAttractor.processTasks: " + tracking.size() + " of " + candidates + " " + new BlockCoord(this));
|
||||
|
||||
tracking = trackingThisTick;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -199,46 +226,96 @@ public class TileAttractor extends AbstractMachineEntity {
|
||||
for (int i = slotDefinition.minInputSlot; i <= slotDefinition.maxInputSlot; i++) {
|
||||
if(inventory[i] != null) {
|
||||
String mob = EnderIO.itemSoulVessel.getMobTypeFromStack(inventory[i]);
|
||||
if(mob != null && mob.equals(entityId)) {
|
||||
if(mob != null && mob.equals(entityId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trackMob(EntityLiving ent) {
|
||||
if(ent instanceof EntityEnderman) {
|
||||
private boolean trackMob(EntityLiving ent) {
|
||||
if(useSetTarget(ent)) {
|
||||
((EntityMob) ent).setTarget(getTarget());
|
||||
return true;
|
||||
} else {
|
||||
} else if(useSpecialCase(ent)) {
|
||||
return applySpecialCase(ent);
|
||||
} else {
|
||||
tracking.add(ent);
|
||||
List<EntityAITaskEntry> entries = ent.tasks.taskEntries;
|
||||
boolean hasTask = false;
|
||||
EntityAIBase remove = null;
|
||||
boolean isTracked;
|
||||
for(EntityAITaskEntry entry : entries) {
|
||||
for (EntityAITaskEntry entry : entries) {
|
||||
if(entry.action instanceof AttractTask) {
|
||||
AttractTask at = (AttractTask)entry.action;
|
||||
AttractTask at = (AttractTask) entry.action;
|
||||
if(at.coord.equals(new BlockCoord(this)) || !at.continueExecuting()) {
|
||||
//System.out.println("TileAttractor.trackMob: Removing stale tracking task");
|
||||
remove = entry.action;
|
||||
} else {
|
||||
// System.out.println("TileAttractor.trackMob: Already tracked");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(remove != null) {
|
||||
ent.tasks.removeTask(remove);
|
||||
// System.out.println("TileAttractor.trackMob: Removed task so we dont have 2");
|
||||
}
|
||||
|
||||
}
|
||||
ent.tasks.addTask(0, new AttractTask(ent, getTarget(), new BlockCoord(this)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else if(ent instanceof EntitySilverfish) {
|
||||
PathEntity pathentity = worldObj.getPathEntityToEntity(ent, getTarget(), getRange(), true, false, false, true);
|
||||
((EntityCreature) ent).setPathToEntity(pathentity);
|
||||
return true;
|
||||
}
|
||||
else if(ent instanceof EntityBlaze) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onEntityTick(EntityLiving ent) {
|
||||
if(ent instanceof EntitySlime) {
|
||||
ent.faceEntity(getTarget(), 10.0F, 20.0F);
|
||||
} else if(ent instanceof EntitySilverfish) {
|
||||
if(tickCounter < 10) {
|
||||
return;
|
||||
}
|
||||
EntitySilverfish sf = (EntitySilverfish) ent;
|
||||
PathEntity pathentity = worldObj.getPathEntityToEntity(ent, getTarget(), getRange(), true, false, false, true);
|
||||
sf.setPathToEntity(pathentity);
|
||||
} else if(ent instanceof EntityBlaze) {
|
||||
EntityBlaze mob = (EntityBlaze) ent;
|
||||
|
||||
double x = (xCoord + 0.5D - ent.posX);
|
||||
double y = (yCoord + 1D - ent.posY);
|
||||
double z = (zCoord + 0.5D - ent.posZ);
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
if(distance > 1.25) {
|
||||
double speed = 0.01;
|
||||
ent.motionX += x / distance * speed;
|
||||
if(y > 0) {
|
||||
ent.motionY += (0.30000001192092896D - ent.motionY) * 0.30000001192092896D;
|
||||
}
|
||||
ent.motionZ += z / distance * speed;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean useSetTarget(EntityLiving ent) {
|
||||
return ent instanceof EntityEnderman || ent instanceof EntityPigZombie || ent instanceof EntitySpider || ent instanceof EntitySilverfish;
|
||||
}
|
||||
|
||||
private class Target extends FakePlayer {
|
||||
|
||||
ItemStack prevWeapon;
|
||||
|
||||
Reference in new issue
Block a user