2018-11-19 20:18:22 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles.render;
|
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable;
|
2020-01-29 18:18:41 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2020-01-28 18:08:56 +01:00
|
|
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
2020-01-29 18:18:41 +01:00
|
|
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
|
|
|
|
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
|
2020-01-29 18:18:41 +01:00
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.util.math.Mth;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.math.vector.Vector3f;
|
2018-11-19 20:18:22 +01:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
public class RenderOfferingTable extends BlockEntityRenderer<BlockEntityOfferingTable> {
|
2018-11-19 20:18:22 +01:00
|
|
|
|
|
|
|
private final Random rand = new Random();
|
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
public RenderOfferingTable(BlockEntityRendererDispatcher disp) {
|
2020-01-28 18:08:56 +01:00
|
|
|
super(disp);
|
|
|
|
}
|
|
|
|
|
2018-11-19 20:18:22 +01:00
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
|
2020-01-28 18:08:56 +01:00
|
|
|
ItemStack stack = tileEntityOfferingTable.items.getStackInSlot(0);
|
2018-11-19 20:18:22 +01:00
|
|
|
if (!stack.isEmpty()) {
|
2020-01-21 23:02:39 +01:00
|
|
|
this.rand.setSeed(Item.getIdFromItem(stack.getItem()) + stack.getDamage());
|
2018-11-19 20:18:22 +01:00
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
int amount = Mth.ceil(stack.getCount() / 2F);
|
2018-11-19 20:18:22 +01:00
|
|
|
for (int i = 0; i < amount; i++) {
|
2020-01-29 18:18:41 +01:00
|
|
|
matrixStack.push();
|
2018-11-19 20:18:22 +01:00
|
|
|
Item item = stack.getItem();
|
|
|
|
|
|
|
|
float scale;
|
|
|
|
float yOff;
|
2020-01-28 18:08:56 +01:00
|
|
|
if (item instanceof BlockItem) {
|
2020-01-29 18:18:41 +01:00
|
|
|
scale = 0.5F;
|
2018-11-19 20:18:22 +01:00
|
|
|
yOff = 0.08F;
|
|
|
|
} else {
|
2020-01-29 18:18:41 +01:00
|
|
|
scale = 0.35F;
|
2018-11-19 20:18:22 +01:00
|
|
|
yOff = 0F;
|
|
|
|
}
|
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
matrixStack.translate(
|
|
|
|
0.35F + this.rand.nextFloat() * 0.3F,
|
|
|
|
0.9F + yOff + i * 0.001F,
|
|
|
|
0.35F + this.rand.nextFloat() * 0.3F);
|
2020-01-29 18:18:41 +01:00
|
|
|
matrixStack.rotate(Vector3f.YP.rotationDegrees(this.rand.nextFloat() * 360));
|
|
|
|
matrixStack.rotate(Vector3f.XP.rotationDegrees(90F));
|
2020-01-28 18:08:56 +01:00
|
|
|
matrixStack.scale(scale, scale, scale);
|
2018-11-19 20:18:22 +01:00
|
|
|
|
2020-01-29 18:18:41 +01:00
|
|
|
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStack, iRenderTypeBuffer);
|
|
|
|
matrixStack.pop();
|
2018-11-19 20:18:22 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 18:18:41 +01:00
|
|
|
}
|
2018-11-19 20:18:22 +01:00
|
|
|
}
|