use of buildcraft.api.core.IAreaProvider in project BuildCraft by BuildCraft.
the class TileQuarry method setBoundaries.
private void setBoundaries(boolean useDefaultI) {
boolean useDefault = useDefaultI;
if (BuildCraftBuilders.quarryLoadsChunks && chunkTicket == null) {
chunkTicket = ForgeChunkManager.requestTicket(BuildCraftBuilders.instance, worldObj, Type.NORMAL);
}
if (chunkTicket != null) {
chunkTicket.getModData().setInteger("quarryX", pos.getX());
chunkTicket.getModData().setInteger("quarryY", pos.getY());
chunkTicket.getModData().setInteger("quarryZ", pos.getZ());
ForgeChunkManager.forceChunk(chunkTicket, new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4));
}
IAreaProvider a = null;
if (!useDefault) {
a = Utils.getNearbyAreaProvider(worldObj, pos);
}
if (a == null) {
a = new DefaultAreaProvider(pos, pos.add(new BlockPos(10, 4, 10)));
useDefault = true;
}
int xSize = a.max().getX() - a.min().getX() + 1;
int zSize = a.max().getZ() - a.min().getZ() + 1;
if (xSize < 3 || zSize < 3 || (chunkTicket != null && ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth())) {
if (placedBy != null) {
placedBy.addChatMessage(new TextComponentTranslation("chat.buildcraft.quarry.tooSmall", xSize, zSize, chunkTicket != null ? chunkTicket.getMaxChunkListDepth() : 0));
}
a = new DefaultAreaProvider(pos, pos.add(new BlockPos(10, 4, 10)));
useDefault = true;
}
xSize = a.max().getX() - a.min().getX() + 1;
int ySize = a.max().getY() - a.min().getY() + 1;
zSize = a.max().getZ() - a.min().getZ() + 1;
box.initialize(a);
if (ySize < 5) {
ySize = 5;
box.setMax(VecUtil.replaceValue(box.max(), Axis.Y, box.min().getY() + ySize - 1));
}
if (useDefault) {
int xMin, zMin;
EnumFacing face = worldObj.getBlockState(pos).getValue(BuildCraftProperties.BLOCK_FACING).getOpposite();
switch(face) {
case EAST:
xMin = pos.getX() + 1;
zMin = pos.getZ() - 4 - 1;
break;
case WEST:
xMin = pos.getX() - 9 - 2;
zMin = pos.getZ() - 4 - 1;
break;
case SOUTH:
xMin = pos.getX() - 4 - 1;
zMin = pos.getZ() + 1;
break;
case NORTH:
default:
xMin = pos.getX() - 4 - 1;
zMin = pos.getZ() - 9 - 2;
break;
}
box.reset();
box.setMin(new BlockPos(xMin, pos.getY(), zMin));
box.setMax(new BlockPos(xMin + xSize - 1, pos.getY() + ySize - 1, zMin + zSize - 1));
}
a.removeFromWorld();
if (chunkTicket != null) {
forceChunkLoading(chunkTicket);
}
sendNetworkUpdate();
}
use of buildcraft.api.core.IAreaProvider in project BuildCraft by BuildCraft.
the class TileArchitectTable method onPlacedBy.
@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
super.onPlacedBy(placer, stack);
if (placer.world.isRemote) {
return;
}
WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
IBlockState blockState = world.getBlockState(pos);
BlockPos offsetPos = pos.offset(blockState.getValue(BlockArchitectTable.PROP_FACING).getOpposite());
VolumeBox volumeBox = volumeBoxes.getVolumeBoxAt(offsetPos);
TileEntity tile = world.getTileEntity(offsetPos);
if (volumeBox != null) {
box.reset();
box.setMin(volumeBox.box.min());
box.setMax(volumeBox.box.max());
isValid = true;
volumeBox.locks.add(new Lock(new Lock.Cause.CauseBlock(pos, blockState.getBlock()), new Lock.Target.TargetRemove(), new Lock.Target.TargetResize(), new Lock.Target.TargetUsedByMachine(Lock.Target.TargetUsedByMachine.EnumType.STRIPES_READ)));
volumeBoxes.markDirty();
sendNetworkUpdate(NET_BOX);
} else if (tile instanceof IAreaProvider) {
IAreaProvider provider = (IAreaProvider) tile;
box.reset();
box.setMin(provider.min());
box.setMax(provider.max());
markerBox = true;
isValid = true;
provider.removeFromWorld();
} else {
isValid = false;
IBlockState state = world.getBlockState(pos);
state = state.withProperty(BlockArchitectTable.PROP_VALID, Boolean.FALSE);
world.setBlockState(pos, state);
}
}
use of buildcraft.api.core.IAreaProvider in project BuildCraft by BuildCraft.
the class TileArchitect method initialize.
@Override
public void initialize() {
super.initialize();
if (!worldObj.isRemote && !initialized) {
if (!box.isInitialized()) {
IAreaProvider a = Utils.getNearbyAreaProvider(worldObj, pos);
if (a != null) {
mode = Mode.COPY;
box.initialize(a);
a.removeFromWorld();
sendNetworkUpdate();
return;
} else {
if (BuildCraftCore.DEVELOPER_MODE) {
mode = Mode.EDIT;
} else {
mode = Mode.NONE;
}
}
} else {
mode = Mode.COPY;
}
initialized = true;
sendNetworkUpdate();
}
}
use of buildcraft.api.core.IAreaProvider in project BuildCraft by BuildCraft.
the class TileFiller method initialize.
@Override
public void initialize() {
super.initialize();
if (worldObj.isRemote) {
return;
}
IAreaProvider a = Utils.getNearbyAreaProvider(worldObj, pos);
if (a != null) {
box.initialize(a);
a.removeFromWorld();
sendNetworkUpdate();
}
if (currentTemplate == null) {
initTemplate();
}
if (initNBT != null && currentTemplate != null) {
currentTemplate.loadBuildStateToNBT(initNBT.getCompoundTag("builderState"), this);
}
initNBT = null;
}
use of buildcraft.api.core.IAreaProvider in project BuildCraft by BuildCraft.
the class TileQuarry method onPlacedBy.
@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
super.onPlacedBy(placer, stack);
if (placer.world.isRemote) {
return;
}
EnumFacing facing = world.getBlockState(pos).getValue(BlockBCBase_Neptune.PROP_FACING);
BlockPos areaPos = pos.offset(facing.getOpposite());
TileEntity tile = world.getTileEntity(areaPos);
BlockPos min = null, max = null;
if (tile instanceof IAreaProvider) {
IAreaProvider provider = (IAreaProvider) tile;
min = provider.min();
max = provider.max();
int dx = max.getX() - min.getX();
int dz = max.getZ() - min.getZ();
if (dx < 3 || dz < 3) {
min = null;
max = null;
} else {
provider.removeFromWorld();
}
}
// noinspection ConstantConditions
if (min == null || max == null) {
min = null;
max = null;
VolumeSubCache cache = VolumeCache.INSTANCE.getSubCache(getWorld());
for (BlockPos markerPos : cache.getAllMarkers()) {
TileMarkerVolume marker = (TileMarkerVolume) cache.getMarker(markerPos);
if (marker == null) {
continue;
}
VolumeConnection connection = marker.getCurrentConnection();
if (connection == null) {
continue;
}
Box volBox = connection.getBox();
Box box2 = new Box();
box2.initialize(volBox);
if (!box2.isInitialized()) {
continue;
}
if (pos.getY() != box2.min().getY()) {
continue;
}
if (box2.contains(pos)) {
continue;
}
if (!box2.contains(areaPos)) {
continue;
}
if (box2.size().getX() < 3 || box2.size().getZ() < 3) {
continue;
}
box2.expand(1);
box2.setMin(box2.min().up());
if (box2.isOnEdge(pos)) {
min = volBox.min();
max = volBox.max();
marker.removeFromWorld();
break;
}
}
}
if (min == null || max == null) {
miningBox.reset();
frameBox.reset();
switch(facing.getOpposite()) {
case DOWN:
case UP:
default:
case // +X
EAST:
min = pos.add(1, 0, -5);
max = pos.add(11, 4, 5);
break;
case // -X
WEST:
min = pos.add(-11, 0, -5);
max = pos.add(-1, 4, 5);
break;
case // +Z
SOUTH:
min = pos.add(-5, 0, 1);
max = pos.add(5, 4, 11);
break;
case // -Z
NORTH:
min = pos.add(-5, 0, -11);
max = pos.add(5, 4, -1);
break;
}
}
if (max.getY() - min.getY() < 4) {
max = new BlockPos(max.getX(), min.getY() + 4, max.getZ());
}
frameBox.reset();
frameBox.setMin(min);
frameBox.setMax(max);
miningBox.reset();
miningBox.setMin(new BlockPos(min.getX() + 1, 0, min.getZ() + 1));
miningBox.setMax(new BlockPos(max.getX() - 1, max.getY() - 1, max.getZ() - 1));
updatePoses();
}
Aggregations