Search in sources :

Example 1 with DoubleCoordinatesType

use of network.rs485.logisticspipes.world.DoubleCoordinatesType in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method placePipe.

public static boolean placePipe(CoreUnroutedPipe pipe, World world, int i, int j, int k, Block block, int meta, ITubeOrientation orientation) {
    if (world.isRemote) {
        return true;
    }
    boolean placed = world.setBlock(i, j, k, block, meta, 2);
    if (placed) {
        TileEntity tile = world.getTileEntity(i, j, k);
        if (tile instanceof LogisticsTileGenericPipe) {
            LogisticsTileGenericPipe tilePipe = (LogisticsTileGenericPipe) tile;
            if (pipe instanceof CoreMultiBlockPipe) {
                if (orientation == null) {
                    throw new NullPointerException();
                }
                CoreMultiBlockPipe mPipe = (CoreMultiBlockPipe) pipe;
                orientation.setOnPipe(mPipe);
                DoubleCoordinates placeAt = new DoubleCoordinates(i, j, k);
                LogisticsBlockGenericSubMultiBlock.currentCreatedMultiBlock = placeAt;
                LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> positions = ((CoreMultiBlockPipe) pipe).getSubBlocks();
                orientation.rotatePositions(positions);
                for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> pos : positions) {
                    pos.add(placeAt);
                    TileEntity subTile = world.getTileEntity(pos.getXInt(), pos.getYInt(), pos.getZInt());
                    if (subTile instanceof LogisticsTileGenericSubMultiBlock) {
                        ((LogisticsTileGenericSubMultiBlock) subTile).addMultiBlockMainPos(placeAt);
                        ((LogisticsTileGenericSubMultiBlock) subTile).addSubTypeTo(pos.getType());
                        MainProxy.sendPacketToAllWatchingChunk(subTile, ((LogisticsTileGenericSubMultiBlock) subTile).getLPDescriptionPacket());
                    } else {
                        world.setBlock(pos.getXInt(), pos.getYInt(), pos.getZInt(), LogisticsPipes.LogisticsSubMultiBlock, 0, 2);
                        subTile = world.getTileEntity(pos.getXInt(), pos.getYInt(), pos.getZInt());
                        if (subTile instanceof LogisticsTileGenericSubMultiBlock) {
                            ((LogisticsTileGenericSubMultiBlock) subTile).addSubTypeTo(pos.getType());
                        }
                    }
                    world.notifyBlockChange(pos.getXInt(), pos.getYInt(), pos.getZInt(), LogisticsPipes.LogisticsSubMultiBlock);
                }
                LogisticsBlockGenericSubMultiBlock.currentCreatedMultiBlock = null;
            }
            tilePipe.initialize(pipe);
            tilePipe.sendUpdateToClient();
        }
        world.notifyBlockChange(i, j, k, block);
    }
    return placed;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 2 with DoubleCoordinatesType

use of network.rs485.logisticspipes.world.DoubleCoordinatesType in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method addDestroyEffects.

/**
	 * Spawn particles for when the block is destroyed. Due to the nature of how
	 * this is invoked, the x/y/z locations are not always guaranteed to host
	 * your block. So be sure to do proper sanity checks before assuming that
	 * the location is this block.
	 *
	 * @param worldObj
	 *            The current world
	 * @param x
	 *            X position to spawn the particle
	 * @param y
	 *            Y position to spawn the particle
	 * @param z
	 *            Z position to spawn the particle
	 * @param meta
	 *            The metadata for the block before it was destroyed.
	 * @param effectRenderer
	 *            A reference to the current effect renderer.
	 * @return True to prevent vanilla break particles from spawning.
	 */
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
    CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.getPipe(worldObj, x, y, z);
    if (pipe == null) {
        return false;
    }
    PlayerConfig config = LogisticsPipes.getClientPlayerConfig();
    if (config.isUseNewRenderer()) {
        LogisticsNewRenderPipe.renderDestruction(pipe, worldObj, x, y, z, effectRenderer);
    } else {
        IIcon icon = pipe.getIconProvider().getIcon(pipe.getIconIndexForItem());
        byte its = 4;
        for (int i = 0; i < its; ++i) {
            for (int j = 0; j < its; ++j) {
                for (int k = 0; k < its; ++k) {
                    if (pipe.isMultiBlock()) {
                        LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> set = ((CoreMultiBlockPipe) pipe).getRotatedSubBlocks();
                        set.add(new DoubleCoordinatesType<>(0, 0, 0, CoreMultiBlockPipe.SubBlockTypeForShare.NON_SHARE));
                        for (DoubleCoordinates pos : set) {
                            int localx = x + pos.getXInt();
                            int localy = y + pos.getYInt();
                            int localz = z + pos.getZInt();
                            double px = localx + (i + 0.5D) / its;
                            double py = localy + (j + 0.5D) / its;
                            double pz = localz + (k + 0.5D) / its;
                            int random = rand.nextInt(6);
                            EntityDiggingFX fx = new EntityDiggingFX(worldObj, px, py, pz, px - localx - 0.5D, py - localy - 0.5D, pz - localz - 0.5D, LogisticsPipes.LogisticsPipeBlock, random, meta);
                            fx.setParticleIcon(icon);
                            effectRenderer.addEffect(fx.applyColourMultiplier(x, y, z));
                        }
                    } else {
                        double px = x + (i + 0.5D) / its;
                        double py = y + (j + 0.5D) / its;
                        double pz = z + (k + 0.5D) / its;
                        int random = rand.nextInt(6);
                        EntityDiggingFX fx = new EntityDiggingFX(worldObj, px, py, pz, px - x - 0.5D, py - y - 0.5D, pz - z - 0.5D, LogisticsPipes.LogisticsPipeBlock, random, meta);
                        fx.setParticleIcon(icon);
                        effectRenderer.addEffect(fx.applyColourMultiplier(x, y, z));
                    }
                }
            }
        }
    }
    return true;
}
Also used : EntityDiggingFX(net.minecraft.client.particle.EntityDiggingFX) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) IIcon(net.minecraft.util.IIcon) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) PlayerConfig(logisticspipes.config.PlayerConfig) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 3 with DoubleCoordinatesType

use of network.rs485.logisticspipes.world.DoubleCoordinatesType in project LogisticsPipes by RS485.

the class RenderTickHandler method renderWorldLast.

// private static final ResourceLocation TEXTURE = new ResourceLocation("logisticspipes", "textures/blocks/pipes/White.png");
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void renderWorldLast(RenderWorldLastEvent worldEvent) {
    // if (LogisticsRenderPipe.config.isUseNewRenderer()) {
    if (displayPipeGhost()) {
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayer player = mc.player;
        RayTraceResult box = mc.objectMouseOver;
        if (box != null && box.typeOfHit == RayTraceResult.Type.BLOCK) {
            ItemStack stack = FMLClientHandler.instance().getClient().player.inventory.mainInventory.get(FMLClientHandler.instance().getClient().player.inventory.currentItem);
            CoreUnroutedPipe pipe = ((ItemLogisticsPipe) stack.getItem()).getDummyPipe();
            World world = player.getEntityWorld();
            EnumFacing side = box.sideHit;
            BlockPos bPos = box.getBlockPos();
            Block block = world.getBlockState(bPos).getBlock();
            if (block == Blocks.SNOW_LAYER && block.isReplaceable(world, bPos)) {
                side = EnumFacing.UP;
            } else if (!block.isReplaceable(world, bPos)) {
                bPos = bPos.offset(side);
            }
            boolean isFreeSpace = true;
            ITubeOrientation orientation = null;
            if (pipe instanceof CoreMultiBlockPipe) {
                CoreMultiBlockPipe multipipe = (CoreMultiBlockPipe) pipe;
                DoubleCoordinates placeAt = new DoubleCoordinates(bPos);
                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();
                orientation = multipipe.getTubeOrientation(player, bPos.getX(), bPos.getZ());
                if (orientation != null) {
                    orientation.rotatePositions(positions);
                    positions.stream().map(pos -> pos.add(placeAt)).forEach(globalPos::add);
                    globalPos.addToAll(orientation.getOffset());
                    for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> pos : globalPos) {
                        if (!player.getEntityWorld().mayPlace(LPBlocks.pipe, pos.getBlockPos(), false, side, player)) {
                            TileEntity tile = player.getEntityWorld().getTileEntity(pos.getBlockPos());
                            boolean canPlace = false;
                            if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                                if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), pos.getType())) {
                                    canPlace = true;
                                }
                            }
                            if (!canPlace) {
                                isFreeSpace = false;
                                break;
                            }
                        }
                    }
                } else {
                    return;
                }
            } else {
                if (!player.getEntityWorld().mayPlace(LPBlocks.pipe, bPos, false, side, player)) {
                    isFreeSpace = false;
                }
            }
            if (isFreeSpace) {
                GlStateManager.pushMatrix();
                double x;
                double y;
                double z;
                if (orientation != null) {
                    x = bPos.getX() + orientation.getOffset().getXInt() - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.getPartialTicks());
                    y = bPos.getY() + orientation.getOffset().getYInt() - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.getPartialTicks());
                    z = bPos.getZ() + orientation.getOffset().getZInt() - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.getPartialTicks());
                } else {
                    x = bPos.getX() - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.getPartialTicks());
                    y = bPos.getY() - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.getPartialTicks());
                    z = bPos.getZ() - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.getPartialTicks());
                }
                GL11.glTranslated(x + 0.001, y + 0.001, z + 0.001);
                GlStateManager.enableBlend();
                // GL11.glDepthMask(false);
                GlStateManager.disableTexture2D();
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                mc.renderEngine.bindTexture(new ResourceLocation("logisticspipes", "textures/blocks/pipes/white.png"));
                SimpleServiceLocator.cclProxy.getRenderState().reset();
                SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0xff);
                GlStateManager.enableTexture2D();
                SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0x50);
                SimpleServiceLocator.cclProxy.getRenderState().startDrawing(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                pipe.getHighlightRenderer().renderHighlight(orientation);
                SimpleServiceLocator.cclProxy.getRenderState().draw();
                SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0xff);
                GlStateManager.disableBlend();
                GlStateManager.depthMask(true);
                GlStateManager.popMatrix();
            }
        }
    }
// }
}
Also used : ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) RenderTickEvent(net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent) Blocks(net.minecraft.init.Blocks) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) ActiveRenderInfo(net.minecraft.client.renderer.ActiveRenderInfo) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) ClientViewController(logisticspipes.routing.debug.ClientViewController) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) GL11(org.lwjgl.opengl.GL11) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) World(net.minecraft.world.World) GlStateManager(net.minecraft.client.renderer.GlStateManager) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) EventPriority(net.minecraftforge.fml.common.eventhandler.EventPriority) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) LPBlocks(logisticspipes.LPBlocks) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Phase(net.minecraftforge.fml.common.gameevent.TickEvent.Phase) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) ResourceLocation(net.minecraft.util.ResourceLocation) ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) BlockPos(net.minecraft.util.math.BlockPos) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) RayTraceResult(net.minecraft.util.math.RayTraceResult) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Minecraft(net.minecraft.client.Minecraft) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) LPPositionSet(logisticspipes.utils.LPPositionSet) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with DoubleCoordinatesType

use of network.rs485.logisticspipes.world.DoubleCoordinatesType 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)

Example 5 with DoubleCoordinatesType

use of network.rs485.logisticspipes.world.DoubleCoordinatesType in project LogisticsPipes by RS485.

the class ItemLogisticsPipe method onItemUse.

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    Block block = LPBlocks.pipe;
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block worldBlock = iblockstate.getBlock();
    if (!worldBlock.isReplaceable(worldIn, pos)) {
        pos = pos.offset(facing);
    }
    ItemStack itemstack = player.getHeldItem(hand);
    if (itemstack.isEmpty()) {
        return EnumActionResult.FAIL;
    }
    if (!dummyPipe.isMultiBlock()) {
        if (player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) {
            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[] { pos.getX(), pos.getY(), pos.getZ() });
                return EnumActionResult.PASS;
            }
            if (LogisticsBlockGenericPipe.placePipe(pipe, worldIn, pos, block, null)) {
                IBlockState state = worldIn.getBlockState(pos);
                if (state.getBlock() == block) {
                    // setTileEntityNBT(world, player, pos, stack);
                    block.onBlockPlacedBy(worldIn, pos, state, player, itemstack);
                    if (player instanceof EntityPlayerMP)
                        CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, itemstack);
                    IBlockState newBlockState = worldIn.getBlockState(pos);
                    SoundType soundtype = newBlockState.getBlock().getSoundType(newBlockState, worldIn, pos, player);
                    worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    itemstack.shrink(1);
                }
            }
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.FAIL;
        }
    } else {
        CoreMultiBlockPipe multiPipe = (CoreMultiBlockPipe) dummyPipe;
        boolean isFreeSpace = true;
        DoubleCoordinates placeAt = new DoubleCoordinates(pos);
        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(player, pos.getX(), pos.getZ());
        if (orientation == null) {
            return EnumActionResult.FAIL;
        }
        orientation.rotatePositions(positions);
        positions.stream().map(iPos -> iPos.add(placeAt)).forEach(globalPos::add);
        globalPos.addToAll(orientation.getOffset());
        placeAt.add(orientation.getOffset());
        for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> iPos : globalPos) {
            if (!player.canPlayerEdit(iPos.getBlockPos(), facing, itemstack) || !worldIn.mayPlace(block, iPos.getBlockPos(), false, facing, null)) {
                TileEntity tile = worldIn.getTileEntity(iPos.getBlockPos());
                boolean canPlace = false;
                if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                    if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), iPos.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[] { pos.getX(), pos.getY(), pos.getZ() });
                return EnumActionResult.SUCCESS;
            }
            if (LogisticsBlockGenericPipe.placePipe(pipe, worldIn, placeAt.getBlockPos(), block, orientation)) {
                IBlockState state = worldIn.getBlockState(placeAt.getBlockPos());
                if (state.getBlock() == block) {
                    // setTileEntityNBT(world, player, pos, stack);
                    block.onBlockPlacedBy(worldIn, pos, state, player, itemstack);
                    if (player instanceof EntityPlayerMP)
                        CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, placeAt.getBlockPos(), itemstack);
                    IBlockState newBlockState = worldIn.getBlockState(placeAt.getBlockPos());
                    SoundType soundtype = newBlockState.getBlock().getSoundType(newBlockState, worldIn, placeAt.getBlockPos(), player);
                    worldIn.playSound(player, placeAt.getBlockPos(), soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    itemstack.shrink(1);
                }
            }
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.FAIL;
        }
    }
}
Also used : SoundType(net.minecraft.block.SoundType) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) Getter(lombok.Getter) LogisticsPipes(logisticspipes.LogisticsPipes) EnumHand(net.minecraft.util.EnumHand) Level(org.apache.logging.log4j.Level) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) Side(net.minecraftforge.fml.relauncher.Side) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) SoundCategory(net.minecraft.util.SoundCategory) SoundType(net.minecraft.block.SoundType) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) LogisticsBlockGenericPipe(logisticspipes.pipes.basic.LogisticsBlockGenericPipe) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) IBlockState(net.minecraft.block.state.IBlockState) LPBlocks(logisticspipes.LPBlocks) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) IIconProvider(logisticspipes.renderer.IIconProvider) TileEntity(net.minecraft.tileentity.TileEntity) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) IBlockState(net.minecraft.block.state.IBlockState) 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) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

DoubleCoordinatesType (network.rs485.logisticspipes.world.DoubleCoordinatesType)8 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)7 TileEntity (net.minecraft.tileentity.TileEntity)6 World (net.minecraft.world.World)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 ITubeOrientation (logisticspipes.interfaces.ITubeOrientation)3 CoreMultiBlockPipe (logisticspipes.pipes.basic.CoreMultiBlockPipe)3 CoreUnroutedPipe (logisticspipes.pipes.basic.CoreUnroutedPipe)3 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)3 LPPositionSet (logisticspipes.utils.LPPositionSet)3 Block (net.minecraft.block.Block)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 BlockPos (net.minecraft.util.math.BlockPos)3 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 Nonnull (javax.annotation.Nonnull)2 LPBlocks (logisticspipes.LPBlocks)2 LogisticsPipes (logisticspipes.LogisticsPipes)2 LogisticsBlockGenericPipe (logisticspipes.pipes.basic.LogisticsBlockGenericPipe)2 IIconProvider (logisticspipes.renderer.IIconProvider)2