use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.
the class BlockCable method notifyNetworkAboutRefresh.
private void notifyNetworkAboutRefresh(World world, BlockPos initialPos) {
PooledMutableBlockPos currentPos = PooledMutableBlockPos.retain(initialPos.getX(), initialPos.getY(), initialPos.getZ());
List<BlockPos> visited = new ArrayList<>();
Stack<EnumFacing> moveStack = new Stack<>();
while (true) {
for (EnumFacing facing : EnumFacing.VALUES) {
currentPos.move(facing);
EnumFacing opposite = facing.getOpposite();
if (!visited.contains(currentPos)) {
visited.add(currentPos.toImmutable());
} else {
currentPos.move(opposite);
continue;
}
if (world.getBlockState(currentPos).getBlock() instanceof BlockCable) {
world.setBlockState(currentPos.up(), Blocks.LOG.getDefaultState());
// if we are cable, move forward, and update emitter, if we has one
TileEntityCableEmitter emitter = (TileEntityCableEmitter) world.getTileEntity(currentPos);
if (emitter != null)
emitter.refreshConnections();
moveStack.push(opposite);
continue;
}
// move back if we aren't cable and din't continue
currentPos.move(opposite);
}
// if we didn't found any cable, go back, or return
if (!moveStack.isEmpty()) {
currentPos.move(moveStack.pop());
} else
break;
}
// DebugRenderer.blockPosSet = ImmutableSet.copyOf(visited);
currentPos.release();
}
use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.
the class MetaTileEntity method pushItemsIntoNearbyHandlers.
public void pushItemsIntoNearbyHandlers(EnumFacing... allowedFaces) {
PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
for (EnumFacing nearbyFacing : allowedFaces) {
blockPos.setPos(getPos()).move(nearbyFacing);
TileEntity tileEntity = getWorld().getTileEntity(blockPos);
if (tileEntity == null) {
continue;
}
IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
// use getCoverCapability so item/ore dictionary filter covers will work properly
IItemHandler myItemHandler = getCoverCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing);
if (itemHandler == null || myItemHandler == null) {
continue;
}
moveInventoryItems(myItemHandler, itemHandler);
}
blockPos.release();
}
use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.
the class MetaTileEntity method pullItemsFromNearbyHandlers.
public void pullItemsFromNearbyHandlers(EnumFacing... allowedFaces) {
PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
for (EnumFacing nearbyFacing : allowedFaces) {
blockPos.setPos(getPos()).move(nearbyFacing);
TileEntity tileEntity = getWorld().getTileEntity(blockPos);
if (tileEntity == null) {
continue;
}
IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
// use getCoverCapability so item/ore dictionary filter covers will work properly
IItemHandler myItemHandler = getCoverCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing);
if (itemHandler == null || myItemHandler == null) {
continue;
}
moveInventoryItems(itemHandler, myItemHandler);
}
blockPos.release();
}
use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.
the class CoverPump method doTransferFluids.
protected int doTransferFluids(int transferLimit) {
PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
blockPos.setPos(coverHolder.getPos()).move(attachedSide);
TileEntity tileEntity = coverHolder.getWorld().getTileEntity(blockPos);
blockPos.release();
IFluidHandler fluidHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, attachedSide.getOpposite());
IFluidHandler myFluidHandler = coverHolder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, attachedSide);
if (fluidHandler == null || myFluidHandler == null) {
return 0;
}
return doTransferFluidsInternal(myFluidHandler, fluidHandler, transferLimit);
}
use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.
the class BlockCable method refreshSelfState.
private void refreshSelfState(World world, BlockPos selfPos) {
boolean shouldPlaceEmitter = false;
PooledMutableBlockPos mutableBlockPos = PooledMutableBlockPos.retain(selfPos);
for (EnumFacing facing : EnumFacing.VALUES) {
mutableBlockPos.move(facing);
EnumFacing opposite = facing.getOpposite();
IBlockState blockState = world.getBlockState(mutableBlockPos);
if (blockState.getBlock().hasTileEntity(blockState)) {
TileEntity tileEntity = world.getTileEntity(mutableBlockPos);
IEnergyContainer container = tileEntity == null ? null : tileEntity.getCapability(IEnergyContainer.CAPABILITY_ENERGY_CONTAINER, opposite);
if (container != null && container.outputsEnergy(opposite)) {
shouldPlaceEmitter = true;
break;
}
}
mutableBlockPos.move(opposite);
}
mutableBlockPos.release();
// remove emitter if we don't have inputs, or add if we have inputs and it doesn't exist
TileEntity currentTileEntity = world.getTileEntity(selfPos);
if (shouldPlaceEmitter) {
if (!(currentTileEntity instanceof TileEntityCableEmitter)) {
TileEntityCableEmitter tileEntityCableEmitter = new TileEntityCableEmitter();
world.setTileEntity(selfPos, tileEntityCableEmitter);
tileEntityCableEmitter.refreshConnections();
}
} else if (currentTileEntity instanceof TileEntityCableEmitter) {
world.removeTileEntity(selfPos);
}
}
Aggregations