use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.
the class TileEntityLiquidHopper method exportItem.
@Override
protected boolean exportItem(int maxItems) {
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
if (tank.getFluid() != null) {
TileEntity neighbor = IOHelper.getNeighbor(this, dir);
if (neighbor instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) neighbor;
if (fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
FluidStack fluid = tank.getFluid().copy();
fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
if (fluid.amount > 0) {
tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
if (tank.getFluidAmount() <= 0)
tank.setFluid(null);
return true;
}
}
}
}
if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
for (EntityItem entity : getNeighborItems(this, dir)) {
if (!entity.isDead) {
List<ItemStack> returnedItems = new ArrayList<ItemStack>();
if (FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
if (entity.getEntityItem().stackSize <= 0)
entity.setDead();
for (ItemStack stack : returnedItems) {
EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
item.motionX = entity.motionX;
item.motionY = entity.motionY;
item.motionZ = entity.motionZ;
worldObj.spawnEntityInWorld(item);
}
return true;
}
}
}
}
if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
if (extractedFluid != null && extractedFluid.amount == 1000) {
Block fluidBlock = extractedFluid.getFluid().getBlock();
if (fluidBlock != null) {
drain(ForgeDirection.UNKNOWN, 1000, true);
worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
}
}
}
}
return false;
}
use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.
the class TileEntityPneumaticBase method updateEntity.
@Override
public void updateEntity() {
// volume calculations
if (!worldObj.isRemote && getUpgradeSlots() != null) {
int upgradeVolume = getVolumeFromUpgrades(getUpgradeSlots());
setVolume(DEFAULT_VOLUME + upgradeVolume);
if (getUpgrades(ItemMachineUpgrade.UPGRADE_SECURITY, getUpgradeSlots()) > 0) {
if (getPressure(ForgeDirection.UNKNOWN) >= DANGER_PRESSURE - 0.1) {
airLeak(ForgeDirection.DOWN);
}
//Remove the remaining air if there is any still.
int excessAir = getCurrentAir(ForgeDirection.UNKNOWN) - (int) (getVolume() * (DANGER_PRESSURE - 0.1));
if (excessAir > 0) {
addAir(-excessAir, ForgeDirection.DOWN);
onAirDispersion(-excessAir, ForgeDirection.DOWN);
}
}
}
super.updateEntity();
// getPressure());
for (ForgeDirection pneumaticSide : ForgeDirection.values()) {
if (!worldObj.isRemote && getPressure(pneumaticSide) > maxPressure) {
worldObj.createExplosion(null, xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, 1.0F, true);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}
if (!worldObj.isRemote)
disperseAir();
if (soundCounter > 0)
soundCounter--;
}
use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.
the class TileEntityUVLightBox method updateConnections.
public void updateConnections() {
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (isConnectedTo(direction)) {
boolean checkingLeft = ForgeDirection.getOrientation(getBlockMetadata()).getRotation(ForgeDirection.UP) == direction;
TileEntity te = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
if (te instanceof IPneumaticMachine) {
/*sidesConnected[direction.ordinal()]*/
boolean isConnected = ((IPneumaticMachine) te).isConnectedTo(direction.getOpposite());
if (checkingLeft)
leftConnected = isConnected;
else
rightConnected = isConnected;
} else {
/*sidesConnected[direction.ordinal()]*/
if (checkingLeft)
leftConnected = false;
else
rightConnected = false;
}
}
}
}
use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.
the class TileEntityCache method getDefaultCache.
public static TileEntityCache[] getDefaultCache(World world, int x, int y, int z) {
TileEntityCache[] cache = new TileEntityCache[6];
for (int i = 0; i < 6; i++) {
ForgeDirection d = ForgeDirection.getOrientation(i);
cache[i] = new TileEntityCache(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ);
}
return cache;
}
use of net.minecraftforge.common.util.ForgeDirection in project Minechem by iopleke.
the class AugmentRedstone method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int level) {
ForgeDirection dir = ForgeDirection.getOrientation(side);
x += dir.offsetX;
y += dir.offsetY;
z += dir.offsetZ;
if (!world.isRemote && player != null && player.canPlayerEdit(x, y, z, side, null)) {
if (world.isAirBlock(x, y, z)) {
world.setBlock(x, y, z, BlockRegistry.blockRedstone, levels[level], 7);
}
}
return false;
}
Aggregations