use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class ModuleAirGrate method update.
@Override
public void update() {
super.update();
World worldObj = pressureTube.world();
int xCoord = pressureTube.x();
int yCoord = pressureTube.y();
int zCoord = pressureTube.z();
Vec3 tileVec = Vec3.createVectorHelper(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D);
if (!worldObj.isRemote) {
int oldGrateRange = grateRange;
grateRange = getRange();
pressureTube.getAirHandler().addAir((vacuum ? 1 : -1) * grateRange * PneumaticValues.USAGE_AIR_GRATE, ForgeDirection.UNKNOWN);
if (oldGrateRange != grateRange)
sendDescriptionPacket();
checkForPlantsAndFarm(worldObj, xCoord, yCoord, zCoord, grateRange);
coolHeatSinks(worldObj, xCoord, yCoord, zCoord, grateRange);
} else {
rangeLineRenderer.update();
/* updateParticleTargets(tileVec, grateRange);
for(Vec3 particleVec : particleTargets) {
//if(worldObj.rand.nextInt(10) == 0) {
Vec3 motionVec = particleVec.subtract(tileVec);
double force = 0.1D;
motionVec.xCoord *= force;
motionVec.yCoord *= force;
motionVec.zCoord *= force;
if(vacuum) {
worldObj.spawnParticle("smoke", particleVec.xCoord, particleVec.yCoord, particleVec.zCoord, -motionVec.xCoord, -motionVec.yCoord, -motionVec.zCoord);
} else {
worldObj.spawnParticle("smoke", tileVec.xCoord, tileVec.yCoord, tileVec.zCoord, motionVec.xCoord, motionVec.yCoord, motionVec.zCoord);
}
// }
}*/
}
AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(xCoord - grateRange, yCoord - grateRange, zCoord - grateRange, xCoord + grateRange + 1, yCoord + grateRange + 1, zCoord + grateRange + 1);
List<Entity> entities = worldObj.selectEntitiesWithinAABB(Entity.class, bbBox, new StringFilterEntitySelector().setFilter(entityFilter));
double d0 = grateRange + 0.5D;
for (Entity entity : entities) {
if (!entity.worldObj.isRemote && entity.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) < 0.6D && entity instanceof EntityItem && !entity.isDead) {
List<IInventory> inventories = new ArrayList<IInventory>();
List<Integer> sides = new ArrayList<Integer>();
for (int i = 0; i < 6; i++) {
IInventory inventory = TileEntityHopper.func_145893_b(worldObj, xCoord + Facing.offsetsXForSide[i], yCoord + Facing.offsetsYForSide[i], zCoord + Facing.offsetsZForSide[i]);
if (inventory != null) {
inventories.add(inventory);
sides.add(i);
}
}
// if there isn't a
if (inventories.size() == 0)
continue;
// inventory attached,
// stop handling.
int inventoryIndexSelected = new Random().nextInt(inventories.size());
IInventory inventory = inventories.get(inventoryIndexSelected);
int side = sides.get(inventoryIndexSelected);
side = Facing.oppositeSide[side];
ItemStack leftoverStack = TileEntityHopper.func_145889_a(inventory, ((EntityItem) entity).getEntityItem(), side);
if (leftoverStack == null || leftoverStack.stackSize == 0) {
entity.setDead();
}
} else {
if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).capabilities.isCreativeMode) {
Vec3 entityVec = Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ);
MovingObjectPosition trace = worldObj.rayTraceBlocks(entityVec, tileVec);
if (trace != null && trace.blockX == xCoord && trace.blockY == yCoord && trace.blockZ == zCoord) {
double d1 = (entity.posX - xCoord - 0.5D) / d0;
double d2 = (entity.posY - yCoord - 0.5D) / d0;
double d3 = (entity.posZ - zCoord - 0.5D) / d0;
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
double d5 = 1.0D - d4;
if (d5 > 0.0D) {
d5 *= d5;
if (!vacuum)
d5 *= -1;
entity.motionX -= d1 / d4 * d5 * 0.1D;
entity.motionY -= d2 / d4 * d5 * 0.1D;
entity.motionZ -= d3 / d4 * d5 * 0.1D;
}
}
}
}
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class BlockPressureTube method rotateBlock.
@Override
public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side) {
TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
if (player.isSneaking()) {
TubeModule module = getLookedModule(world, x, y, z, player);
if (module != null) {
if (!player.capabilities.isCreativeMode) {
List<ItemStack> drops = module.getDrops();
for (ItemStack drop : drops) {
EntityItem entity = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5);
entity.setEntityItemStack(drop);
world.spawnEntityInWorld(entity);
entity.onCollideWithPlayer(player);
}
}
tube.setModule(null, module.getDirection());
onNeighborBlockChange(world, x, y, z, this);
world.notifyBlocksOfNeighborChange(x, y, z, this, module.getDirection().getOpposite().ordinal());
return true;
}
if (!player.capabilities.isCreativeMode) {
EntityItem entity = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(tube.maxPressure <= PneumaticValues.MAX_PRESSURE_PRESSURE_TUBE ? Blockss.pressureTube : Blockss.advancedPressureTube));
world.spawnEntityInWorld(entity);
entity.onCollideWithPlayer(player);
}
ModInteractionUtils.getInstance().removeTube(world.getTileEntity(x, y, z));
return true;
} else {
return super.rotateBlock(world, player, x, y, z, side);
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class BlockEnderPlant method executeFullGrownEffect.
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand) {
if (!world.isRemote) {
for (int i = 0; i < 50; i++) {
int randX = x + rand.nextInt(30) - 15;
int randY = y + rand.nextInt(8);
int randZ = z + rand.nextInt(30) - 15;
Block block = world.getBlock(randX, randY, randZ);
if (!block.getMaterial().blocksMovement()) {
ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.ENDER_PLANT_DAMAGE);
EntityItem plant = new EntityItem(world, randX + 0.5D, randY + 0.5D, randZ + 0.5D, seed);
// plant.motionX = plant.motionY = plant.motionZ = 0;
plant.lifespan = 300;
ItemPlasticPlants.markInactive(plant);
world.spawnEntityInWorld(plant);
plant.playSound("mob.endermen.portal", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
short short1 = 128;
for (int j = 0; j < short1; ++j) {
double d6 = j / (short1 - 1.0D);
float f = (rand.nextFloat() - 0.5F) * 0.2F;
float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
double d7 = x + 0.5D + (plant.posX - (x + 0.5D)) * d6 + (rand.nextDouble() - 0.5D);
double d8 = y + 0.5D + (plant.posY - (y + 0.5D)) * d6 + rand.nextDouble();
double d9 = z + 0.5D + (plant.posZ - (z + 0.5D)) * d6 + (rand.nextDouble() - 0.5D);
NetworkHandler.sendToAllAround(new PacketSpawnParticle("portal", d7, d8, d9, f, f1, f2), world);
}
world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
break;
}
}
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class BlockFireFlower method executeFullGrownEffect.
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand) {
if (world.getBlockMetadata(x, y, z) == 14) {
world.setBlockMetadataWithNotify(x, y, z, 11, 3);
if (!world.isRemote) {
ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.FIRE_FLOWER_DAMAGE);
EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
plant.motionX = (rand.nextFloat() - 0.5F) / 2;
plant.motionY = 0.5F;
plant.motionZ = (rand.nextFloat() - 0.5F) / 2;
plant.lifespan = 300;
ItemPlasticPlants.markInactive(plant);
world.spawnEntityInWorld(plant);
plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}
} else {
world.setBlockMetadataWithNotify(x, y, z, 14, 2);
world.scheduleBlockUpdate(x, y, z, this, 60);
}
}
use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.
the class BlockFlyingFlower method executeFullGrownEffect.
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand) {
if (!world.isRemote) {
ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.FLYING_FLOWER_DAMAGE);
EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
plant.motionX = (rand.nextFloat() - 0.5F) / 4F;
plant.motionY = rand.nextFloat() * 0.2F;
plant.motionZ = (rand.nextFloat() - 0.5F) / 4F;
plant.lifespan = 1200;
ItemPlasticPlants.markInactive(plant);
world.spawnEntityInWorld(plant);
plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
world.setBlockMetadataWithNotify(x, y, z, 4, 3);
}
}
Aggregations