Search in sources :

Example 6 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method doRayTrace.

private RaytraceResult doRayTrace(LogisticsTileGenericPipe tileG, CoreUnroutedPipe pipe, Vec3 origin, Vec3 direction) {
    if (tileG == null) {
        return null;
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return null;
    }
    /**
		 * pipe hits along x, y, and z axis, gate (all 6 sides) [and
		 * wires+facades]
		 */
    MovingObjectPosition[] hits = new MovingObjectPosition[31];
    AxisAlignedBB[] boxes = new AxisAlignedBB[31];
    ForgeDirection[] sideHit = new ForgeDirection[31];
    Arrays.fill(sideHit, ForgeDirection.UNKNOWN);
    // pipe
    for (ForgeDirection side : LogisticsBlockGenericPipe.DIR_VALUES) {
        if (side == ForgeDirection.UNKNOWN || tileG.isPipeConnected(side)) {
            if (side != ForgeDirection.UNKNOWN && ignoreSideRayTrace)
                continue;
            AxisAlignedBB bb = getPipeBoundingBox(side);
            setBlockBounds(bb);
            boxes[side.ordinal()] = bb;
            hits[side.ordinal()] = super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction);
            sideHit[side.ordinal()] = side;
        }
    }
    for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
        if (tileG.getPipePluggable(side) != null) {
            if (side != ForgeDirection.UNKNOWN && ignoreSideRayTrace)
                continue;
            AxisAlignedBB bb = tileG.getPipePluggable(side).getBoundingBox(side);
            setBlockBounds(bb);
            boxes[7 + side.ordinal()] = bb;
            hits[7 + side.ordinal()] = super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction);
            sideHit[7 + side.ordinal()] = side;
        }
    }
    // TODO: check wires
    // get closest hit
    double minLengthSquared = Double.POSITIVE_INFINITY;
    int minIndex = -1;
    for (int i = 0; i < hits.length; i++) {
        MovingObjectPosition hit = hits[i];
        if (hit == null) {
            continue;
        }
        double lengthSquared = hit.hitVec.squareDistanceTo(origin);
        if (lengthSquared < minLengthSquared) {
            minLengthSquared = lengthSquared;
            minIndex = i;
        }
    }
    // reset bounds
    setBlockBounds(0, 0, 0, 1, 1, 1);
    if (minIndex == -1) {
        return null;
    } else {
        Part hitPart;
        if (minIndex < 7) {
            hitPart = Part.Pipe;
        } else {
            hitPart = Part.Pluggable;
        }
        return new RaytraceResult(hitPart, hits[minIndex], boxes[minIndex], sideHit[minIndex]);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 7 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project LogisticsPipes by RS485.

the class LogisticsHUDRenderer method renderWorldRelative.

public void renderWorldRelative(long renderTicks, float partialTick) {
    if (!displayRenderer()) {
        return;
    }
    Minecraft mc = FMLClientHandler.instance().getClient();
    EntityPlayer player = mc.thePlayer;
    if (list.size() == 0 || Math.hypot(lastXPos - player.posX, Math.hypot(lastYPos - player.posY, lastZPos - player.posZ)) > 0.5 || (renderTicks % 10 == 0 && (lastXPos != player.posX || lastYPos != player.posY || lastZPos != player.posZ)) || renderTicks % 600 == 0) {
        refreshList(player.posX, player.posY, player.posZ);
        lastXPos = player.posX;
        lastYPos = player.posY;
        lastZPos = player.posZ;
    }
    boolean cursorHandled = false;
    displayCross = false;
    IHUDConfig config;
    if (debugHUD == null) {
        config = new HUDConfig(mc.thePlayer.inventory.armorInventory[3]);
    } else {
        config = new IHUDConfig() {

            @Override
            public boolean isHUDSatellite() {
                return false;
            }

            @Override
            public boolean isHUDProvider() {
                return false;
            }

            @Override
            public boolean isHUDPowerLevel() {
                return false;
            }

            @Override
            public boolean isHUDInvSysCon() {
                return false;
            }

            @Override
            public boolean isHUDCrafting() {
                return false;
            }

            @Override
            public boolean isHUDChassie() {
                return false;
            }

            @Override
            public void setHUDChassie(boolean state) {
            }

            @Override
            public void setHUDCrafting(boolean state) {
            }

            @Override
            public void setHUDInvSysCon(boolean state) {
            }

            @Override
            public void setHUDPowerJunction(boolean state) {
            }

            @Override
            public void setHUDProvider(boolean state) {
            }

            @Override
            public void setHUDSatellite(boolean state) {
            }
        };
    }
    IHeadUpDisplayRendererProvider thisIsLast = null;
    List<IHeadUpDisplayRendererProvider> toUse = list;
    if (debugHUD != null) {
        toUse = debugHUD.getHUDs();
    }
    for (IHeadUpDisplayRendererProvider renderer : toUse) {
        if (renderer.getRenderer() == null) {
            continue;
        }
        if (renderer.getRenderer().display(config)) {
            GL11.glPushMatrix();
            if (!cursorHandled) {
                double x = renderer.getX() + 0.5 - player.posX;
                double y = renderer.getY() + 0.5 - player.posY;
                double z = renderer.getZ() + 0.5 - player.posZ;
                if (Math.hypot(x, Math.hypot(y, z)) < 0.75 || (renderer instanceof IHeadUpDisplayBlockRendererProvider && (((IHeadUpDisplayBlockRendererProvider) renderer).isHUDInvalid() || !((IHeadUpDisplayBlockRendererProvider) renderer).isHUDExistent()))) {
                    refreshList(player.posX, player.posY, player.posZ);
                    GL11.glPopMatrix();
                    break;
                }
                int[] pos = getCursor(renderer);
                if (pos.length == 2) {
                    if (renderer.getRenderer().cursorOnWindow(pos[0], pos[1])) {
                        renderer.getRenderer().handleCursor(pos[0], pos[1]);
                        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
                            //if(FMLClientHandler.instance().getClient().thePlayer.isSneaking()) {
                            thisIsLast = renderer;
                            displayCross = true;
                        }
                        cursorHandled = true;
                    }
                }
            }
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            if (thisIsLast != renderer) {
                displayOneView(renderer, config, partialTick, false);
            }
            GL11.glPopMatrix();
        }
    }
    if (thisIsLast != null) {
        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        displayOneView(thisIsLast, config, partialTick, true);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glPopMatrix();
    }
    GL11.glPushMatrix();
    MovingObjectPosition box = mc.objectMouseOver;
    if (box != null && box.typeOfHit == MovingObjectType.BLOCK) {
        if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
            progress = Math.min(progress + (2 * Math.max(1, (int) Math.floor((System.currentTimeMillis() - last) / 50.0D))), 100);
        } else {
            progress = Math.max(progress - (2 * Math.max(1, (int) Math.floor((System.currentTimeMillis() - last) / 50.0D))), 0);
        }
        if (progress != 0) {
            List<String> textData = new ArrayList<>();
            if (textData.isEmpty()) {
                textData = SimpleServiceLocator.neiProxy.getInfoForPosition(player.worldObj, player, box);
            }
            if (!textData.isEmpty()) {
                double xCoord = box.blockX + 0.5D;
                double yCoord = box.blockY + 0.5D;
                double zCoord = box.blockZ + 0.5D;
                double x = xCoord - player.prevPosX - ((player.posX - player.prevPosX) * partialTick);
                double y = yCoord - player.prevPosY - ((player.posY - player.prevPosY) * partialTick);
                double z = zCoord - player.prevPosZ - ((player.posZ - player.prevPosZ) * partialTick);
                GL11.glDisable(GL11.GL_DEPTH_TEST);
                GL11.glTranslatef((float) x, (float) y, (float) z);
                GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(getAngle(z, x) + 110F, 0.0F, 0.0F, 1.0F);
                GL11.glRotatef((-1) * getAngle(Math.hypot(x + 0.8, z + 0.8), y + 0.5) + 180, 1.0F, 0.0F, 0.0F);
                double dProgress = progress / 100D;
                GL11.glTranslated(0.4D * dProgress + 0.6D, -0.2D * dProgress - 0.6D, -0.0D);
                GL11.glScalef(0.01F, 0.01F, 1F);
                int heigth = Math.max(32, 10 * textData.size() + 15);
                int width = 0;
                for (String s : textData) {
                    width = Math.max(width, mc.fontRenderer.getStringWidth(s) + 22);
                }
                width = Math.max(32, width + 15);
                GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 96);
                GuiGraphics.drawGuiBackGround(mc, (int) ((-0.5 * (width - 32)) * dProgress) - 16, (int) ((-0.5 * (heigth - 32)) * dProgress) - 16, (int) ((0.5 * (width - 32)) * dProgress) + 16, (int) ((0.5 * (heigth - 32)) * dProgress) + 16, 0, false);
                GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 127);
                if (progress == 100) {
                    GL11.glTranslated((int) ((-0.5 * (width - 32)) * dProgress) - 16, (int) ((-0.5 * (heigth - 32)) * dProgress) - 16, -0.0001D);
                    for (int i = 0; i < textData.size(); i++) {
                        mc.fontRenderer.drawString(textData.get(i), 28, 8 + i * 10, 0x000000);
                    }
                    ItemStack item = SimpleServiceLocator.neiProxy.getItemForPosition(player.worldObj, player, box);
                    if (item != null) {
                        float scaleX = 1.5F * 0.8F;
                        float scaleY = 1.5F * 0.8F;
                        float scaleZ = -0.0001F;
                        GL11.glScalef(scaleX, scaleY, scaleZ);
                        ItemStackRenderer itemStackRenderer = new ItemStackRenderer(5, 6, 0.0F, false, true, true);
                        itemStackRenderer.setItemstack(item).setDisplayAmount(DisplayAmount.NEVER);
                        itemStackRenderer.setScaleX(scaleX).setScaleY(scaleY).setScaleZ(scaleZ);
                        itemStackRenderer.renderInGui();
                    }
                }
                GL11.glEnable(GL11.GL_DEPTH_TEST);
            }
        }
    } else if (!Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
        progress = 0;
    }
    GL11.glPopMatrix();
    //Render Laser
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    //GL11.glEnable(GL11.GL_LIGHTING);
    for (LaserData data : lasers) {
        GL11.glPushMatrix();
        double x = data.getPosX() + 0.5 - player.prevPosX - ((player.posX - player.prevPosX) * partialTick);
        double y = data.getPosY() + 0.5 - player.prevPosY - ((player.posY - player.prevPosY) * partialTick);
        double z = data.getPosZ() + 0.5 - player.prevPosZ - ((player.posZ - player.prevPosZ) * partialTick);
        GL11.glTranslatef((float) x, (float) y, (float) z);
        switch(data.getDir()) {
            case NORTH:
                GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
                break;
            case SOUTH:
                GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
                break;
            case EAST:
                break;
            case WEST:
                GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
                break;
            case UP:
                GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F);
                break;
            case DOWN:
                GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
                break;
            default:
                break;
        }
        GL11.glScalef(0.01F, 0.01F, 0.01F);
        Tessellator tessellator = Tessellator.instance;
        for (float i = 0; i < 6 * data.getLength(); i++) {
            setColor(i, data.getConnectionType());
            float shift = 100f * i / 6f;
            float start = 0.0f;
            if (data.isStartPipe() && i == 0) {
                start = -6.0f;
            }
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, 3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, 3.0f);
            tessellator.addVertex(19.7f + shift, 3.0f, 3.0f);
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, -3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, -3.0f);
            tessellator.addVertex(19.7f + shift, -3.0f, -3.0f);
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, 3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, 3.0f);
            tessellator.addVertex(19.7f + shift, -3.0f, 3.0f);
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, -3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, -3.0f);
            tessellator.addVertex(19.7f + shift, 3.0f, -3.0f);
            tessellator.draw();
        }
        if (data.isStartPipe()) {
            setColor(0, data.getConnectionType());
            tessellator.startDrawingQuads();
            tessellator.addVertex(-3.0f, 3.0f, 3.0f);
            tessellator.addVertex(-3.0f, 3.0f, -3.0f);
            tessellator.addVertex(-3.0f, -3.0f, -3.0f);
            tessellator.addVertex(-3.0f, -3.0f, 3.0f);
            tessellator.draw();
        }
        if (data.isFinalPipe()) {
            setColor(6 * data.getLength() - 1, data.getConnectionType());
            tessellator.startDrawingQuads();
            tessellator.addVertex(100.0f * data.getLength() + 3f, 3.0f, -3.0f);
            tessellator.addVertex(100.0f * data.getLength() + 3f, 3.0f, 3.0f);
            tessellator.addVertex(100.0f * data.getLength() + 3f, -3.0f, 3.0f);
            tessellator.addVertex(100.0f * data.getLength() + 3f, -3.0f, -3.0f);
            tessellator.draw();
        }
        GL11.glPopMatrix();
    }
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    last = System.currentTimeMillis();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) ArrayList(java.util.ArrayList) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) Minecraft(net.minecraft.client.Minecraft) IHUDConfig(logisticspipes.interfaces.IHUDConfig) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) HUDConfig(logisticspipes.hud.HUDConfig) IHUDConfig(logisticspipes.interfaces.IHUDConfig) EntityPlayer(net.minecraft.entity.player.EntityPlayer) LaserData(logisticspipes.routing.LaserData) ItemStack(net.minecraft.item.ItemStack) ItemStackRenderer(logisticspipes.utils.item.ItemStackRenderer)

Example 8 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition 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 9 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition 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 10 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project SimplyJetpacks by Tonius.

the class ItemJetpackFueller method onUsingTick.

@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IEnergyProvider(cofh.api.energy.IEnergyProvider) FluidStack(net.minecraftforge.fluids.FluidStack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) FuelType(tonius.simplyjetpacks.setup.FuelType) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

MovingObjectPosition (net.minecraft.util.MovingObjectPosition)60 Vec3 (net.minecraft.util.Vec3)19 Entity (net.minecraft.entity.Entity)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)17 ItemStack (net.minecraft.item.ItemStack)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Block (net.minecraft.block.Block)8 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 AMVector3 (am2.api.math.AMVector3)5 World (net.minecraft.world.World)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 List (java.util.List)4 SpellCastResult (am2.api.spell.enums.SpellCastResult)3 ParticleApproachPoint (am2.particles.ParticleApproachPoint)3 IBlockState (net.minecraft.block.state.IBlockState)3 AMParticle (am2.particles.AMParticle)2 PacketPlayerItem (com.builtbroken.mc.core.network.packet.PacketPlayerItem)2