Search in sources :

Example 46 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class RenderTickHandler method renderWorldLast.

//private static final ResourceLocation TEXTURE = new ResourceLocation("logisticspipes", "textures/blocks/pipes/White.png");
@SubscribeEvent
public void renderWorldLast(RenderWorldLastEvent worldEvent) {
    if (LogisticsRenderPipe.config.isUseNewRenderer()) {
        if (displayPipeGhost()) {
            Minecraft mc = Minecraft.getMinecraft();
            EntityPlayer player = mc.thePlayer;
            MovingObjectPosition box = mc.objectMouseOver;
            if (box != null && box.typeOfHit == MovingObjectType.BLOCK) {
                ItemStack stack = FMLClientHandler.instance().getClient().thePlayer.inventory.mainInventory[FMLClientHandler.instance().getClient().thePlayer.inventory.currentItem];
                CoreUnroutedPipe pipe = ((ItemLogisticsPipe) stack.getItem()).getDummyPipe();
                int i = box.blockX;
                int j = box.blockY;
                int k = box.blockZ;
                World world = player.getEntityWorld();
                int side = box.sideHit;
                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++;
                    }
                }
                double xCoord = i;
                double yCoord = j;
                double zCoord = k;
                boolean isFreeSpace = true;
                ITubeOrientation orientation = null;
                if (pipe instanceof CoreMultiBlockPipe) {
                    CoreMultiBlockPipe multipipe = (CoreMultiBlockPipe) pipe;
                    DoubleCoordinates placeAt = new DoubleCoordinates(xCoord, yCoord, zCoord);
                    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, (int) xCoord, (int) zCoord);
                    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().canPlaceEntityOnSide(LogisticsPipes.LogisticsPipeBlock, pos.getXInt(), pos.getYInt(), pos.getZInt(), false, side, player, stack)) {
                                TileEntity tile = player.getEntityWorld().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;
                                }
                            }
                        }
                    } else {
                        return;
                    }
                } else {
                    if (!player.getEntityWorld().canPlaceEntityOnSide(LogisticsPipes.LogisticsPipeBlock, i, j, k, false, side, player, stack)) {
                        isFreeSpace = false;
                    }
                }
                if (isFreeSpace) {
                    GL11.glPushMatrix();
                    double x;
                    double y;
                    double z;
                    if (orientation != null) {
                        x = xCoord + orientation.getOffset().getXInt() - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.partialTicks);
                        y = yCoord + orientation.getOffset().getYInt() - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.partialTicks);
                        z = zCoord + orientation.getOffset().getZInt() - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.partialTicks);
                    } else {
                        x = xCoord - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.partialTicks);
                        y = yCoord - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.partialTicks);
                        z = zCoord - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.partialTicks);
                    }
                    GL11.glTranslated(x + 0.001, y + 0.001, z + 0.001);
                    GL11.glEnable(GL11.GL_BLEND);
                    //GL11.glDepthMask(false);
                    GL11.glDisable(GL11.GL_TEXTURE_2D);
                    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                    mc.renderEngine.bindTexture(new ResourceLocation("logisticspipes", "textures/blocks/pipes/White.png"));
                    Tessellator tess = Tessellator.instance;
                    CCRenderState.reset();
                    CCRenderState.useNormals = true;
                    CCRenderState.alphaOverride = 0xff;
                    GL11.glEnable(GL11.GL_TEXTURE_2D);
                    CCRenderState.alphaOverride = 0x50;
                    CCRenderState.useNormals = true;
                    CCRenderState.hasBrightness = false;
                    CCRenderState.startDrawing();
                    pipe.getHighlightRenderer().renderHighlight(orientation);
                    tess.draw();
                    CCRenderState.alphaOverride = 0xff;
                    GL11.glDisable(GL11.GL_BLEND);
                    GL11.glDepthMask(true);
                    GL11.glPopMatrix();
                }
            }
        }
    }
}
Also used : ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) EventPriority(cpw.mods.fml.common.eventhandler.EventPriority) Blocks(net.minecraft.init.Blocks) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) LogisticsPipes(logisticspipes.LogisticsPipes) ActiveRenderInfo(net.minecraft.client.renderer.ActiveRenderInfo) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) RenderTickEvent(cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) Minecraft(net.minecraft.client.Minecraft) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) ClientViewController(logisticspipes.routing.debug.ClientViewController) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) Core(tv.twitch.Core) GL11(org.lwjgl.opengl.GL11) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) CCRenderState(codechicken.lib.render.CCRenderState) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) Phase(cpw.mods.fml.common.gameevent.TickEvent.Phase) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Tessellator(net.minecraft.client.renderer.Tessellator) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectType(net.minecraft.util.MovingObjectPosition.MovingObjectType) Tessellator(net.minecraft.client.renderer.Tessellator) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) ResourceLocation(net.minecraft.util.ResourceLocation) ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Minecraft(net.minecraft.client.Minecraft) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) 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(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 47 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class SideConfigDisplay method doTileEntityRenderPass.

private void doTileEntityRenderPass(List<DoubleCoordinates> blocks, int pass) {
    RenderPassHelper.setEntityRenderPass(pass);
    for (DoubleCoordinates bc : blocks) {
        TileEntity tile = world.getTileEntity(bc.getXInt(), bc.getYInt(), bc.getZInt());
        if (tile != null) {
            Vector3d at = new Vector3d(eye.x, eye.y, eye.z);
            at.x += bc.getXDouble() - origin.x;
            at.y += bc.getYDouble() - origin.y;
            at.z += bc.getZDouble() - origin.z;
            GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
            TileEntityRendererDispatcher.instance.renderTileEntityAt(tile, at.x, at.y, at.z, 0);
            GL11.glPopAttrib();
        }
    }
    RenderPassHelper.clearEntityRenderPass();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Vector3d(logisticspipes.utils.math.Vector3d) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 48 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class SideConfigDisplay method updateSelection.

private void updateSelection(Vector3d start, Vector3d end) {
    start.add(origin);
    end.add(origin);
    List<MovingObjectPosition> hits = new ArrayList<>();
    LogisticsBlockGenericPipe.ignoreSideRayTrace = true;
    for (DoubleCoordinates bc : configurables) {
        Block block = world.getBlock(bc.getXInt(), bc.getYInt(), bc.getZInt());
        if (block != null) {
            if (block instanceof LogisticsBlockGenericPipe) {
                cachedLPBlockTrace = LogisticsPipes.LogisticsPipeBlock.doRayTrace(world, bc.getXInt(), bc.getYInt(), bc.getZInt(), Vec3.createVectorHelper(start.x, start.y, start.z), Vec3.createVectorHelper(end.x, end.y, end.z));
            } else {
                cachedLPBlockTrace = null;
            }
            MovingObjectPosition hit = block.collisionRayTrace(world, bc.getXInt(), bc.getYInt(), bc.getZInt(), Vec3.createVectorHelper(start.x, start.y, start.z), Vec3.createVectorHelper(end.x, end.y, end.z));
            if (hit != null) {
                hits.add(hit);
            }
        }
    }
    LogisticsBlockGenericPipe.ignoreSideRayTrace = false;
    selection = null;
    MovingObjectPosition hit = getClosestHit(Vec3.createVectorHelper(start.x, start.y, start.z), hits);
    if (hit != null) {
        TileEntity te = world.getTileEntity(hit.blockX, hit.blockY, hit.blockZ);
        if (te != null) {
            ForgeDirection face = ForgeDirection.getOrientation(hit.sideHit);
            selection = new SelectedFace(te, face, hit);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) LogisticsBlockGenericPipe(logisticspipes.pipes.basic.LogisticsBlockGenericPipe) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 49 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class PipeTransportLogistics method resolveUnroutedDestination.

public ForgeDirection resolveUnroutedDestination(LPTravelingItemServer data) {
    List<ForgeDirection> dirs = new ArrayList<>(Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
    dirs.remove(data.input.getOpposite());
    Iterator<ForgeDirection> iter = dirs.iterator();
    while (iter.hasNext()) {
        ForgeDirection dir = iter.next();
        DoubleCoordinates pos = CoordinateUtils.add(getPipe().getLPPosition(), dir);
        TileEntity tile = pos.getTileEntity(getWorld());
        if (!SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
            iter.remove();
        } else if (!canPipeConnect(tile, dir)) {
            iter.remove();
        } else if (tile instanceof LogisticsTileGenericPipe && !((LogisticsTileGenericPipe) tile).canConnect(container, dir.getOpposite(), false)) {
            iter.remove();
        }
    }
    if (dirs.isEmpty()) {
        return ForgeDirection.UNKNOWN;
    }
    int num = new Random().nextInt(dirs.size());
    return dirs.get(num);
}
Also used : LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 50 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class TEControl method handleBlockUpdate.

public static void handleBlockUpdate(final World world, final LPWorldInfo info, int x, int y, int z) {
    if (info.getWorldTick() < 5) {
        return;
    }
    final DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
    if (info.getUpdateQueued().contains(pos)) {
        return;
    }
    if (!pos.blockExists(world)) {
        return;
    }
    final TileEntity tile = pos.getTileEntity(world);
    if (SimpleServiceLocator.enderIOProxy.isBundledPipe(tile)) {
        QueuedTasks.queueTask(() -> {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile instanceof LogisticsTileGenericPipe) {
                    ((LogisticsTileGenericPipe) nextTile).scheduleNeighborChange();
                }
            }
            return null;
        });
    }
    if (tile == null || ((ILPTEInformation) tile).getObject() == null) {
        return;
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile) || SimpleServiceLocator.specialtileconnection.isType(tile)) {
        info.getUpdateQueued().add(pos);
        QueuedTasks.queueTask(() -> {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) nextTile).getObject().changeListeners)) {
                        listener.pipeModified(pos);
                    }
                }
            }
            for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) tile).getObject().changeListeners)) {
                listener.pipeModified(pos);
            }
            info.getUpdateQueued().remove(pos);
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)822 ItemStack (net.minecraft.item.ItemStack)149 BlockPos (net.minecraft.util.math.BlockPos)130 Block (net.minecraft.block.Block)83 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)76 EnumFacing (net.minecraft.util.EnumFacing)62 ArrayList (java.util.ArrayList)61 IBlockState (net.minecraft.block.state.IBlockState)61 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 IInventory (net.minecraft.inventory.IInventory)49 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)44 World (net.minecraft.world.World)43 EntityItem (net.minecraft.entity.item.EntityItem)39 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)35 FluidStack (net.minecraftforge.fluids.FluidStack)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 HashMap (java.util.HashMap)25 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)23 AMVector3 (am2.api.math.AMVector3)21 Entity (net.minecraft.entity.Entity)21