Search in sources :

Example 1 with VolumeBox

use of buildcraft.core.marker.volume.VolumeBox in project BuildCraft by BuildCraft.

the class TileFiller method readPayload.

@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
    super.readPayload(id, buffer, side, ctx);
    if (side == Side.CLIENT) {
        if (id == NET_RENDER_DATA) {
            builder.readFromByteBuf(buffer);
            readPayload(NET_BOX, buffer, side, ctx);
        } else if (id == NET_GUI_DATA || id == NET_GUI_TICK) {
            readPayload(NET_CAN_EXCAVATE, buffer, side, ctx);
            readPayload(NET_INVERT, buffer, side, ctx);
            readPayload(NET_PATTERN, buffer, side, ctx);
            builder.readFromByteBuf(buffer);
            finished = buffer.readBoolean();
            lockedTicks = buffer.readBoolean() ? (byte) 1 : (byte) 0;
            mode = buffer.readEnumValue(Mode.class);
        } else if (id == NET_BOX) {
            box.readData(buffer);
            markerBox = buffer.readBoolean();
            if (buffer.readBoolean()) {
                UUID volumeBoxId = buffer.readUniqueId();
                VolumeBox volumeBox = world.isRemote ? ClientVolumeBoxes.INSTANCE.volumeBoxes.stream().filter(localVolumeBox -> localVolumeBox.id.equals(volumeBoxId)).findFirst().orElseThrow(NullPointerException::new) : WorldSavedDataVolumeBoxes.get(world).getVolumeBoxFromId(volumeBoxId);
                addon = (AddonFillerPlanner) volumeBox.addons.get(buffer.readEnumValue(EnumAddonSlot.class));
            }
        } else if (id == NET_CAN_EXCAVATE) {
            canExcavate = buffer.readBoolean();
        } else if (id == NET_INVERT) {
            inverted = buffer.readBoolean();
        } else if (id == NET_PATTERN) {
            patternStatement.readFromBuffer(buffer);
        }
    }
    if (side == Side.SERVER) {
        if (id == NET_CAN_EXCAVATE) {
            canExcavate = buffer.readBoolean();
            sendNetworkGuiUpdate(NET_CAN_EXCAVATE);
        }
    }
}
Also used : EnumAccess(buildcraft.lib.tile.item.ItemHandlerManager.EnumAccess) IFillerPattern(buildcraft.api.filler.IFillerPattern) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) FillerType(buildcraft.builders.filler.FillerType) Side(net.minecraftforge.fml.relauncher.Side) TilesAPI(buildcraft.api.tiles.TilesAPI) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Template(buildcraft.builders.snapshot.Template) IBox(buildcraft.api.core.IBox) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) AddonFillerPlanner(buildcraft.builders.addon.AddonFillerPlanner) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) VolumeBox(buildcraft.core.marker.volume.VolumeBox) TileBC_Neptune(buildcraft.lib.tile.TileBC_Neptune) UUID(java.util.UUID) List(java.util.List) BlockBCBase_Neptune(buildcraft.lib.block.BlockBCBase_Neptune) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) MjBattery(buildcraft.api.mj.MjBattery) Optional(java.util.Optional) ItemBlocks(buildcraft.builders.snapshot.ItemBlocks) IFillerStatementContainer(buildcraft.api.statements.containers.IFillerStatementContainer) MjAPI(buildcraft.api.mj.MjAPI) EnumPipePart(buildcraft.api.core.EnumPipePart) IntStream(java.util.stream.IntStream) Box(buildcraft.lib.misc.data.Box) TemplateBuilder(buildcraft.builders.snapshot.TemplateBuilder) IAreaProvider(buildcraft.api.core.IAreaProvider) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ITileForTemplateBuilder(buildcraft.builders.snapshot.ITileForTemplateBuilder) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) ItemStack(net.minecraft.item.ItemStack) NBTUtilBC(buildcraft.lib.misc.NBTUtilBC) MjBatteryReceiver(buildcraft.lib.mj.MjBatteryReceiver) BoundingBoxUtil(buildcraft.lib.misc.BoundingBoxUtil) IStatementParameter(buildcraft.api.statements.IStatementParameter) ITickable(net.minecraft.util.ITickable) BuildingInfo(buildcraft.builders.snapshot.Template.BuildingInfo) MessageManager(buildcraft.lib.net.MessageManager) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) FullStatement(buildcraft.lib.statement.FullStatement) FillerUtil(buildcraft.builders.filler.FillerUtil) IdAllocator(buildcraft.lib.misc.data.IdAllocator) World(net.minecraft.world.World) IDebuggable(buildcraft.api.tiles.IDebuggable) EnumFacing(net.minecraft.util.EnumFacing) MjCapabilityHelper(buildcraft.api.mj.MjCapabilityHelper) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) ClientVolumeBoxes(buildcraft.core.marker.volume.ClientVolumeBoxes) IBlockState(net.minecraft.block.state.IBlockState) IControllable(buildcraft.api.tiles.IControllable) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Lock(buildcraft.core.marker.volume.Lock) TileEntity(net.minecraft.tileentity.TileEntity) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) IItemTransactor(buildcraft.api.inventory.IItemTransactor) VolumeBox(buildcraft.core.marker.volume.VolumeBox) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) UUID(java.util.UUID)

Example 2 with VolumeBox

use of buildcraft.core.marker.volume.VolumeBox in project BuildCraft by BuildCraft.

the class ItemMarkerConnector method onItemRightClickVolumeBoxes.

private EnumActionResult onItemRightClickVolumeBoxes(World world, EntityPlayer player) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
    VolumeBox currentEditing = volumeBoxes.getCurrentEditing(player);
    Vec3d start = player.getPositionVector().addVector(0, player.getEyeHeight(), 0);
    Vec3d end = start.add(player.getLookVec().scale(4));
    Pair<VolumeBox, EnumAddonSlot> selectingVolumeBoxAndSlot = EnumAddonSlot.getSelectingVolumeBoxAndSlot(player, volumeBoxes.volumeBoxes);
    VolumeBox addonVolumeBox = selectingVolumeBoxAndSlot.getLeft();
    EnumAddonSlot addonSlot = selectingVolumeBoxAndSlot.getRight();
    if (addonVolumeBox != null && addonSlot != null) {
        if (addonVolumeBox.addons.containsKey(addonSlot) && addonVolumeBox.getLockTargetsStream().noneMatch(target -> target instanceof Lock.Target.TargetAddon && ((Lock.Target.TargetAddon) target).slot == addonSlot)) {
            if (player.isSneaking()) {
                addonVolumeBox.addons.get(addonSlot).onRemoved();
                addonVolumeBox.addons.remove(addonSlot);
                volumeBoxes.markDirty();
            } else {
                addonVolumeBox.addons.get(addonSlot).onPlayerRightClick(player);
                volumeBoxes.markDirty();
            }
        }
    } else if (player.isSneaking()) {
        if (currentEditing == null) {
            for (Iterator<VolumeBox> iterator = volumeBoxes.volumeBoxes.iterator(); iterator.hasNext(); ) {
                VolumeBox volumeBox = iterator.next();
                if (volumeBox.box.getBoundingBox().calculateIntercept(start, end) != null) {
                    if (volumeBox.getLockTargetsStream().noneMatch(Lock.Target.TargetResize.class::isInstance)) {
                        volumeBox.addons.values().forEach(Addon::onRemoved);
                        iterator.remove();
                        volumeBoxes.markDirty();
                        return EnumActionResult.SUCCESS;
                    } else {
                        return EnumActionResult.FAIL;
                    }
                }
            }
        } else {
            currentEditing.cancelEditing();
            volumeBoxes.markDirty();
            return EnumActionResult.SUCCESS;
        }
    } else {
        if (currentEditing == null) {
            VolumeBox bestVolumeBox = null;
            double bestDist = Double.MAX_VALUE;
            BlockPos editing = null;
            for (VolumeBox volumeBox : volumeBoxes.volumeBoxes.stream().filter(box -> box.getLockTargetsStream().noneMatch(Lock.Target.TargetResize.class::isInstance)).collect(Collectors.toList())) {
                for (BlockPos p : PositionUtil.getCorners(volumeBox.box.min(), volumeBox.box.max())) {
                    RayTraceResult ray = new AxisAlignedBB(p).calculateIntercept(start, end);
                    if (ray != null) {
                        double dist = ray.hitVec.distanceTo(start);
                        if (bestDist > dist) {
                            bestDist = dist;
                            bestVolumeBox = volumeBox;
                            editing = p;
                        }
                    }
                }
            }
            if (bestVolumeBox != null) {
                bestVolumeBox.setPlayer(player);
                BlockPos min = bestVolumeBox.box.min();
                BlockPos max = bestVolumeBox.box.max();
                BlockPos held = min;
                if (editing.getX() == min.getX()) {
                    held = VecUtil.replaceValue(held, EnumFacing.Axis.X, max.getX());
                }
                if (editing.getY() == min.getY()) {
                    held = VecUtil.replaceValue(held, EnumFacing.Axis.Y, max.getY());
                }
                if (editing.getZ() == min.getZ()) {
                    held = VecUtil.replaceValue(held, EnumFacing.Axis.Z, max.getZ());
                }
                bestVolumeBox.setHeldDistOldMinOldMax(held, Math.max(1.5, bestDist + 0.5), bestVolumeBox.box.min(), bestVolumeBox.box.max());
                volumeBoxes.markDirty();
                return EnumActionResult.SUCCESS;
            }
        } else {
            currentEditing.confirmEditing();
            volumeBoxes.markDirty();
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.FAIL;
}
Also used : Addon(buildcraft.core.marker.volume.Addon) PositionUtil(buildcraft.lib.misc.PositionUtil) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) ItemBC_Neptune(buildcraft.lib.item.ItemBC_Neptune) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.commons.lang3.tuple.Pair) Vec3d(net.minecraft.util.math.Vec3d) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) LineSkewResult(buildcraft.lib.misc.PositionUtil.LineSkewResult) VecUtil(buildcraft.lib.misc.VecUtil) MarkerSubCache(buildcraft.lib.marker.MarkerSubCache) Iterator(java.util.Iterator) VolumeBox(buildcraft.core.marker.volume.VolumeBox) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) ActionResult(net.minecraft.util.ActionResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) Lock(buildcraft.core.marker.volume.Lock) MarkerCache(buildcraft.lib.marker.MarkerCache) Line(buildcraft.lib.misc.PositionUtil.Line) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) VolumeBox(buildcraft.core.marker.volume.VolumeBox) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) RayTraceResult(net.minecraft.util.math.RayTraceResult) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) Vec3d(net.minecraft.util.math.Vec3d) Lock(buildcraft.core.marker.volume.Lock) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with VolumeBox

use of buildcraft.core.marker.volume.VolumeBox 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);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAreaProvider(buildcraft.api.core.IAreaProvider) IBlockState(net.minecraft.block.state.IBlockState) VolumeBox(buildcraft.core.marker.volume.VolumeBox) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) BlockPos(net.minecraft.util.math.BlockPos) Lock(buildcraft.core.marker.volume.Lock)

Example 4 with VolumeBox

use of buildcraft.core.marker.volume.VolumeBox in project BuildCraft by BuildCraft.

the class ItemVolumeBox method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    BlockPos offset = pos.offset(facing);
    WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
    VolumeBox current = volumeBoxes.getVolumeBoxAt(offset);
    if (current == null) {
        volumeBoxes.addVolumeBox(offset);
        volumeBoxes.markDirty();
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : VolumeBox(buildcraft.core.marker.volume.VolumeBox) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with VolumeBox

use of buildcraft.core.marker.volume.VolumeBox in project BuildCraft by BuildCraft.

the class TileFiller method onPlacedBy.

@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
    super.onPlacedBy(placer, stack);
    if (world.isRemote) {
        return;
    }
    IBlockState blockState = world.getBlockState(pos);
    WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
    BlockPos offsetPos = pos.offset(blockState.getValue(BlockBCBase_Neptune.PROP_FACING).getOpposite());
    VolumeBox volumeBox = volumeBoxes.getVolumeBoxAt(offsetPos);
    TileEntity tile = world.getTileEntity(offsetPos);
    if (volumeBox != null) {
        addon = (AddonFillerPlanner) volumeBox.addons.values().stream().filter(AddonFillerPlanner.class::isInstance).findFirst().orElse(null);
        if (addon != null) {
            volumeBox.locks.add(new Lock(new Lock.Cause.CauseBlock(pos, blockState.getBlock()), new Lock.Target.TargetAddon(addon.getSlot()), new Lock.Target.TargetRemove(), new Lock.Target.TargetResize(), new Lock.Target.TargetUsedByMachine(Lock.Target.TargetUsedByMachine.EnumType.STRIPES_WRITE)));
            volumeBoxes.markDirty();
            addon.updateBuildingInfo();
            markerBox = false;
        } else {
            box.reset();
            box.setMin(volumeBox.box.min());
            box.setMax(volumeBox.box.max());
            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_WRITE)));
            volumeBoxes.markDirty();
            markerBox = false;
        }
    } else if (tile instanceof IAreaProvider) {
        IAreaProvider provider = (IAreaProvider) tile;
        box.reset();
        box.setMin(provider.min());
        box.setMax(provider.max());
        provider.removeFromWorld();
    }
    updateBuildingInfo();
    sendNetworkUpdate(NET_RENDER_DATA);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) VolumeBox(buildcraft.core.marker.volume.VolumeBox) AddonFillerPlanner(buildcraft.builders.addon.AddonFillerPlanner) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) Lock(buildcraft.core.marker.volume.Lock) TileEntity(net.minecraft.tileentity.TileEntity) IAreaProvider(buildcraft.api.core.IAreaProvider) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

VolumeBox (buildcraft.core.marker.volume.VolumeBox)5 WorldSavedDataVolumeBoxes (buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes)5 BlockPos (net.minecraft.util.math.BlockPos)5 Lock (buildcraft.core.marker.volume.Lock)4 IAreaProvider (buildcraft.api.core.IAreaProvider)3 IBlockState (net.minecraft.block.state.IBlockState)3 TileEntity (net.minecraft.tileentity.TileEntity)3 AddonFillerPlanner (buildcraft.builders.addon.AddonFillerPlanner)2 EnumAddonSlot (buildcraft.core.marker.volume.EnumAddonSlot)2 ItemStack (net.minecraft.item.ItemStack)2 EnumFacing (net.minecraft.util.EnumFacing)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 World (net.minecraft.world.World)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IBox (buildcraft.api.core.IBox)1 IFillerPattern (buildcraft.api.filler.IFillerPattern)1 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 MjAPI (buildcraft.api.mj.MjAPI)1 MjBattery (buildcraft.api.mj.MjBattery)1 MjCapabilityHelper (buildcraft.api.mj.MjCapabilityHelper)1