use of pneumaticCraft.common.ai.StringFilterEntitySelector 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 pneumaticCraft.common.ai.StringFilterEntitySelector in project PneumaticCraft by MineMaarten.
the class ProgWidgetAreaItemBase method getEntityFilter.
public static StringFilterEntitySelector getEntityFilter(ProgWidgetString widget, boolean allowEntityIfNoFilter) {
StringFilterEntitySelector filter = new StringFilterEntitySelector();
if (widget != null) {
while (widget != null) {
filter.addEntry(widget.string);
widget = (ProgWidgetString) widget.getConnectedParameters()[0];
}
} else if (allowEntityIfNoFilter) {
filter.setFilter("");
}
return filter;
}
use of pneumaticCraft.common.ai.StringFilterEntitySelector in project PneumaticCraft by MineMaarten.
the class ProgWidgetDroneConditionEntity method isEntityValid.
@Override
public boolean isEntityValid(Entity entity) {
StringFilterEntitySelector whitelistFilter = ProgWidgetAreaItemBase.getEntityFilter((ProgWidgetString) getConnectedParameters()[0], true);
StringFilterEntitySelector blacklistFilter = ProgWidgetAreaItemBase.getEntityFilter((ProgWidgetString) getConnectedParameters()[getParameters().length], false);
return whitelistFilter.isEntityApplicable(entity) && !blacklistFilter.isEntityApplicable(entity);
}
use of pneumaticCraft.common.ai.StringFilterEntitySelector in project PneumaticCraft by MineMaarten.
the class ProgWidgetEntityAttack method isEntityValid.
@Override
public boolean isEntityValid(Entity entity) {
StringFilterEntitySelector whitelistFilter = ProgWidgetAreaItemBase.getEntityFilter((ProgWidgetString) getConnectedParameters()[1], true);
StringFilterEntitySelector blacklistFilter = ProgWidgetAreaItemBase.getEntityFilter((ProgWidgetString) getConnectedParameters()[3], false);
return whitelistFilter.isEntityApplicable(entity) && !blacklistFilter.isEntityApplicable(entity);
}
use of pneumaticCraft.common.ai.StringFilterEntitySelector in project PneumaticCraft by MineMaarten.
the class ProgWidgetEntityAttack method getValidEntities.
@Override
public List<Entity> getValidEntities(World world) {
StringFilterEntitySelector whitelistFilter = ProgWidgetAreaItemBase.getEntityFilter((ProgWidgetString) getConnectedParameters()[1], true);
StringFilterEntitySelector blacklistFilter = ProgWidgetAreaItemBase.getEntityFilter((ProgWidgetString) getConnectedParameters()[3], false);
return ProgWidgetAreaItemBase.getEntitiesInArea((ProgWidgetArea) getConnectedParameters()[0], (ProgWidgetArea) getConnectedParameters()[2], world, whitelistFilter, blacklistFilter);
}
Aggregations