Search in sources :

Example 1 with ItemStackHandlerIterable

use of me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable in project pnc-repressurized by TeamPneumatic.

the class RenderPressureChamber method render.

@Override
public void render(TileEntityPressureChamberValve te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    List<ItemStack> stacks = new ItemStackHandlerIterable(te.getStacksInChamber()).stream().filter(stack -> !stack.isEmpty()).collect(Collectors.toList());
    if (!stacks.isEmpty()) {
        x += te.multiBlockX - te.getPos().getX() + te.multiBlockSize / 2D;
        // Set to '+ 1' for normal y value.
        y += te.multiBlockY - te.getPos().getY() + 1.1;
        z += te.multiBlockZ - te.getPos().getZ() + te.multiBlockSize / 2D;
        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
        RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
        boolean fancySetting = renderManager.options.fancyGraphics;
        renderManager.options.fancyGraphics = true;
        // render single item centered (looks best), multiple items arranged in a circle
        // around the centre of the chamber, radius dependent on chamber size
        float circleRadius = stacks.size() == 1 ? 0 : 0.33f * (te.multiBlockSize - 2);
        float degreesPerStack = 360f / stacks.size();
        // some gentle rotation and bobbing looks good here
        double ticks = ClientTickHandler.TICKS + partialTicks;
        float yBob = MathHelper.sin(((float) ticks / 10) % 360) * 0.01f;
        float yRot = (float) (ticks / 2) % 360;
        for (int i = 0; i < stacks.size(); i++) {
            GlStateManager.pushMatrix();
            GlStateManager.rotate(i * degreesPerStack, 0, 1, 0);
            GlStateManager.translate(circleRadius, yBob, 0);
            GlStateManager.rotate(yRot, 0, 1, 0);
            Minecraft.getMinecraft().getRenderItem().renderItem(stacks.get(i), ItemCameraTransforms.TransformType.GROUND);
            GlStateManager.popMatrix();
        }
        renderManager.options.fancyGraphics = fancySetting;
        GlStateManager.popMatrix();
    }
}
Also used : ClientTickHandler(me.desht.pneumaticcraft.client.ClientTickHandler) RenderManager(net.minecraft.client.renderer.entity.RenderManager) ItemStack(net.minecraft.item.ItemStack) TileEntityPressureChamberValve(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureChamberValve) List(java.util.List) ItemStackHandlerIterable(me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable) Minecraft(net.minecraft.client.Minecraft) MathHelper(net.minecraft.util.math.MathHelper) GlStateManager(net.minecraft.client.renderer.GlStateManager) TileEntitySpecialRenderer(net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer) ItemCameraTransforms(net.minecraft.client.renderer.block.model.ItemCameraTransforms) Collectors(java.util.stream.Collectors) ItemStackHandlerIterable(me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable) ItemStack(net.minecraft.item.ItemStack) RenderManager(net.minecraft.client.renderer.entity.RenderManager)

Example 2 with ItemStackHandlerIterable

use of me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable in project pnc-repressurized by TeamPneumatic.

the class TileEntityPressureChamberInterface method importFromChamber.

private void importFromChamber(TileEntityPressureChamberValve core) {
    ItemStackHandler chamberStacks = core.getStacksInChamber();
    for (ItemStack chamberStack : new ItemStackHandlerIterable(chamberStacks)) {
        ItemStack inputStack = inventory.getStackInSlot(0);
        if ((inputStack.isEmpty() || inputStack.isItemEqual(chamberStack)) && filterHandler.doesItemMatchFilter(chamberStack)) {
            int maxAllowedItems = Math.abs(core.getAirHandler(null).getAir()) / PneumaticValues.USAGE_CHAMBER_INTERFACE;
            if (maxAllowedItems > 0) {
                if (!inputStack.isEmpty()) {
                    maxAllowedItems = Math.min(maxAllowedItems, chamberStack.getMaxStackSize() - inputStack.getCount());
                }
                int transferredItems = Math.min(chamberStack.getCount(), maxAllowedItems);
                ItemStack toTransferStack = chamberStack.copy().splitStack(transferredItems);
                ItemStack excess = inventory.insertItem(0, toTransferStack, true);
                if (excess.getCount() < toTransferStack.getCount()) {
                    // we can transfer at least some of the items
                    transferredItems = toTransferStack.getCount() - excess.getCount();
                    core.addAir((core.getAirHandler(null).getAir() > 0 ? -1 : 1) * transferredItems * PneumaticValues.USAGE_CHAMBER_INTERFACE);
                    toTransferStack.setCount(transferredItems);
                    inventory.insertItem(0, toTransferStack, false);
                    chamberStack.shrink(transferredItems);
                }
            }
        }
    }
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ItemStackHandlerIterable(me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemStackHandlerIterable

use of me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable in project pnc-repressurized by TeamPneumatic.

the class TileEntityPressureChamberValve method onMultiBlockBreak.

public void onMultiBlockBreak() {
    if (multiBlockSize > 0) {
        Iterator<ItemStack> itemsInChamberIterator = new ItemStackHandlerIterable(itemsInChamber).iterator();
        while (itemsInChamberIterator.hasNext()) {
            ItemStack stack = itemsInChamberIterator.next();
            dropItemOnGround(stack);
            itemsInChamberIterator.remove();
        }
    }
    invalidateMultiBlock();
}
Also used : ItemStackHandlerIterable(me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStackHandlerIterable (me.desht.pneumaticcraft.common.util.ItemStackHandlerIterable)3 ItemStack (net.minecraft.item.ItemStack)3 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ClientTickHandler (me.desht.pneumaticcraft.client.ClientTickHandler)1 TileEntityPressureChamberValve (me.desht.pneumaticcraft.common.tileentity.TileEntityPressureChamberValve)1 Minecraft (net.minecraft.client.Minecraft)1 GlStateManager (net.minecraft.client.renderer.GlStateManager)1 ItemCameraTransforms (net.minecraft.client.renderer.block.model.ItemCameraTransforms)1 RenderManager (net.minecraft.client.renderer.entity.RenderManager)1 TileEntitySpecialRenderer (net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer)1 MathHelper (net.minecraft.util.math.MathHelper)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1