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