Search in sources :

Example 1 with TileEntityLogisticalTransporterBase

use of mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase in project Mekanism by mekanism.

the class RenderLogisticalTransporter method render.

@Override
protected void render(TileEntityLogisticalTransporterBase tile, float partialTick, MatrixStack matrix, IRenderTypeBuffer renderer, int light, int overlayLight, IProfiler profiler) {
    LogisticalTransporterBase transporter = tile.getTransmitter();
    Collection<TransporterStack> inTransit = transporter.getTransit();
    BlockPos pos = tile.getBlockPos();
    if (!inTransit.isEmpty()) {
        matrix.pushPose();
        itemRenderer.init(tile.getLevel(), pos);
        float partial = partialTick * transporter.tier.getSpeed();
        Collection<TransporterStack> reducedTransit = getReducedTransit(inTransit);
        for (TransporterStack stack : reducedTransit) {
            float[] stackPos = TransporterUtils.getStackPosition(transporter, stack, partial);
            matrix.pushPose();
            matrix.translate(stackPos[0], stackPos[1], stackPos[2]);
            matrix.scale(0.75F, 0.75F, 0.75F);
            itemRenderer.renderAsStack(matrix, renderer, stack.itemStack);
            matrix.popPose();
            if (stack.color != null) {
                modelBox.render(matrix, renderer, MekanismRenderer.FULL_LIGHT, overlayLight, stackPos[0], stackPos[1], stackPos[2], stack.color);
            }
        }
        matrix.popPose();
    }
    if (transporter instanceof DiversionTransporter) {
        PlayerEntity player = Minecraft.getInstance().player;
        ItemStack itemStack = player.inventory.getSelected();
        if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemConfigurator) {
            BlockRayTraceResult rayTraceResult = MekanismUtils.rayTrace(player);
            if (!rayTraceResult.getType().equals(Type.MISS) && rayTraceResult.getBlockPos().equals(pos)) {
                Direction side = tile.getSideLookingAt(player, rayTraceResult.getDirection());
                matrix.pushPose();
                matrix.scale(0.5F, 0.5F, 0.5F);
                matrix.translate(0.5, 0.5, 0.5);
                MekanismRenderer.renderObject(getOverlayModel((DiversionTransporter) transporter, side), matrix, renderer.getBuffer(Atlases.translucentCullBlockSheet()), MekanismRenderer.getColorARGB(255, 255, 255, 0.8F), MekanismRenderer.FULL_LIGHT, overlayLight, FaceDisplay.FRONT);
                matrix.popPose();
            }
        }
    }
}
Also used : TransporterStack(mekanism.common.content.transporter.TransporterStack) ItemConfigurator(mekanism.common.item.ItemConfigurator) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) LogisticalTransporterBase(mekanism.common.content.network.transmitter.LogisticalTransporterBase) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) DiversionTransporter(mekanism.common.content.network.transmitter.DiversionTransporter) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with TileEntityLogisticalTransporterBase

use of mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase in project Mekanism by mekanism.

the class TileEntityBin method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    addTicks = Math.max(0, addTicks - 1);
    removeTicks = Math.max(0, removeTicks - 1);
    delayTicks = Math.max(0, delayTicks - 1);
    if (delayTicks == 0) {
        if (getActive()) {
            TileEntity tile = WorldUtils.getTileEntity(getLevel(), getBlockPos().below());
            TileTransitRequest request = new TileTransitRequest(this, Direction.DOWN);
            request.addItem(binSlot.getBottomStack(), 0);
            TransitResponse response;
            if (tile instanceof TileEntityLogisticalTransporterBase) {
                response = ((TileEntityLogisticalTransporterBase) tile).getTransmitter().insert(this, request, null, true, 0);
            } else {
                response = request.addToInventory(tile, Direction.DOWN, 0, false);
            }
            if (!response.isEmpty() && tier != BinTier.CREATIVE) {
                int sendingAmount = response.getSendingAmount();
                MekanismUtils.logMismatchedStackSize(binSlot.shrinkStack(sendingAmount, Action.EXECUTE), sendingAmount);
            }
            delayTicks = 10;
        }
    } else {
        delayTicks--;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) TileTransitRequest(mekanism.common.lib.inventory.TileTransitRequest) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase)

Example 3 with TileEntityLogisticalTransporterBase

use of mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase in project Mekanism by mekanism.

the class TileComponentEjector method outputItems.

/**
 * @apiNote Ensure that it can eject before calling this method.
 */
private void outputItems(ConfigInfo info) {
    for (DataType dataType : info.getSupportedDataTypes()) {
        if (!dataType.canOutput()) {
            continue;
        }
        ISlotInfo slotInfo = info.getSlotInfo(dataType);
        if (slotInfo instanceof InventorySlotInfo) {
            // Validate the slot info is of the correct type
            Set<Direction> outputs = info.getSidesForData(dataType);
            if (!outputs.isEmpty()) {
                EjectTransitRequest ejectMap = InventoryUtils.getEjectItemMap(new EjectTransitRequest(tile, outputs.iterator().next()), ((InventorySlotInfo) slotInfo).getSlots());
                if (!ejectMap.isEmpty()) {
                    for (Direction side : outputs) {
                        TileEntity target = WorldUtils.getTileEntity(tile.getLevel(), tile.getBlockPos().relative(side));
                        if (target != null) {
                            // Update the side so that if/when the response uses it, it makes sure it is grabbing from the correct side
                            ejectMap.side = side;
                            // If the spot is not loaded just skip trying to eject to it
                            TransitResponse response;
                            if (target instanceof TileEntityLogisticalTransporterBase) {
                                response = ((TileEntityLogisticalTransporterBase) target).getTransmitter().insert(tile, ejectMap, outputColor, true, 0);
                            } else {
                                response = ejectMap.addToInventory(target, side, 0, false);
                            }
                            if (!response.isEmpty()) {
                                // use the items returned by the TransitResponse; will be visible next loop
                                response.useAll();
                                if (ejectMap.isEmpty()) {
                                    // If we are out of items to eject, break
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    tickDelay = 10;
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) TileEntity(net.minecraft.tileentity.TileEntity) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) DataType(mekanism.common.tile.component.config.DataType) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) Direction(net.minecraft.util.Direction) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase)

Example 4 with TileEntityLogisticalTransporterBase

use of mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase in project Mekanism by mekanism.

the class TileEntityDigitalMiner method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    closeInvalidScreens();
    if (!initCalc) {
        // reset it and start running again if needed. This happens after saving the miner to disk
        if (searcher.state == State.FINISHED) {
            boolean prevRunning = running;
            reset();
            start();
            running = prevRunning;
        }
        initCalc = true;
    }
    energySlot.fillContainerOrConvert();
    if (MekanismUtils.canFunction(this) && running && searcher.state == State.FINISHED && !oresToMine.isEmpty()) {
        FloatingLong energyPerTick = energyContainer.getEnergyPerTick();
        if (energyContainer.extract(energyPerTick, Action.SIMULATE, AutomationType.INTERNAL).equals(energyPerTick)) {
            setActive(true);
            if (delay > 0) {
                delay--;
            }
            energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
            if (delay == 0) {
                tryMineBlock();
                delay = getDelay();
            }
        } else {
            setActive(false);
        }
    } else {
        setActive(false);
    }
    if (doEject && delayTicks == 0) {
        Direction oppositeDirection = getOppositeDirection();
        TileEntity ejectInv = WorldUtils.getTileEntity(level, getBlockPos().above().relative(oppositeDirection, 2));
        TileEntity ejectTile = WorldUtils.getTileEntity(getLevel(), getBlockPos().above().relative(oppositeDirection));
        if (ejectInv != null && ejectTile != null) {
            TransitRequest ejectMap = InventoryUtils.getEjectItemMap(ejectTile, oppositeDirection, mainSlots);
            if (!ejectMap.isEmpty()) {
                TransitResponse response;
                if (ejectInv instanceof TileEntityLogisticalTransporterBase) {
                    response = ((TileEntityLogisticalTransporterBase) ejectInv).getTransmitter().insert(ejectTile, ejectMap, null, true, 0);
                } else {
                    response = ejectMap.addToInventory(ejectInv, oppositeDirection, 0, false);
                }
                if (!response.isEmpty()) {
                    response.useAll();
                }
            }
            delayTicks = 10;
        }
    } else if (delayTicks > 0) {
        delayTicks--;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FloatingLong(mekanism.api.math.FloatingLong) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) Direction(net.minecraft.util.Direction) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) TransitRequest(mekanism.common.lib.inventory.TransitRequest)

Aggregations

TileEntityLogisticalTransporterBase (mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase)4 TransitResponse (mekanism.common.lib.inventory.TransitRequest.TransitResponse)3 TileEntity (net.minecraft.tileentity.TileEntity)3 Direction (net.minecraft.util.Direction)3 FloatingLong (mekanism.api.math.FloatingLong)1 DiversionTransporter (mekanism.common.content.network.transmitter.DiversionTransporter)1 LogisticalTransporterBase (mekanism.common.content.network.transmitter.LogisticalTransporterBase)1 TransporterStack (mekanism.common.content.transporter.TransporterStack)1 ItemConfigurator (mekanism.common.item.ItemConfigurator)1 TileTransitRequest (mekanism.common.lib.inventory.TileTransitRequest)1 TransitRequest (mekanism.common.lib.inventory.TransitRequest)1 DataType (mekanism.common.tile.component.config.DataType)1 ISlotInfo (mekanism.common.tile.component.config.slot.ISlotInfo)1 InventorySlotInfo (mekanism.common.tile.component.config.slot.InventorySlotInfo)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)1