2018-11-19 20:18:22 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles.render;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityOfferingTable;
|
2019-10-20 22:30:49 +02:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
2018-11-19 20:18:22 +01:00
|
|
|
import net.minecraft.item.Item;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.item.BlockItem;
|
2018-11-19 20:18:22 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
public class RenderOfferingTable extends TileEntityRenderer<TileEntityOfferingTable> {
|
2018-11-19 20:18:22 +01:00
|
|
|
|
|
|
|
private final Random rand = new Random();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(TileEntityOfferingTable tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
|
|
|
ItemStack stack = tile.items.getStackInSlot(0);
|
|
|
|
if (!stack.isEmpty()) {
|
|
|
|
this.rand.setSeed(Item.getIdFromItem(stack.getItem()) + stack.getMetadata());
|
|
|
|
|
2018-11-21 01:05:50 +01:00
|
|
|
int amount = MathHelper.ceil(stack.getCount() / 2F);
|
2018-11-19 20:18:22 +01:00
|
|
|
for (int i = 0; i < amount; i++) {
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
Item item = stack.getItem();
|
|
|
|
|
|
|
|
float scale;
|
|
|
|
float yOff;
|
2019-10-20 22:30:49 +02:00
|
|
|
if (item instanceof BlockItem && ((BlockItem) item).getBlock().getRenderLayer() == BlockRenderLayer.SOLID) {
|
2018-11-19 20:18:22 +01:00
|
|
|
scale = 0.4F;
|
|
|
|
yOff = 0.08F;
|
|
|
|
} else {
|
|
|
|
scale = 0.25F;
|
|
|
|
yOff = 0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlStateManager.translate(
|
|
|
|
x + 0.35F + this.rand.nextFloat() * 0.3F,
|
|
|
|
y + 0.9F + yOff + (i * 0.001F),
|
|
|
|
z + 0.35F + this.rand.nextFloat() * 0.3F);
|
|
|
|
GlStateManager.rotate(this.rand.nextFloat() * 360F, 0F, 1F, 0F);
|
|
|
|
GlStateManager.rotate(90F, 1F, 0F, 0F);
|
|
|
|
GlStateManager.scale(scale, scale, scale);
|
|
|
|
|
|
|
|
Helper.renderItemInWorld(stack);
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|