Search in sources :

Example 1 with VolumeSubCache

use of buildcraft.core.marker.VolumeSubCache 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();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAreaProvider(buildcraft.api.core.IAreaProvider) TileMarkerVolume(buildcraft.core.tile.TileMarkerVolume) VolumeConnection(buildcraft.core.marker.VolumeConnection) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Box(buildcraft.lib.misc.data.Box) VolumeSubCache(buildcraft.core.marker.VolumeSubCache)

Aggregations

IAreaProvider (buildcraft.api.core.IAreaProvider)1 VolumeConnection (buildcraft.core.marker.VolumeConnection)1 VolumeSubCache (buildcraft.core.marker.VolumeSubCache)1 TileMarkerVolume (buildcraft.core.tile.TileMarkerVolume)1 Box (buildcraft.lib.misc.data.Box)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1