use of net.minecraft.entity.EntityLiving in project MineFactoryReloaded by powercrystals.
the class BlockConveyor method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (entity instanceof EntityPlayer && MFRConfig.conveyorNeverCapturesPlayers.getBoolean(false)) {
return;
}
// TODO: add conveyer entity blacklist: these two cases will be covered conditionally elsewhere
if (entity.getClass().getName().contains("thaumcraft.common.entities.golems") && MFRConfig.conveyorNeverCapturesTCGolems.getBoolean(false)) {
return;
}
if (!(entity instanceof EntityItem || entity instanceof EntityXPOrb || (entity instanceof EntityLiving && MFRConfig.conveyorCaptureNonItems.getBoolean(true)))) {
return;
}
TileEntity conveyor = world.getBlockTileEntity(x, y, z);
if (!(conveyor instanceof TileEntityConveyor && ((TileEntityConveyor) conveyor).getConveyorActive())) {
return;
}
if (!world.isRemote && entity instanceof EntityItem) {
specialRoute(world, x, y, z, (EntityItem) entity);
}
double xVelocity = 0;
double yVelocity = 0;
double zVelocity = 0;
int md = world.getBlockMetadata(x, y, z);
int horizDirection = md & 0x03;
boolean isUphill = (md & 0x04) != 0;
boolean isDownhill = (md & 0x08) != 0;
if (isUphill) {
yVelocity = 0.25D;
}
if (isUphill || isDownhill) {
entity.onGround = false;
}
if (horizDirection == 0) {
xVelocity = 0.1D;
} else if (horizDirection == 1) {
zVelocity = 0.1D;
} else if (horizDirection == 2) {
xVelocity = -0.1D;
} else if (horizDirection == 3) {
zVelocity = -0.1D;
}
if (horizDirection == 0 || horizDirection == 2) {
if (entity.posZ > z + 0.55D) {
zVelocity = -0.1D;
} else if (entity.posZ < z + 0.45D) {
zVelocity = 0.1D;
}
} else if (horizDirection == 1 || horizDirection == 3) {
if (entity.posX > x + 0.55D) {
xVelocity = -0.1D;
} else if (entity.posX < x + 0.45D) {
xVelocity = 0.1D;
}
}
setEntityVelocity(entity, xVelocity, yVelocity, zVelocity);
if (entity instanceof EntityLiving) {
((EntityLiving) entity).fallDistance = 0;
} else if (entity instanceof EntityItem) {
((EntityItem) entity).delayBeforeCanPickup = 40;
}
}
use of net.minecraft.entity.EntityLiving in project MineFactoryReloaded by powercrystals.
the class BlockFactoryFluid method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (world.isRemote) {
return;
}
if (entity instanceof EntityPlayer || entity instanceof EntityMob && !((EntityLiving) entity).isEntityUndead()) {
EntityLiving ent = (EntityLiving) entity;
if (blockID == MineFactoryReloadedCore.sludgeLiquid.blockID) {
ent.addPotionEffect(new PotionEffect(Potion.poison.id, 12 * 20, 0));
ent.addPotionEffect(new PotionEffect(Potion.weakness.id, 12 * 20, 0));
ent.addPotionEffect(new PotionEffect(Potion.confusion.id, 12 * 20, 0));
} else if (blockID == MineFactoryReloadedCore.sewageLiquid.blockID) {
ent.addPotionEffect(new PotionEffect(Potion.hunger.id, 12 * 20, 0));
ent.addPotionEffect(new PotionEffect(Potion.poison.id, 12 * 20, 0));
ent.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 12 * 20, 0));
} else if (blockID == MineFactoryReloadedCore.essenceLiquid.blockID) {
ent.addPotionEffect(new PotionEffect(Potion.nightVision.id, 60 * 20, 0));
} else if (blockID == MineFactoryReloadedCore.milkLiquid.blockID) {
ent.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 6 * 20, 0));
} else if (blockID == MineFactoryReloadedCore.biofuelLiquid.blockID) {
ent.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 12 * 20, 0));
}
}
super.onEntityCollidedWithBlock(world, x, y, z, entity);
}
use of net.minecraft.entity.EntityLiving in project MineFactoryReloaded by powercrystals.
the class ServerPacketHandler method onPacketData.
@SuppressWarnings("rawtypes")
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
int packetType = PacketWrapper.readPacketID(data);
if (// client -> server: autoenchanter GUI buttons
packetType == Packets.EnchanterButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoEnchanter) {
((TileEntityAutoEnchanter) te).setTargetLevel(((TileEntityAutoEnchanter) te).getTargetLevel() + (Integer) packetReadout[3]);
} else if (te instanceof TileEntityBlockSmasher) {
((TileEntityBlockSmasher) te).setFortune(((TileEntityBlockSmasher) te).getFortune() + (Integer) packetReadout[3]);
} else if (te instanceof TileEntityAutoDisenchanter) {
Integer v = (Integer) packetReadout[3];
((TileEntityAutoDisenchanter) te).setRepeatDisenchant(v == 1 ? true : false);
}
} else if (// client -> server: harvester setting
packetType == Packets.HarvesterButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, String.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityHarvester) {
((TileEntityHarvester) te).getSettings().put((String) packetReadout[3], (Boolean) packetReadout[4]);
}
} else if (// client -> server: toggle chronotyper
packetType == Packets.ChronotyperButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityChronotyper) {
((TileEntityChronotyper) te).setMoveOld(!((TileEntityChronotyper) te).getMoveOld());
}
} else if (// client -> server: toggle DSU output side
packetType == Packets.DSUButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityDeepStorageUnit) {
int side = (Integer) packetReadout[3];
((TileEntityDeepStorageUnit) te).setSideIsOutput(side, (!((TileEntityDeepStorageUnit) te).getIsSideOutput(side)));
}
} else if (// client -> server: copy record
packetType == Packets.AutoJukeboxButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoJukebox) {
TileEntityAutoJukebox j = ((TileEntityAutoJukebox) te);
int button = (Integer) packetReadout[3];
if (button == 1)
j.playRecord();
else if (button == 2)
j.stopRecord();
else if (button == 3)
j.copyRecord();
}
} else if (// client -> server: toggle autospawner
packetType == Packets.AutoSpawnerButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoSpawner) {
((TileEntityAutoSpawner) te).setSpawnExact(!((TileEntityAutoSpawner) te).getSpawnExact());
}
} else if (// client -> server: request circuit from server
packetType == Packets.LogicRequestCircuitDefinition) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).sendCircuitDefinition((Integer) packetReadout[3]);
}
} else if (// client -> server: set circuit
packetType == Packets.LogicSetCircuit) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, String.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).initCircuit((Integer) packetReadout[3], (String) packetReadout[4]);
((TileEntityRedNetLogic) te).sendCircuitDefinition((Integer) packetReadout[3]);
}
} else if (// client -> server: set pin
packetType == Packets.LogicSetPin) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
if ((Integer) packetReadout[3] == 0) {
((TileEntityRedNetLogic) te).setInputPinMapping((Integer) packetReadout[4], (Integer) packetReadout[5], (Integer) packetReadout[6], (Integer) packetReadout[7]);
} else if ((Integer) packetReadout[3] == 1) {
((TileEntityRedNetLogic) te).setOutputPinMapping((Integer) packetReadout[4], (Integer) packetReadout[5], (Integer) packetReadout[6], (Integer) packetReadout[7]);
}
((TileEntityRedNetLogic) te).sendCircuitDefinition((Integer) packetReadout[4]);
}
} else if (// client -> server: set circuit
packetType == Packets.LogicReinitialize) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).reinitialize((EntityPlayer) player);
}
} else if (// client -> server: toggle 'levels'/'reject unmapped' mode
packetType == Packets.RouterButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityEnchantmentRouter) {
((TileEntityEnchantmentRouter) te).setMatchLevels(!((TileEntityEnchantmentRouter) te).getMatchLevels());
} else if (te instanceof TileEntityItemRouter) {
((TileEntityItemRouter) te).setRejectUnmapped(!((TileEntityItemRouter) te).getRejectUnmapped());
}
} else if (// client -> server: client clicked on a fake slot
packetType == Packets.FakeSlotChange) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
ItemStack playerStack = ((EntityPlayer) player).inventory.getItemStack();
Integer slotNumber = (Integer) packetReadout[3];
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof IInventory) {
if (playerStack == null) {
((IInventory) te).setInventorySlotContents(slotNumber, null);
} else {
playerStack = playerStack.copy();
playerStack.stackSize = 1;
((IInventory) te).setInventorySlotContents(slotNumber, playerStack);
}
}
} else if (packetType == Packets.RocketLaunchWithLock) {
Class[] decodeAs = { Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
World world = ((EntityPlayer) player).worldObj;
Entity owner = world.getEntityByID((Integer) packetReadout[0]);
Entity target = null;
if (((Integer) packetReadout[1]) != Integer.MIN_VALUE) {
target = world.getEntityByID((Integer) packetReadout[1]);
}
if (owner instanceof EntityLiving) {
EntityRocket r = new EntityRocket(world, ((EntityLiving) owner), target);
world.spawnEntityInWorld(r);
}
}
}
use of net.minecraft.entity.EntityLiving in project MineFactoryReloaded by powercrystals.
the class TileEntityAutoSpawner method activateMachine.
@Override
protected boolean activateMachine() {
ItemStack item = getStackInSlot(0);
if (!isStackValidForSlot(0, item)) {
setWorkDone(0);
return false;
}
NBTTagCompound itemTag = item.getTagCompound();
String entityID = itemTag.getString("id");
boolean isBlackListed = MFRRegistry.getAutoSpawnerBlacklist().contains(entityID);
blackList: if (!isBlackListed) {
Class<?> e = (Class<?>) EntityList.stringToClassMapping.get(entityID);
if (e == null) {
isBlackListed = true;
break blackList;
}
for (Class<?> t : MFRRegistry.getAutoSpawnerClassBlacklist()) {
if (t.isAssignableFrom(e)) {
isBlackListed = true;
break blackList;
}
}
}
if (isBlackListed) {
setWorkDone(0);
return false;
}
if (getWorkDone() < getWorkMax()) {
if (_tank.getLiquid() != null && _tank.getLiquid().amount >= 10) {
_tank.getLiquid().amount -= 10;
setWorkDone(getWorkDone() + 1);
return true;
} else {
return false;
}
} else {
Entity spawnedEntity = EntityList.createEntityByName(entityID, worldObj);
if (!(spawnedEntity instanceof EntityLiving)) {
return false;
}
EntityLiving spawnedLiving = (EntityLiving) spawnedEntity;
if (_spawnExact) {
NBTTagCompound tag = (NBTTagCompound) itemTag.copy();
spawnedLiving.readEntityFromNBT(tag);
for (int i = 0; i < 5; ++i) {
spawnedLiving.func_96120_a(i, 0);
}
}
double x = xCoord + (worldObj.rand.nextDouble() - worldObj.rand.nextDouble()) * _spawnRange;
double y = yCoord + worldObj.rand.nextInt(3) - 1;
double z = zCoord + (worldObj.rand.nextDouble() - worldObj.rand.nextDouble()) * _spawnRange;
spawnedLiving.setLocationAndAngles(x, y, z, worldObj.rand.nextFloat() * 360.0F, 0.0F);
if (!worldObj.checkNoEntityCollision(spawnedLiving.boundingBox) || !worldObj.getCollidingBoundingBoxes(spawnedLiving, spawnedLiving.boundingBox).isEmpty() || (worldObj.isAnyLiquid(spawnedLiving.boundingBox) != (spawnedLiving instanceof EntityWaterMob))) {
return false;
}
if (!_spawnExact) {
spawnedLiving.initCreature();
}
worldObj.spawnEntityInWorld(spawnedLiving);
worldObj.playAuxSFX(2004, this.xCoord, this.yCoord, this.zCoord, 0);
spawnedLiving.spawnExplosionParticle();
setWorkDone(0);
return true;
}
}
use of net.minecraft.entity.EntityLiving in project NetherEx by LogicTechCorp.
the class EntityGoldGolem method initEntityAI.
@Override
protected void initEntityAI() {
tasks.addTask(1, new EntityAIAttackMelee(this, 1.0D, true));
tasks.addTask(2, new EntityAIMoveTowardsTarget(this, 0.9D, 32.0F));
tasks.addTask(3, new EntityAIMoveThroughVillage(this, 0.6D, true));
tasks.addTask(4, new EntityAIMoveTowardsRestriction(this, 1.0D));
tasks.addTask(5, new EntityAIGoldGolemLookAtPigtificate(this));
tasks.addTask(6, new EntityAIWanderAvoidWater(this, 0.6D));
tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
tasks.addTask(8, new EntityAILookIdle(this));
targetTasks.addTask(1, new EntityAIGoldGolemDefendVillage(this));
targetTasks.addTask(2, new EntityAIHurtByTarget(this, false));
targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityLiving.class, 10, false, true, entity -> entity != null && IMob.VISIBLE_MOB_SELECTOR.apply((EntityLiving) entity) && !(entity instanceof EntitySporeCreeper)));
}
Aggregations