Skip to content

Commit

Permalink
configuration card & renderering fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushmead committed Jul 30, 2024
1 parent edd3672 commit 00085fa
Show file tree
Hide file tree
Showing 25 changed files with 601 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 1.20.2 2024-07-20T12:53:36.9724263 Item Models: theatrical
// 1.20.2 2024-07-30T19:12:09.649396 Item Models: theatrical
b61dea162dac1064778fccd83e00b34aeea3d2b7 assets/theatrical/models/item/artnet_interface.json
b8f0135bf11be0f31f5d16d76a8c50f28900ee04 assets/theatrical/models/item/basic_lighting_desk.json
545f9e738bfe2c1e7b2236f46042b2504b81373b assets/theatrical/models/item/configuration_card.json
0dc3e30a7627a40ada8a4b8e20249c809067a337 assets/theatrical/models/item/led_fresnel.json
81307d2abd44e288e5e8c9b7824de5a0e895e0be assets/theatrical/models/item/led_panel.json
e6b312509e9a1cfcd5730624d5cbd9f04781d7f7 assets/theatrical/models/item/moving_light.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.2 2024-07-29T23:11:39.1659592 Languages: en_us
51f24e3b8b2d0667dec3cce6b38b13b241264dc8 assets/theatrical/lang/en_us.json
// 1.20.2 2024-07-30T20:12:14.177896 Languages: en_us
dd27ac82d3d3f2c79ab7c9dcfc8cbd0ad314670e assets/theatrical/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
"fixture.dmxStart": "DMX Address",
"fixture.pan": "Pan",
"fixture.tilt": "Tilt",
"item.configurationcard.success": "Configured device to %s network, %s universe, %s address - next address is %s.",
"item.theatrical.configuration_card": "Configuration Card",
"itemGroup.theatrical": "Theatrical",
"screen.artnetconfig.enabled": "ArtNet Enabled: %s",
"screen.artnetconfig.network": "Network",
"screen.configurationcard": "Configuration Card",
"screen.configurationcard.autoincrement": "Address Auto Increment",
"screen.movinglight": "Moving Light",
"ui.control.cue": "Cue - %s",
"ui.control.cues": "Cues",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "theatrical:item/configuration_card"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blockentities.light.BaseLightBlockEntity;
import dev.imabad.theatrical.blocks.light.MovingLightBlock;
import dev.imabad.theatrical.client.LazyRenderers;
import dev.imabad.theatrical.client.blockentities.BasicLightingConsoleRenderer;
import dev.imabad.theatrical.client.blockentities.FresnelRenderer;
import dev.imabad.theatrical.client.blockentities.LEDPanelRenderer;
Expand Down Expand Up @@ -88,6 +89,7 @@ public static void renderWorldLastAfterTripwire(LevelRenderer levelRenderer){

public static void renderWorldLast(PoseStack poseStack, Matrix4f projectionMatrix, Camera camera, float tickDelta){
Minecraft mc = Minecraft.getInstance();
LazyRenderers.doRender(camera,poseStack, mc.renderBuffers().bufferSource(), tickDelta);
if(mc.getDebugOverlay().showDebugScreen()){
Vec3 cameraPos = camera.getPosition();
//#region translateToCamera
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import dev.imabad.theatrical.blockentities.light.LightCollisionContext;
import dev.imabad.theatrical.blocks.HangableBlock;
import dev.imabad.theatrical.dmx.DMXNetworkData;
import dev.imabad.theatrical.items.Items;
import dev.imabad.theatrical.util.UUIDUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -66,4 +71,30 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L
}
}
}
@Override
@Environment(EnvType.CLIENT)
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(player.getItemInHand(hand).getItem() == Items.CONFIGURATION_CARD.get()){
if(!level.isClientSide()) {
ItemStack itemInHand = player.getItemInHand(hand);
CompoundTag tagData = itemInHand.getOrCreateTag();
BlockEntity be = level.getBlockEntity(pos);
if (be instanceof BaseDMXConsumerLightBlockEntity consumerLightBlockEntity) {
consumerLightBlockEntity.setNetworkId(tagData.getUUID("network"));
consumerLightBlockEntity.setUniverse(tagData.getInt("dmxUniverse"));
consumerLightBlockEntity.setChannelStartPoint(tagData.getInt("dmxAddress"));
if (tagData.getBoolean("autoIncrement")) {
tagData.putInt("dmxAddress", tagData.getInt("dmxAddress") + consumerLightBlockEntity.getChannelCount());
}
itemInHand.save(tagData);
DMXNetworkData instance = DMXNetworkData.getInstance(level.getServer().overworld());
player.sendSystemMessage(Component.translatable("item.configurationcard.success", instance.getNetwork(consumerLightBlockEntity.getNetworkId()).name(), Integer.toString(consumerLightBlockEntity.getUniverse()), Integer.toString(consumerLightBlockEntity.getChannelStart()), Integer.toString(tagData.getInt("dmxAddress"))));
return InteractionResult.SUCCESS;
}
} else {
return InteractionResult.SUCCESS;
}
}
return super.use(state, level, pos, player, hand, hit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ public VoxelShape getVisualShape(BlockState state, BlockGetter level, BlockPos p
@Override
@Environment(EnvType.CLIENT)
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(level.isClientSide){
if(player.isCrouching()){
if(TheatricalClient.DEBUG_BLOCKS.contains(pos)){
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
if(super.use(state, level, pos, player, hand, hit) != InteractionResult.SUCCESS) {
if (level.isClientSide) {
if (player.isCrouching()) {
if (TheatricalClient.DEBUG_BLOCKS.contains(pos)) {
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
}
return InteractionResult.SUCCESS;
}
return InteractionResult.SUCCESS;
FresnelBlockEntity be = (FresnelBlockEntity) level.getBlockEntity(pos);
Minecraft.getInstance().setScreen(new FresnelScreen(be));
}
FresnelBlockEntity be = (FresnelBlockEntity)level.getBlockEntity(pos);
Minecraft.getInstance().setScreen(new FresnelScreen(be));
}
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,19 @@ public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPo
@Override
@Environment(EnvType.CLIENT)
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(level.isClientSide){
if(player.isCrouching()){
if(TheatricalClient.DEBUG_BLOCKS.contains(pos)){
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
if(super.use(state, level, pos, player, hand, hit) != InteractionResult.SUCCESS) {
if (level.isClientSide) {
if (player.isCrouching()) {
if (TheatricalClient.DEBUG_BLOCKS.contains(pos)) {
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
}
return InteractionResult.SUCCESS;
}
return InteractionResult.SUCCESS;
LEDPanelBlockEntity be = (LEDPanelBlockEntity) level.getBlockEntity(pos);
Minecraft.getInstance().setScreen(new GenericDMXConfigurationScreen<>(be, pos, "block.theatrical.led_panel"));
}
LEDPanelBlockEntity be = (LEDPanelBlockEntity)level.getBlockEntity(pos);
Minecraft.getInstance().setScreen(new GenericDMXConfigurationScreen<>(be, pos, "block.theatrical.led_panel"));
}
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,19 @@ public VoxelShape getVisualShape(BlockState state, BlockGetter level, BlockPos p
@Override
@Environment(EnvType.CLIENT)
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(level.isClientSide){
if(player.isCrouching()){
if(TheatricalClient.DEBUG_BLOCKS.contains(pos)){
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
if(super.use(state, level, pos, player, hand, hit) != InteractionResult.SUCCESS) {
if (level.isClientSide) {
if (player.isCrouching()) {
if (TheatricalClient.DEBUG_BLOCKS.contains(pos)) {
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
}
return InteractionResult.SUCCESS;
}
return InteractionResult.SUCCESS;
MovingLightBlockEntity be = (MovingLightBlockEntity) level.getBlockEntity(pos);
Minecraft.getInstance().setScreen(new GenericDMXConfigurationScreen<>(be, pos, "block.theatrical.moving_light"));
}
MovingLightBlockEntity be = (MovingLightBlockEntity)level.getBlockEntity(pos);
Minecraft.getInstance().setScreen(new GenericDMXConfigurationScreen<>(be, pos, "block.theatrical.moving_light"));
}
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dev.imabad.theatrical.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.util.Tuple;
import net.minecraft.world.phys.Vec3;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class LazyRenderers {

public static abstract class LazyRenderer {
public abstract void render(MultiBufferSource.BufferSource bufferSource, PoseStack poseStack, Camera camera, float partialTick);
public abstract Vec3 getPos(float partialTick);
}

private static final List<LazyRenderer> renderers = new ArrayList<>();

public static void addLazyRender(LazyRenderer renderer){
renderers.add(renderer);
}

public static void doRender(Camera camera, PoseStack poseStack, MultiBufferSource.BufferSource renderer,float partialTick){
if(!renderers.isEmpty()){
if(renderers.size() == 1){
LazyRenderer first = renderers.get(0);
first.render(renderer, poseStack, camera, partialTick);
} else {
List<Tuple<LazyRenderer, Double>> distanced = new ArrayList<>();
for (LazyRenderer lazyRenderer : renderers) {
distanced.add(new Tuple<>(lazyRenderer, camera.getPosition().distanceToSqr(lazyRenderer.getPos(partialTick))));
}
distanced.sort(Comparator.comparingDouble(t -> -t.getB()));
for (Tuple<LazyRenderer, Double> lazyRendererDoubleTuple : distanced) {
LazyRenderer a = lazyRendererDoubleTuple.getA();
a.render(renderer, poseStack, camera, partialTick);
}
}
renderer.endBatch();
renderers.clear();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ public class TheatricalRenderTypes {
RenderType.CompositeState.builder()
.setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader))
.createCompositeState(false));

public static final RenderType BEAM = RenderType.create(
"TheatricalBeam",
DefaultVertexFormat.POSITION_COLOR,
VertexFormat.Mode.QUADS,
256,
false,
true,
RenderType.translucentState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader))
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import dev.imabad.theatrical.blockentities.light.BaseLightBlockEntity;
import dev.imabad.theatrical.blocks.HangableBlock;
import dev.imabad.theatrical.blocks.light.MovingLightBlock;
import dev.imabad.theatrical.client.LazyRenderers;
import dev.imabad.theatrical.client.TheatricalRenderTypes;
import dev.imabad.theatrical.config.TheatricalConfig;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
Expand Down Expand Up @@ -35,17 +38,34 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB
renderModel(blockEntity, poseStack, vertexConsumer, facing, partialTick, isFlipped, blockState, isHanging, packedLight, packedOverlay);
beforeRenderBeam(blockEntity, poseStack, vertexConsumer, multiBufferSource, facing, partialTick, isFlipped, blockState, isHanging, packedLight, packedOverlay);
if(shouldRenderBeam(blockEntity)){
VertexConsumer beamConsumer = multiBufferSource.getBuffer(RenderType.lightning());
poseStack.translate(blockEntity.getFixture().getBeamStartPosition()[0], blockEntity.getFixture().getBeamStartPosition()[1], blockEntity.getFixture().getBeamStartPosition()[2]);
float intensity = (blockEntity.getPrevIntensity() + ((blockEntity.getIntensity()) - blockEntity.getPrevIntensity()) * partialTick);
int color = blockEntity.calculatePartialColour(partialTick);
renderLightBeam(beamConsumer, poseStack, blockEntity, partialTick, (float) ((intensity * beamOpacity) / 255f), blockEntity.getFixture().getBeamWidth(), (float) blockEntity.getDistance(), color);
LazyRenderers.addLazyRender(new LazyRenderers.LazyRenderer() {
@Override
public void render(MultiBufferSource.BufferSource bufferSource, PoseStack poseStack, Camera camera, float partialTick) {
poseStack.pushPose();
Vec3 offset = Vec3.atLowerCornerOf(blockEntity.getBlockPos()).subtract(camera.getPosition());
poseStack.translate(offset.x, offset.y, offset.z);
preparePoseStack(blockEntity, poseStack, facing, partialTick, isFlipped, blockState, isHanging);
VertexConsumer beamConsumer = bufferSource.getBuffer(TheatricalRenderTypes.BEAM);
poseStack.translate(blockEntity.getFixture().getBeamStartPosition()[0], blockEntity.getFixture().getBeamStartPosition()[1], blockEntity.getFixture().getBeamStartPosition()[2]);
float intensity = (blockEntity.getPrevIntensity() + ((blockEntity.getIntensity()) - blockEntity.getPrevIntensity()) * partialTick);
int color = blockEntity.calculatePartialColour(partialTick);
renderLightBeam(beamConsumer, poseStack, blockEntity, partialTick, (float) ((intensity * beamOpacity) / 255f), blockEntity.getFixture().getBeamWidth(), (float) blockEntity.getDistance(), color);
poseStack.popPose();
}

@Override
public Vec3 getPos(float partialTick) {
return blockEntity.getBlockPos().getCenter();
}
});
}
poseStack.popPose();
}

public abstract void renderModel(T blockEntity, PoseStack poseStack, VertexConsumer vertexConsumer, Direction facing, float partialTicks, boolean isFlipped, BlockState blockState, boolean isHanging, int packedLight, int packedOverlay);

public abstract void preparePoseStack(T blockEntity, PoseStack poseStack, Direction facing, float partialTicks, boolean isFlipped, BlockState blockState, boolean isHanging);

public void beforeRenderBeam(T blockEntity, PoseStack poseStack, VertexConsumer vertexConsumer,
MultiBufferSource multiBufferSource, Direction facing, float partialTicks,
boolean isFlipped, BlockState blockstate, boolean isHanging, int packedLight,
Expand Down Expand Up @@ -89,7 +109,7 @@ protected void renderLightBeam(VertexConsumer builder, PoseStack stack, T tileEn
}

protected void addVertex(VertexConsumer builder, Matrix4f matrix4f, Matrix3f matrix3f, int r, int g, int b, int a, float x, float y, float z) {
builder.vertex(matrix4f, x, y, z).color(r, g, b, a).overlayCoords(OverlayTexture.NO_OVERLAY).normal(matrix3f, 0.0F, 1.0F, 0.0F).endVertex();
builder.vertex(matrix4f, x, y, z).color(r, g, b, a).endVertex();
}

@Override
Expand Down
Loading

0 comments on commit 00085fa

Please sign in to comment.