Search in sources :

Example 6 with LPPositionSet

use of logisticspipes.utils.LPPositionSet in project LogisticsPipes by RS485.

the class HSTubeSpeedup method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(List arraylist, AxisAlignedBB axisalignedbb) {
    DoubleCoordinates pos = getLPPosition();
    DoubleCoordinates posMin = new DoubleCoordinates(LPConstants.PIPE_MIN_POS, LPConstants.PIPE_MIN_POS, LPConstants.PIPE_MIN_POS);
    DoubleCoordinates posMax = new DoubleCoordinates(LPConstants.PIPE_MAX_POS, LPConstants.PIPE_MAX_POS, -3);
    orientation.rotatePositions(posMin);
    orientation.rotatePositions(posMax);
    if (orientation == SpeedupDirection.EAST) {
        pos.add(new DoubleCoordinates(1, 0, 0));
    } else if (orientation == SpeedupDirection.SOUTH) {
        pos.add(new DoubleCoordinates(1, 0, 1));
    } else if (orientation == SpeedupDirection.WEST) {
        pos.add(new DoubleCoordinates(0, 0, 1));
    }
    posMin.add(pos);
    posMax.add(pos);
    LPPositionSet<DoubleCoordinates> set = new LPPositionSet<>(DoubleCoordinates.class);
    set.add(posMin);
    set.add(posMax);
    AxisAlignedBB box = set.toABB();
    if (box != null && (axisalignedbb == null || axisalignedbb.intersectsWith(box))) {
        arraylist.add(box);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 7 with LPPositionSet

use of logisticspipes.utils.LPPositionSet in project LogisticsPipes by RS485.

the class HSTubeGain method getConnectedEndTile.

@Override
public TileEntity getConnectedEndTile(ForgeDirection output) {
    if (orientation.dir.getOpposite() == output) {
        return container.getTile(output);
    } else {
        DoubleCoordinates pos = new DoubleCoordinates(0, 1, -3);
        LPPositionSet<DoubleCoordinates> set = new LPPositionSet<>(DoubleCoordinates.class);
        set.add(pos);
        orientation.rotatePositions(set);
        TileEntity subTile = pos.add(getLPPosition()).getTileEntity(getWorld());
        if (subTile instanceof LogisticsTileGenericSubMultiBlock) {
            return ((LogisticsTileGenericSubMultiBlock) subTile).getTile(output);
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LPPositionSet(logisticspipes.utils.LPPositionSet) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 8 with LPPositionSet

use of logisticspipes.utils.LPPositionSet in project LogisticsPipes by RS485.

the class HSTubeGain method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(List arraylist, AxisAlignedBB axisalignedbb) {
    if (boxes == null || boxes.isEmpty()) {
        boxes = new ArrayList<>();
        double x = getX();
        double y = getY();
        double z = getZ();
        for (int i = -1; i < 54; i++) {
            double xOne = x;
            double yOne = y;
            double zOne = z;
            double xTwo = x;
            double yTwo = y + 2;
            double zTwo = z;
            if (orientation.getRenderOrientation() == TubeGainRenderOrientation.SOUTH) {
                zOne += 4.0F * (i - 4) / 50;
                zTwo += 4.0F * (i + 4) / 50;
                xOne += 1;
                xTwo -= 2;
            } else if (orientation.getRenderOrientation() == TubeGainRenderOrientation.WEST) {
                xOne -= 3;
                xTwo -= 3;
                xOne += 4.0F * (i - 4) / 50;
                xTwo += 4.0F * (i + 4) / 50;
                zOne -= 1;
                zTwo += 2;
            } else if (orientation.getRenderOrientation() == TubeGainRenderOrientation.NORTH) {
                zOne += 1;
                zTwo += 1;
                zOne -= 4.0F * (i - 4) / 50;
                zTwo -= 4.0F * (i + 4) / 50;
                xOne -= 1;
                xTwo += 2;
            } else if (orientation.getRenderOrientation() == TubeGainRenderOrientation.EAST) {
                xOne += 4;
                xTwo += 4;
                xOne -= 4.0F * (i - 4) / 50;
                xTwo -= 4.0F * (i + 4) / 50;
                zOne -= 1;
                zTwo += 2;
            }
            AxisAlignedBB box = GainTubeRenderer.getObjectBoundsAt(AxisAlignedBB.getBoundingBox(Math.min(xOne, xTwo), Math.min(yOne, yTwo), Math.min(zOne, zTwo), Math.max(xOne, xTwo), Math.max(yOne, yTwo), Math.max(zOne, zTwo)).getOffsetBoundingBox(-x, -y, -z), orientation);
            if (box != null) {
                LPPositionSet<DoubleCoordinates> lpBox = new LPPositionSet<>(DoubleCoordinates.class);
                lpBox.addFrom(box);
                DoubleCoordinates center = lpBox.getCenter();
                box = AxisAlignedBB.getBoundingBox(center.getXCoord() - 0.3D, center.getYCoord() - 0.3D, center.getZCoord() - 0.3D, center.getXCoord() + 0.3D, center.getYCoord() + 0.3D, center.getZCoord() + 0.3D);
                if (box != null) {
                    AxisAlignedBB cBox = getCompleteBox();
                    if (box.minX < cBox.minX) {
                        box.minX = cBox.minX;
                    }
                    if (box.minY < cBox.minY) {
                        box.minY = cBox.minY;
                    }
                    if (box.minZ < cBox.minZ) {
                        box.minZ = cBox.minZ;
                    }
                    if (box.maxX > cBox.maxX) {
                        box.maxX = cBox.maxX;
                    }
                    if (box.maxY > cBox.maxY) {
                        box.maxY = cBox.maxY;
                    }
                    if (box.maxZ > cBox.maxZ) {
                        box.maxZ = cBox.maxZ;
                    }
                    box = box.getOffsetBoundingBox(x, y, z);
                    boxes.add(box);
                }
            }
        }
    }
    arraylist.addAll(boxes.stream().filter(box -> box != null && (axisalignedbb == null || axisalignedbb.intersectsWith(box))).collect(Collectors.toList()));
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 9 with LPPositionSet

use of logisticspipes.utils.LPPositionSet in project LogisticsPipes by RS485.

the class HSTubeSCurve method addCollisionBoxesToList.

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addCollisionBoxesToList(List arraylist, AxisAlignedBB axisalignedbb) {
    if (boxes == null || boxes.isEmpty()) {
        boxes = new ArrayList<>();
        double x = getX();
        double y = getY();
        double z = getZ();
        for (int i = -1; i < 54; i++) {
            double xOne = x;
            double yOne = y;
            double zOne = z;
            double xTwo = x;
            double yTwo = y + 1;
            double zTwo = z;
            if (orientation.getRenderOrientation() == TurnSDirection.NORTH_INV || orientation.getRenderOrientation() == TurnSDirection.NORTH) {
                zOne += 1;
                zTwo += 1;
                zOne -= 4.0F * (i - 4) / 50;
                zTwo -= 4.0F * (i + 4) / 50;
                xOne -= 1;
                xTwo += 2;
            } else if (orientation.getRenderOrientation() == TurnSDirection.EAST_INV || orientation.getRenderOrientation() == TurnSDirection.EAST) {
                xOne += 4;
                xTwo += 4;
                xOne -= 4.0F * (i - 4) / 50;
                xTwo -= 4.0F * (i + 4) / 50;
                zOne -= 1;
                zTwo += 2;
            }
            AxisAlignedBB box = SCurveTubeRenderer.getObjectBoundsAt(AxisAlignedBB.getBoundingBox(Math.min(xOne, xTwo), Math.min(yOne, yTwo), Math.min(zOne, zTwo), Math.max(xOne, xTwo), Math.max(yOne, yTwo), Math.max(zOne, zTwo)).getOffsetBoundingBox(-x, -y, -z), orientation);
            if (box != null) {
                LPPositionSet<DoubleCoordinates> lpBox = new LPPositionSet<>(DoubleCoordinates.class);
                lpBox.addFrom(box);
                DoubleCoordinates center = lpBox.getCenter();
                box = AxisAlignedBB.getBoundingBox(center.getXCoord() - 0.3D, center.getYCoord() - 0.3D, center.getZCoord() - 0.3D, center.getXCoord() + 0.3D, center.getYCoord() + 0.3D, center.getZCoord() + 0.3D);
                if (box != null) {
                    AxisAlignedBB cBox = getCompleteBox();
                    if (box.minX < cBox.minX) {
                        box.minX = cBox.minX;
                    }
                    if (box.minY < cBox.minY) {
                        box.minY = cBox.minY;
                    }
                    if (box.minZ < cBox.minZ) {
                        box.minZ = cBox.minZ;
                    }
                    if (box.maxX > cBox.maxX) {
                        box.maxX = cBox.maxX;
                    }
                    if (box.maxY > cBox.maxY) {
                        box.maxY = cBox.maxY;
                    }
                    if (box.maxZ > cBox.maxZ) {
                        box.maxZ = cBox.maxZ;
                    }
                    box = box.getOffsetBoundingBox(x, y, z);
                    boxes.add(box);
                }
            }
        }
    }
    arraylist.addAll(boxes.stream().filter(box -> box != null && (axisalignedbb == null || axisalignedbb.intersectsWith(box))).collect(Collectors.toList()));
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 10 with LPPositionSet

use of logisticspipes.utils.LPPositionSet in project LogisticsPipes by RS485.

the class ItemLogisticsPipe method onItemUse.

@Override
public //TODO use own pipe handling
boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int sideI, float par8, float par9, float par10) {
    int side = sideI;
    Block block = LogisticsPipes.LogisticsPipeBlock;
    int i = x;
    int j = y;
    int k = z;
    Block worldBlock = world.getBlock(i, j, k);
    if (worldBlock == Blocks.snow) {
        side = 1;
    } else if (worldBlock != Blocks.vine && worldBlock != Blocks.tallgrass && worldBlock != Blocks.deadbush && (worldBlock == null || !worldBlock.isReplaceable(world, i, j, k))) {
        if (side == 0) {
            j--;
        }
        if (side == 1) {
            j++;
        }
        if (side == 2) {
            k--;
        }
        if (side == 3) {
            k++;
        }
        if (side == 4) {
            i--;
        }
        if (side == 5) {
            i++;
        }
    }
    if (itemstack.stackSize == 0) {
        return false;
    }
    if (!dummyPipe.isMultiBlock()) {
        if (world.canPlaceEntityOnSide(block, i, j, k, false, side, entityplayer, itemstack)) {
            CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(this);
            if (pipe == null) {
                LogisticsPipes.log.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[] { i, j, k });
                return true;
            }
            if (LogisticsBlockGenericPipe.placePipe(pipe, world, i, j, k, block, 0)) {
                block.onBlockPlacedBy(world, i, j, k, entityplayer, itemstack);
                itemstack.stackSize--;
            }
            return true;
        } else {
            return false;
        }
    } else {
        CoreMultiBlockPipe multiPipe = (CoreMultiBlockPipe) dummyPipe;
        boolean isFreeSpace = true;
        DoubleCoordinates placeAt = new DoubleCoordinates(i, j, k);
        LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> globalPos = new LPPositionSet<>(DoubleCoordinatesType.class);
        globalPos.add(new DoubleCoordinatesType<>(placeAt, CoreMultiBlockPipe.SubBlockTypeForShare.NON_SHARE));
        LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> positions = multiPipe.getSubBlocks();
        ITubeOrientation orientation = multiPipe.getTubeOrientation(entityplayer, i, k);
        if (orientation == null) {
            return false;
        }
        orientation.rotatePositions(positions);
        positions.stream().map(pos -> pos.add(placeAt)).forEach(globalPos::add);
        globalPos.addToAll(orientation.getOffset());
        placeAt.add(orientation.getOffset());
        for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> pos : globalPos) {
            if (!world.canPlaceEntityOnSide(block, pos.getXInt(), pos.getYInt(), pos.getZInt(), false, side, entityplayer, itemstack)) {
                TileEntity tile = world.getTileEntity(pos.getXInt(), pos.getYInt(), pos.getZInt());
                boolean canPlace = false;
                if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                    if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), pos.getType())) {
                        canPlace = true;
                    }
                }
                if (!canPlace) {
                    isFreeSpace = false;
                    break;
                }
            }
        }
        if (isFreeSpace) {
            CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(this);
            if (pipe == null) {
                LogisticsPipes.log.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[] { i, j, k });
                return true;
            }
            if (LogisticsBlockGenericPipe.placePipe(pipe, world, placeAt.getXInt(), placeAt.getYInt(), placeAt.getZInt(), block, 0, orientation)) {
                //TODO
                block.onBlockPlacedBy(world, i, j, k, entityplayer, itemstack);
                itemstack.stackSize--;
            }
            return true;
        } else {
            return false;
        }
    }
}
Also used : Blocks(net.minecraft.init.Blocks) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) Getter(lombok.Getter) LogisticsPipes(logisticspipes.LogisticsPipes) Level(org.apache.logging.log4j.Level) StringUtils(logisticspipes.utils.string.StringUtils) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) LogisticsBlockGenericPipe(logisticspipes.pipes.basic.LogisticsBlockGenericPipe) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) IIcon(net.minecraft.util.IIcon) List(java.util.List) IIconProvider(logisticspipes.renderer.IIconProvider) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) TileEntity(net.minecraft.tileentity.TileEntity) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) LPPositionSet(logisticspipes.utils.LPPositionSet) Block(net.minecraft.block.Block) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)

Aggregations

LPPositionSet (logisticspipes.utils.LPPositionSet)10 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)10 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)6 TileEntity (net.minecraft.tileentity.TileEntity)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)4 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 LogisticsPipes (logisticspipes.LogisticsPipes)2 ITubeOrientation (logisticspipes.interfaces.ITubeOrientation)2 CoreMultiBlockPipe (logisticspipes.pipes.basic.CoreMultiBlockPipe)2 CoreUnroutedPipe (logisticspipes.pipes.basic.CoreUnroutedPipe)2 Block (net.minecraft.block.Block)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Blocks (net.minecraft.init.Blocks)2 ItemStack (net.minecraft.item.ItemStack)2 World (net.minecraft.world.World)2 CoordinateUtils (network.rs485.logisticspipes.world.CoordinateUtils)2 DoubleCoordinatesType (network.rs485.logisticspipes.world.DoubleCoordinatesType)2 CCRenderState (codechicken.lib.render.CCRenderState)1 FMLClientHandler (cpw.mods.fml.client.FMLClientHandler)1 EventPriority (cpw.mods.fml.common.eventhandler.EventPriority)1