use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntitySheetmetalTank method update.
@Override
public void update() {
if (pos == 4 && !worldObj.isRemote && worldObj.isBlockIndirectlyGettingPowered(getPos()) > 0)
for (int i = 0; i < 6; i++) if (i != 1 && tank.getFluidAmount() > 0) {
EnumFacing f = EnumFacing.getFront(i);
int outSize = Math.min(144, tank.getFluidAmount());
FluidStack out = new FluidStack(tank.getFluid().getFluid(), outSize);
BlockPos outputPos = getPos().offset(f);
IFluidHandler output = FluidUtil.getFluidHandler(worldObj, outputPos, f.getOpposite());
if (output != null) {
int accepted = output.fill(out, false);
if (accepted > 0) {
int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);
this.tank.drain(drained, true);
this.markContainingBlockForUpdate(null);
updateComparatorValuesPart2();
}
}
}
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntityRazorWire method isStacked.
private boolean isStacked() {
BlockPos down = getPos().down();
TileEntity te = worldObj.getTileEntity(down);
if (te instanceof TileEntityRazorWire)
return ((TileEntityRazorWire) te).isOnGround();
return false;
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntityRazorWire method outputEnergy.
@Override
public int outputEnergy(int amount, boolean simulate, int energyType) {
if (amount > 0) {
if (!simulate) {
int maxReach = amount / 8;
int widthP = 0;
boolean connectP = true;
int widthN = 0;
boolean connectN = true;
EnumFacing dir = facing.rotateY();
if (dir.getAxisDirection() == AxisDirection.NEGATIVE)
dir = dir.getOpposite();
for (int i = 1; i <= maxReach; i++) {
BlockPos posP = getPos().offset(dir, i);
if (connectP && worldObj.isBlockLoaded(posP) && worldObj.getTileEntity(posP) instanceof TileEntityRazorWire)
widthP++;
else
connectP = false;
BlockPos posN = getPos().offset(dir, -i);
if (connectN && worldObj.isBlockLoaded(posN) && worldObj.getTileEntity(posN) instanceof TileEntityRazorWire)
widthN++;
else
connectN = false;
}
AxisAlignedBB aabb = new AxisAlignedBB(getPos().add(facing.getAxis() == Axis.Z ? -widthN : 0, 0, facing.getAxis() == Axis.X ? -widthN : 0), getPos().add(facing.getAxis() == Axis.Z ? 1 + widthP : 1, 1, facing.getAxis() == Axis.X ? 1 + widthP : 1));
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, aabb);
for (EntityLivingBase ent : entities) ent.attackEntityFrom(IEDamageSources.razorShock, 2);
}
return 64;
}
return 0;
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntityRazorWire method renderWall.
private boolean renderWall(boolean left) {
EnumFacing dir = left ? facing.rotateY() : facing.rotateYCCW();
BlockPos neighbourPos = getPos().offset(dir, -1);
if (!worldObj.isBlockLoaded(neighbourPos))
return true;
if (worldObj.getTileEntity(neighbourPos) instanceof TileEntityRazorWire)
return false;
IBlockState neighbour = worldObj.getBlockState(neighbourPos);
return !neighbour.isSideSolid(worldObj, neighbourPos, dir);
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class ItemWireCoil method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
WireType wire = getWireType(stack);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
tileEntity = world.getTileEntity(masterPos);
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
return EnumActionResult.PASS;
if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
return EnumActionResult.FAIL;
}
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ() });
NBTTagCompound targetNbt = new NBTTagCompound();
target.writeToNBT(targetNbt);
ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
} else {
WireType type = getWireType(stack);
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
if (array[0] != world.provider.getDimension())
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
else if (linkPos.equals(masterPos))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
else {
TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
else {
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
boolean connectionExists = false;
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
if (outputs != null)
for (Connection con : outputs) {
if (con.end.equals(Utils.toCC(nodeLink)))
connectionExists = true;
}
if (connectionExists)
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
else {
Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
Set<BlockPos> ignore = new HashSet<>();
ignore.addAll(nodeHere.getIgnored(nodeLink));
ignore.addAll(nodeLink.getIgnored(nodeHere));
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
if (canSee) {
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
nodeHere.connectCable(type, target, nodeLink);
nodeLink.connectCable(type, targetLink, nodeHere);
IESaveData.setDirty(world.provider.getDimension());
player.addStat(IEAchievements.connectWire);
if (!player.capabilities.isCreativeMode)
stack.stackSize--;
((TileEntity) nodeHere).markDirty();
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
IBlockState state = world.getBlockState(masterPos);
world.notifyBlockUpdate(masterPos, state, state, 3);
((TileEntity) nodeLink).markDirty();
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
state = world.getBlockState(linkPos);
world.notifyBlockUpdate(linkPos, state, state, 3);
} else
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
}
}
}
ItemNBTHelper.remove(stack, "linkingPos");
ItemNBTHelper.remove(stack, "targettingInfo");
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
Aggregations