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();
}
}
}
}
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--;
}
}
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;
}
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--;
}
}
Aggregations