NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/tiles/render/RenderProjectileGenerator.java

71 lines
3.1 KiB
Java
Raw Normal View History

2019-03-31 23:53:53 +02:00
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.vertex.PoseStack;
2021-12-19 18:47:50 +01:00
import com.mojang.blaze3d.vertex.VertexConsumer;
2023-07-08 12:32:27 +02:00
import com.mojang.math.Axis;
2019-03-31 23:53:53 +02:00
import de.ellpeck.naturesaura.NaturesAura;
2021-12-04 15:40:09 +01:00
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
2021-12-19 18:47:50 +01:00
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.renderer.MultiBufferSource;
2021-12-19 18:47:50 +01:00
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
2021-12-15 16:24:53 +01:00
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
2024-02-03 14:56:07 +01:00
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
2019-03-31 23:53:53 +02:00
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
public class RenderProjectileGenerator implements BlockEntityRenderer<BlockEntityProjectileGenerator> {
2020-01-28 18:08:56 +01:00
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/projectile_generator_overlay.png");
2021-12-19 18:47:50 +01:00
private final ModelOverlay model = new ModelOverlay();
2019-03-31 23:53:53 +02:00
2021-12-15 16:24:53 +01:00
public RenderProjectileGenerator(BlockEntityRendererProvider.Context context) {
}
2019-03-31 23:53:53 +02:00
@Override
public void render(BlockEntityProjectileGenerator te, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
stack.pushPose();
2019-10-20 22:30:49 +02:00
if (te.nextSide == Direction.NORTH) {
2023-07-08 12:32:27 +02:00
stack.mulPose(Axis.YP.rotationDegrees(270));
stack.translate(-0.002F, 0, -1);
2019-10-20 22:30:49 +02:00
} else if (te.nextSide == Direction.EAST) {
2023-07-08 12:32:27 +02:00
stack.mulPose(Axis.YP.rotationDegrees(180));
stack.translate(-1.002F, 0, -1);
2019-10-20 22:30:49 +02:00
} else if (te.nextSide == Direction.SOUTH) {
2023-07-08 12:32:27 +02:00
stack.mulPose(Axis.YP.rotationDegrees(90));
stack.translate(-1.002F, 0, 0);
2019-03-31 23:53:53 +02:00
} else {
stack.translate(-0.002F, 0, 0);
2019-03-31 23:53:53 +02:00
}
2021-12-15 16:30:22 +01:00
var brightness = 15 << 20 | 15 << 4;
2022-06-27 15:24:04 +02:00
this.model.renderToBuffer(stack, buffer.getBuffer(this.model.renderType(RenderProjectileGenerator.RES)), brightness, combinedOverlayIn, 1, 1, 1, 1);
stack.popPose();
2019-03-31 23:53:53 +02:00
}
2021-12-19 18:47:50 +01:00
private static class ModelOverlay extends Model {
2019-03-31 23:53:53 +02:00
2021-12-19 18:47:50 +01:00
private final ModelPart model;
2019-03-31 23:53:53 +02:00
public ModelOverlay() {
super(RenderType::entityTranslucent);
2021-12-19 18:47:50 +01:00
var mesh = new MeshDefinition();
var part = mesh.getRoot();
part.addOrReplaceChild("main", new CubeListBuilder().addBox(0, 0, 0, 16, 16, 16), PartPose.ZERO);
this.model = LayerDefinition.create(mesh, 64, 64).bakeRoot();
2019-03-31 23:53:53 +02:00
}
@Override
2021-12-19 18:47:50 +01:00
public void renderToBuffer(PoseStack matrixStackIn, VertexConsumer bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.model.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
2019-03-31 23:53:53 +02:00
}
2021-12-19 18:47:50 +01:00
}
2019-03-31 23:53:53 +02:00
}