use of net.minecraft.entity.passive.EntityAnimal in project Railcraft by Railcraft.
the class TileFeedStation method update.
@Override
public void update() {
super.update();
if (Game.isClient(getWorld())) {
return;
}
ItemStack feed = getStackInSlot(0);
if (clock % (MIN_FEED_INTERVAL / 4) == 0 && (feed == null || feed.stackSize < feed.getMaxStackSize())) {
InventoryComposite chests = InvTools.getAdjacentInventories(worldObj, getPos());
InvTools.moveOneItem(chests, feedInv, StandardStackFilters.FEED);
}
feed = getStackInSlot(0);
feedTime--;
if (!powered && feed != null && feed.stackSize > 0 && feedTime <= 0) {
feedTime = MIN_FEED_INTERVAL + rand.nextInt(FEED_VARIANCE);
//TODO: test (maybe we can draw this somehow?)
AxisAlignedBB box = AABBFactory.start().createBoxForTileAt(getPos()).raiseFloor(-1).raiseCeiling(2).expandHorizontally(AREA).build();
List<EntityAnimal> animals = worldObj.getEntitiesWithinAABB(EntityAnimal.class, box);
for (EntityAnimal target : animals) {
if (target.isBreedingItem(getStackInSlot(0)) && feedAnimal(target)) {
if (feedCounter <= 0) {
setInventorySlotContents(0, InvTools.depleteItem(feed));
feedCounter = ANIMALS_PER_FOOD;
}
feedCounter--;
sendFeedPacket(target);
break;
}
}
}
}
use of net.minecraft.entity.passive.EntityAnimal in project VanillaTeleporter by dyeo.
the class BlockTeleporter method onEntityWalk.
@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
TeleporterNode destinationNode = null;
IBlockState state = world.getBlockState(pos);
EnumType type = EnumType.byMetadata(getMetaFromState(state));
if (entity instanceof EntityLivingBase && entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
ITeleportHandler teleportHandler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
if (!world.isRemote) {
if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
teleportHandler.setOnTeleporter(entity.getPosition().distanceSq(pos) <= 1);
teleportHandler.setDimension(entity.dimension);
if (teleportHandler.getOnTeleporter()) {
boolean isHostile = (entity instanceof EntityMob) || (entity instanceof EntityWolf && ((EntityWolf) entity).isAngry());
boolean isPassive = (entity instanceof EntityAnimal);
if ((isHostile == false || isHostile == ModConfiguration.teleportHostileMobs) && (isPassive == false || isPassive == ModConfiguration.teleportPassiveMobs)) {
destinationNode = TeleporterUtility.teleport((EntityLivingBase) entity, pos);
}
}
}
}
if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
TileEntityTeleporter tEnt = (TileEntityTeleporter) world.getTileEntity(pos);
if (tEnt != null) {
tEnt.spawnParticles();
}
}
if (type.isRecall() && entity instanceof EntityPlayerMP && destinationNode != null) {
WorldServer nextWorld = world.getMinecraftServer().worldServerForDimension(destinationNode.dimension);
breakBlockRecall(world, nextWorld, pos, destinationNode.pos, state, (EntityPlayerMP) entity);
}
}
}
use of net.minecraft.entity.passive.EntityAnimal in project BluePower by Qmunity.
the class TileDeployer method rightClick.
/**
* Be sure to set up the fake player's hotbar with the right clicked items. starting with hotbar slot 0.
* @param player
* @param useItems this method will set the current selected slot of the fake player to 0, and move on to the next slot useItems - 1 times.
* So to use the first slot only, pass 1, to use the full hotbar, 9.
* @return
*/
protected boolean rightClick(FakePlayer player, int useItems) {
if (useItems > 9)
throw new IllegalArgumentException("Hotbar is 9 items in width! You're trying " + useItems + "!");
ForgeDirection faceDir = getFacingDirection();
int dx = faceDir.offsetX;
int dy = faceDir.offsetY;
int dz = faceDir.offsetZ;
int x = xCoord + dx;
int y = yCoord + dy;
int z = zCoord + dz;
player.setPosition(x + 0.5, y + 0.5 - player.eyeHeight, z + 0.5);
player.rotationPitch = faceDir.offsetY * -90;
switch(faceDir) {
case NORTH:
player.rotationYaw = 180;
break;
case SOUTH:
player.rotationYaw = 0;
break;
case WEST:
player.rotationYaw = 90;
break;
case EAST:
player.rotationYaw = -90;
}
try {
PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, x, y, z, faceDir.ordinal(), worldObj);
if (event.isCanceled())
return false;
Block block = worldObj.getBlock(x, y, z);
List<EntityLivingBase> detectedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1));
Entity entity = detectedEntities.isEmpty() ? null : detectedEntities.get(worldObj.rand.nextInt(detectedEntities.size()));
if (entity != null) {
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
if (canDeployItem(stack) && stack.getItem().itemInteractionForEntity(stack, player, (EntityLivingBase) entity))
return true;
if (entity instanceof EntityAnimal && ((EntityAnimal) entity).interact(player))
return true;
}
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
if (canDeployItem(stack) && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz))
return true;
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
if (!worldObj.isAirBlock(x, y, x) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz))
return true;
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
boolean isGoingToShift = false;
if (stack != null) {
if (stack.getItem() instanceof ItemReed || stack.getItem() instanceof ItemRedstone) {
isGoingToShift = true;
}
}
int useX = isGoingToShift ? xCoord : x;
int useY = isGoingToShift ? yCoord : y;
int useZ = isGoingToShift ? zCoord : z;
if (canDeployItem(stack) && stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz))
return true;
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
if (canDeployItem(stack)) {
ItemStack copy = stack.copy();
player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
if (!copy.isItemEqual(stack))
return true;
}
}
return false;
} catch (Throwable e) {
BluePower.log.error("Deployer crashed! Stacktrace: ");
e.printStackTrace();
return true;
}
}
use of net.minecraft.entity.passive.EntityAnimal in project MineFactoryReloaded by powercrystals.
the class TileEntitySewer method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
if (worldObj.isRemote) {
return;
}
_tick++;
if (_nextSewerCheckTick <= worldObj.getTotalWorldTime()) {
Area a = new Area(BlockPosition.fromFactoryTile(this), _areaManager.getRadius(), 0, 0);
_jammed = false;
for (BlockPosition bp : a.getPositionsBottomFirst()) {
if (worldObj.getBlockId(bp.x, bp.y, bp.z) == MineFactoryReloadedCore.machineBlocks.get(0).blockID && worldObj.getBlockMetadata(bp.x, bp.y, bp.z) == Machine.Sewer.getMeta() && !(bp.x == xCoord && bp.y == yCoord && bp.z == zCoord)) {
_jammed = true;
break;
}
}
_nextSewerCheckTick = worldObj.getTotalWorldTime() + 800 + worldObj.rand.nextInt(800);
}
if (_tick >= 31 && !_jammed) {
_tick = 0;
List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
double massFound = 0;
for (Object o : entities) {
if (o instanceof EntityAnimal || o instanceof EntityVillager) {
massFound += Math.pow(((EntityLiving) o).boundingBox.getAverageEdgeLength(), 2);
} else if (o instanceof EntityPlayer && ((EntityPlayer) o).isSneaking()) {
massFound += Math.pow(((EntityLiving) o).boundingBox.getAverageEdgeLength(), 2);
}
}
if (massFound > 0) {
_tank.fill(LiquidDictionary.getLiquid("sewage", (int) (25 * massFound)), true);
} else // TODO: add a second tank to the sewer for essence
if (_tank.getLiquid() == null || _tank.getLiquid().isLiquidEqual(LiquidDictionary.getLiquid("mobEssence", 1))) {
int maxAmount = Math.max(_tank.getCapacity() - (_tank.getLiquid() != null ? _tank.getLiquid().amount : 0), 0);
if (maxAmount < 0) {
return;
}
entities = worldObj.getEntitiesWithinAABB(EntityXPOrb.class, _areaManager.getHarvestArea().toAxisAlignedBB());
for (Object o : entities) {
Entity e = (Entity) o;
if (e != null & e instanceof EntityXPOrb && !e.isDead) {
EntityXPOrb orb = (EntityXPOrb) o;
int found = Math.min(orb.xpValue, maxAmount);
orb.xpValue -= found;
if (orb.xpValue <= 0) {
orb.setDead();
found = Math.max(found, 0);
}
if (found > 0) {
found = (int) (found * 66.66666667f);
maxAmount -= found;
_tank.fill(LiquidDictionary.getLiquid("mobEssence", found), true);
if (maxAmount <= 0) {
break;
}
}
}
}
}
}
}
use of net.minecraft.entity.passive.EntityAnimal in project MineFactoryReloaded by powercrystals.
the class TileEntityBreeder method activateMachine.
@Override
protected boolean activateMachine() {
List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
IInventoryManager manager = InventoryManager.create(this, ForgeDirection.UNKNOWN);
if (entities.size() > MFRConfig.breederShutdownThreshold.getInt()) {
setIdleTicks(getIdleTicksMax());
return false;
}
for (Object o : entities) {
if (o instanceof EntityAnimal) {
EntityAnimal a = ((EntityAnimal) o);
List<ItemStack> foodList;
if (MFRRegistry.getBreederFoods().containsKey(a.getClass())) {
foodList = MFRRegistry.getBreederFoods().get(a.getClass());
} else {
foodList = new ArrayList<ItemStack>();
foodList.add(new ItemStack(Item.wheat));
}
for (ItemStack food : foodList) {
int stackIndex = manager.findItem(food);
if (stackIndex < 0) {
continue;
}
if (!a.isInLove() && a.getGrowingAge() == 0) {
a.inLove = 600;
decrStackSize(stackIndex, 1);
for (int var3 = 0; var3 < 7; ++var3) {
double var4 = a.getRNG().nextGaussian() * 0.02D;
double var6 = a.getRNG().nextGaussian() * 0.02D;
double var8 = a.getRNG().nextGaussian() * 0.02D;
this.worldObj.spawnParticle("heart", a.posX + a.getRNG().nextFloat() * a.width * 2.0F - a.width, a.posY + 0.5D + a.getRNG().nextFloat() * a.height, a.posZ + a.getRNG().nextFloat() * a.width * 2.0F - a.width, var4, var6, var8);
}
return true;
}
}
}
}
setIdleTicks(getIdleTicksMax());
return false;
}
Aggregations