Search in sources :

Example 1 with RenderWorldLastEvent

use of net.minecraftforge.client.event.RenderWorldLastEvent 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 2 with RenderWorldLastEvent

use of net.minecraftforge.client.event.RenderWorldLastEvent in project GregTech by GregTechCE.

the class DebugRenderer method onRenderWorldLast.

@SubscribeEvent
public static void onRenderWorldLast(RenderWorldLastEvent event) {
    RenderGlobal context = event.getContext();
    float partialTicks = event.getPartialTicks();
    EntityPlayer player = Minecraft.getMinecraft().player;
    WorldClient world = Minecraft.getMinecraft().world;
    if (blockPosSet.size() == 0) {
        return;
    }
    double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
    GlStateManager.pushMatrix();
    GlStateManager.translate(-playerX, -playerY, -playerZ);
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.disableTexture2D();
    GlStateManager.disableDepth();
    GlStateManager.glLineWidth(2.5F);
    {
        blockPosSet.forEach(blockPos -> {
            double distance = MathHelper.sqrt(player.getDistanceSqToCenter(blockPos));
            if (distance > 64F) {
                return;
            }
            AxisAlignedBB box = new AxisAlignedBB(blockPos.getX() + 0.25, blockPos.getY() + 0.25, blockPos.getZ() + 0.25, blockPos.getX() + 0.75, blockPos.getY() + 0.75, blockPos.getZ() + 0.75);
            RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 1F, 0.0F, 0.5F);
            TileEntity tileEntity = world.getTileEntity(blockPos);
            if (tileEntity != null) {
                AxisAlignedBB axisAlignedBB = new AxisAlignedBB(blockPos.getX() + 0.25, blockPos.getY() + 0.25, blockPos.getZ() + 0.25, blockPos.getX() + 0.75, blockPos.getY() + 0.75, blockPos.getZ() + 0.75);
                RenderGlobal.drawSelectionBoundingBox(axisAlignedBB, 0.0F, 0.0F, 1F, 0.5F);
            // ((TileEntityCableEmitter) tileEntity).outgoingConnections.forEach(connectionInfo -> {
            // RenderGlobal.drawSelectionBoundingBox(new AxisAlignedBB(connectionInfo.receiverContainer.getPos()), 0.0F, 1F, 1F, 0.5F);
            // 
            // });
            }
        });
    }
    GlStateManager.enableDepth();
    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
    GlStateManager.popMatrix();
}
Also used : BlockEvent(net.minecraftforge.event.world.BlockEvent) MetaBlocks(gregtech.common.blocks.MetaBlocks) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) GlStateManager(net.minecraft.client.renderer.GlStateManager) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Set(java.util.Set) WorldClient(net.minecraft.client.multiplayer.WorldClient) BlockPos(net.minecraft.util.math.BlockPos) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) HashSet(java.util.HashSet) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) Mod(net.minecraftforge.fml.common.Mod) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldClient(net.minecraft.client.multiplayer.WorldClient) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Minecraft (net.minecraft.client.Minecraft)2 GlStateManager (net.minecraft.client.renderer.GlStateManager)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 RenderWorldLastEvent (net.minecraftforge.client.event.RenderWorldLastEvent)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Side (net.minecraftforge.fml.relauncher.Side)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 MetaBlocks (gregtech.common.blocks.MetaBlocks)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 LPBlocks (logisticspipes.LPBlocks)1 ITubeOrientation (logisticspipes.interfaces.ITubeOrientation)1 ItemLogisticsPipe (logisticspipes.items.ItemLogisticsPipe)1 CoreMultiBlockPipe (logisticspipes.pipes.basic.CoreMultiBlockPipe)1 CoreUnroutedPipe (logisticspipes.pipes.basic.CoreUnroutedPipe)1 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)1 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)1 LogisticsGuiOverrenderer (logisticspipes.renderer.LogisticsGuiOverrenderer)1