Search in sources :

Example 21 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class ItemDrainRenderer method renderItem.

protected void renderItem(ItemDrainTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    TransportedItemStack transported = te.heldItem;
    if (transported == null)
        return;
    TransformStack msr = TransformStack.cast(ms);
    Vec3 itemPosition = VecHelper.getCenterOf(te.getBlockPos());
    Direction insertedFrom = transported.insertedFrom;
    if (!insertedFrom.getAxis().isHorizontal())
        return;
    ms.pushPose();
    ms.translate(.5f, 15 / 16f, .5f);
    msr.nudge(0);
    float offset = Mth.lerp(partialTicks, transported.prevBeltPosition, transported.beltPosition);
    float sideOffset = Mth.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset);
    Vec3 offsetVec = Vec3.atLowerCornerOf(insertedFrom.getOpposite().getNormal()).scale(.5f - offset);
    ms.translate(offsetVec.x, offsetVec.y, offsetVec.z);
    boolean alongX = insertedFrom.getClockWise().getAxis() == Axis.X;
    if (!alongX)
        sideOffset *= -1;
    ms.translate(alongX ? sideOffset : 0, 0, alongX ? 0 : sideOffset);
    ItemStack itemStack = transported.stack;
    Random r = new Random(0);
    ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
    int count = (int) (Mth.log2((int) (itemStack.getCount()))) / 2;
    boolean renderUpright = BeltHelper.isItemUpright(itemStack);
    boolean blockItem = itemRenderer.getModel(itemStack, null, null, 0).isGui3d();
    if (renderUpright)
        ms.translate(0, 3 / 32d, 0);
    int positive = insertedFrom.getAxisDirection().getStep();
    float verticalAngle = positive * offset * 360;
    if (insertedFrom.getAxis() != Axis.X)
        msr.rotateX(verticalAngle);
    if (insertedFrom.getAxis() != Axis.Z)
        msr.rotateZ(-verticalAngle);
    if (renderUpright) {
        Entity renderViewEntity = Minecraft.getInstance().cameraEntity;
        if (renderViewEntity != null) {
            Vec3 positionVec = renderViewEntity.position();
            Vec3 vectorForOffset = itemPosition.add(offsetVec);
            Vec3 diff = vectorForOffset.subtract(positionVec);
            if (insertedFrom.getAxis() != Axis.X)
                diff = VecHelper.rotate(diff, verticalAngle, Axis.X);
            if (insertedFrom.getAxis() != Axis.Z)
                diff = VecHelper.rotate(diff, -verticalAngle, Axis.Z);
            float yRot = (float) Mth.atan2(diff.z, -diff.x);
            ms.mulPose(Vector3f.YP.rotation((float) (yRot - Math.PI / 2)));
        }
        ms.translate(0, 0, -1 / 16f);
    }
    for (int i = 0; i <= count; i++) {
        ms.pushPose();
        if (blockItem)
            ms.translate(r.nextFloat() * .0625f * i, 0, r.nextFloat() * .0625f * i);
        ms.scale(.5f, .5f, .5f);
        if (!blockItem && !renderUpright)
            msr.rotateX(90);
        itemRenderer.renderStatic(itemStack, TransformType.FIXED, light, overlay, ms, buffer, 0);
        ms.popPose();
        if (!renderUpright) {
            if (!blockItem)
                msr.rotateY(10);
            ms.translate(0, blockItem ? 1 / 64d : 1 / 16d, 0);
        } else
            ms.translate(0, 0, -1 / 16f);
    }
    ms.popPose();
}
Also used : Entity(net.minecraft.world.entity.Entity) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Random(java.util.Random) Vec3(net.minecraft.world.phys.Vec3) ItemRenderer(net.minecraft.client.renderer.entity.ItemRenderer) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Example 22 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class SpoutTileEntity method whenItemHeld.

protected ProcessingResult whenItemHeld(TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler) {
    if (processingTicks != -1 && processingTicks != 5)
        return HOLD;
    if (!FillingBySpout.canItemBeFilled(level, transported.stack))
        return PASS;
    if (tank.isEmpty())
        return HOLD;
    FluidStack fluid = getCurrentFluidInTank();
    int requiredAmountForItem = FillingBySpout.getRequiredAmountForItem(level, transported.stack, fluid.copy());
    if (requiredAmountForItem == -1)
        return PASS;
    if (requiredAmountForItem > fluid.getAmount())
        return HOLD;
    if (processingTicks == -1) {
        processingTicks = FILLING_TIME;
        notifyUpdate();
        return HOLD;
    }
    // Process finished
    ItemStack out = FillingBySpout.fillItem(level, requiredAmountForItem, transported.stack, fluid);
    if (!out.isEmpty()) {
        List<TransportedItemStack> outList = new ArrayList<>();
        TransportedItemStack held = null;
        TransportedItemStack result = transported.copy();
        result.stack = out;
        if (!transported.stack.isEmpty())
            held = transported.copy();
        outList.add(result);
        handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(outList, held));
    }
    AllTriggers.triggerForNearbyPlayers(AllTriggers.SPOUT, level, worldPosition, 5);
    if (out.getItem() instanceof PotionItem && !PotionUtils.getMobEffects(out).isEmpty())
        AllTriggers.triggerForNearbyPlayers(AllTriggers.SPOUT_POTION, level, worldPosition, 5);
    tank.getPrimaryHandler().setFluid(fluid);
    sendSplash = true;
    notifyUpdate();
    return HOLD;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) FluidStack(net.minecraftforge.fluids.FluidStack) PotionItem(net.minecraft.world.item.PotionItem) ArrayList(java.util.ArrayList) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 23 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class DepotBehaviour method tryInsertingFromSide.

private ItemStack tryInsertingFromSide(TransportedItemStack transportedStack, Direction side, boolean simulate) {
    ItemStack inserted = transportedStack.stack;
    if (!getHeldItemStack().isEmpty() && !canMergeItems())
        return inserted;
    if (!isOutputEmpty() && !canMergeItems())
        return inserted;
    if (!canAcceptItems.get())
        return inserted;
    int size = transportedStack.stack.getCount();
    transportedStack = transportedStack.copy();
    transportedStack.beltPosition = side.getAxis().isVertical() ? .5f : 0;
    transportedStack.insertedFrom = side;
    transportedStack.prevSideOffset = transportedStack.sideOffset;
    transportedStack.prevBeltPosition = transportedStack.beltPosition;
    ItemStack remainder = insert(transportedStack, simulate);
    if (remainder.getCount() != size)
        tileEntity.notifyUpdate();
    return remainder;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 24 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class DepotBehaviour method applyToAllItems.

private void applyToAllItems(float maxDistanceFromCentre, Function<TransportedItemStack, TransportedResult> processFunction) {
    if (heldItem == null)
        return;
    if (.5f - heldItem.beltPosition > maxDistanceFromCentre)
        return;
    boolean dirty = false;
    TransportedItemStack transportedItemStack = heldItem;
    ItemStack stackBefore = transportedItemStack.stack.copy();
    TransportedResult result = processFunction.apply(transportedItemStack);
    if (result == null || result.didntChangeFrom(stackBefore))
        return;
    dirty = true;
    heldItem = null;
    if (result.hasHeldOutput())
        setCenteredHeldItem(result.getHeldOutput());
    for (TransportedItemStack added : result.getOutputs()) {
        if (getHeldItemStack().isEmpty()) {
            setCenteredHeldItem(added);
            continue;
        }
        ItemStack remainder = ItemHandlerHelper.insertItemStacked(processingOutputBuffer, added.stack, false);
        Vec3 vec = VecHelper.getCenterOf(tileEntity.getBlockPos());
        Containers.dropItemStack(tileEntity.getLevel(), vec.x, vec.y + .5f, vec.z, remainder);
    }
    if (dirty)
        tileEntity.notifyUpdate();
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Vec3(net.minecraft.world.phys.Vec3) TransportedResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 25 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class DepotBehaviour method getRemainingSpace.

public int getRemainingSpace() {
    int cumulativeStackSize = getPresentStackSize();
    for (TransportedItemStack transportedItemStack : incoming) cumulativeStackSize += transportedItemStack.stack.getCount();
    int fromGetter = maxStackSize.get();
    return (fromGetter == 0 ? 64 : fromGetter) - cumulativeStackSize;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)

Aggregations

TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)26 ItemStack (net.minecraft.world.item.ItemStack)20 BlockState (net.minecraft.world.level.block.state.BlockState)8 Vec3 (net.minecraft.world.phys.Vec3)8 BlockPos (net.minecraft.core.BlockPos)6 Direction (net.minecraft.core.Direction)6 BeltInventory (com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory)3 ProcessingResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult)3 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)3 TransportedResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 Entity (net.minecraft.world.entity.Entity)3 ItemEntity (net.minecraft.world.entity.item.ItemEntity)3 Level (net.minecraft.world.level.Level)3 TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)2 Create (com.simibubi.create.Create)2 InWorldProcessing (com.simibubi.create.content.contraptions.processing.InWorldProcessing)2 BeltHelper (com.simibubi.create.content.contraptions.relays.belt.BeltHelper)2 List (java.util.List)2