Fixed *Sign* rendering
This commit is contained in:
parent
827018078f
commit
abcf90e0bc
2 changed files with 95 additions and 32 deletions
|
@ -1,7 +1,5 @@
|
||||||
package ru.bclib.client.gui;
|
package ru.bclib.client.gui;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.platform.Lighting;
|
import com.mojang.blaze3d.platform.Lighting;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
@ -11,8 +9,8 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.Tesselator;
|
import com.mojang.blaze3d.vertex.Tesselator;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
|
@ -20,22 +18,25 @@ import net.minecraft.client.gui.GuiComponent;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.font.TextFieldHelper;
|
import net.minecraft.client.gui.font.TextFieldHelper;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.client.model.geom.ModelLayers;
|
||||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel;
|
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||||
import net.minecraft.network.chat.CommonComponents;
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket;
|
import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||||
import ru.bclib.blockentities.BaseSignBlockEntity;
|
import ru.bclib.blockentities.BaseSignBlockEntity;
|
||||||
import ru.bclib.blocks.BaseSignBlock;
|
import ru.bclib.blocks.BaseSignBlock;
|
||||||
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
|
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public class BlockSignEditScreen extends Screen {
|
public class BlockSignEditScreen extends Screen {
|
||||||
private final SignModel model = new SignModel();
|
|
||||||
private final BaseSignBlockEntity sign;
|
private final BaseSignBlockEntity sign;
|
||||||
private int ticksSinceOpened;
|
private int ticksSinceOpened;
|
||||||
private int currentRow;
|
private int currentRow;
|
||||||
|
@ -43,6 +44,7 @@ public class BlockSignEditScreen extends Screen {
|
||||||
private final String[] text = (String[]) Util.make(new String[4], (strings) -> {
|
private final String[] text = (String[]) Util.make(new String[4], (strings) -> {
|
||||||
Arrays.fill(strings, "");
|
Arrays.fill(strings, "");
|
||||||
});
|
});
|
||||||
|
private SignRenderer.SignModel model;
|
||||||
|
|
||||||
public BlockSignEditScreen(BaseSignBlockEntity sign) {
|
public BlockSignEditScreen(BaseSignBlockEntity sign) {
|
||||||
super(new TranslatableComponent("sign.edit"));
|
super(new TranslatableComponent("sign.edit"));
|
||||||
|
@ -50,8 +52,11 @@ public class BlockSignEditScreen extends Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
//set up a default model
|
||||||
|
model = new SignRenderer.SignModel(this.minecraft.getEntityModels().bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
|
||||||
|
|
||||||
minecraft.keyboardHandler.setSendRepeatsToGui(true);
|
minecraft.keyboardHandler.setSendRepeatsToGui(true);
|
||||||
this.addButton(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE,
|
this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE,
|
||||||
(buttonWidget) -> {
|
(buttonWidget) -> {
|
||||||
this.finishEditing();
|
this.finishEditing();
|
||||||
}));
|
}));
|
||||||
|
@ -80,7 +85,7 @@ public class BlockSignEditScreen extends Screen {
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
++this.ticksSinceOpened;
|
++this.ticksSinceOpened;
|
||||||
if (!this.sign.getType().isValid(this.sign.getBlockState().getBlock())) {
|
if (!this.sign.getType().isValid(this.sign.getBlockState())) {
|
||||||
this.finishEditing();
|
this.finishEditing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +140,7 @@ public class BlockSignEditScreen extends Screen {
|
||||||
matrices.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
matrices.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||||
MultiBufferSource.BufferSource immediate = minecraft.renderBuffers().bufferSource();
|
MultiBufferSource.BufferSource immediate = minecraft.renderBuffers().bufferSource();
|
||||||
VertexConsumer vertexConsumer = BaseSignBlockEntityRenderer.getConsumer(immediate, blockState.getBlock());
|
VertexConsumer vertexConsumer = BaseSignBlockEntityRenderer.getConsumer(immediate, blockState.getBlock());
|
||||||
model.sign.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY);
|
model.root.getChild("sign").render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY);
|
||||||
|
|
||||||
if (bl) {
|
if (bl) {
|
||||||
model.stick.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY);
|
model.stick.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY);
|
||||||
|
@ -206,7 +211,7 @@ public class BlockSignEditScreen extends Screen {
|
||||||
RenderSystem.disableTexture();
|
RenderSystem.disableTexture();
|
||||||
RenderSystem.enableColorLogicOp();
|
RenderSystem.enableColorLogicOp();
|
||||||
RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE);
|
RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE);
|
||||||
bufferBuilder.begin(7, DefaultVertexFormat.POSITION_COLOR);
|
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||||
float var32 = (float) x;
|
float var32 = (float) x;
|
||||||
bufferBuilder.vertex(matrix4f, var32, (float) (l + 9), 0.0F).color(0, 0, 255, 255).endVertex();
|
bufferBuilder.vertex(matrix4f, var32, (float) (l + 9), 0.0F).color(0, 0, 255, 255).endVertex();
|
||||||
var32 = (float) y;
|
var32 = (float) y;
|
||||||
|
|
|
@ -1,68 +1,84 @@
|
||||||
package ru.bclib.client.render;
|
package ru.bclib.client.render;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.mojang.blaze3d.platform.NativeImage;
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
import com.mojang.math.Vector3f;
|
import com.mojang.math.Vector3f;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.model.geom.ModelLayers;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.client.renderer.Sheets;
|
import net.minecraft.client.renderer.Sheets;
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||||
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||||
import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel;
|
|
||||||
import net.minecraft.client.resources.model.Material;
|
import net.minecraft.client.resources.model.Material;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.FormattedCharSequence;
|
import net.minecraft.util.FormattedCharSequence;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.SignBlock;
|
import net.minecraft.world.level.block.SignBlock;
|
||||||
import net.minecraft.world.level.block.StandingSignBlock;
|
import net.minecraft.world.level.block.StandingSignBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
import ru.bclib.blockentities.BaseSignBlockEntity;
|
import ru.bclib.blockentities.BaseSignBlockEntity;
|
||||||
import ru.bclib.blocks.BaseSignBlock;
|
import ru.bclib.blocks.BaseSignBlock;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSignBlockEntity> {
|
public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSignBlockEntity> {
|
||||||
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
||||||
private static final RenderType defaultLayer;
|
private static final RenderType defaultLayer;
|
||||||
private final SignModel model = new SignRenderer.SignModel();
|
private final Font font;
|
||||||
|
private final SignRenderer.SignModel model;
|
||||||
|
|
||||||
public BaseSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
|
||||||
super(dispatcher);
|
private static final int OUTLINE_RENDER_DISTANCE = Mth.square(16);
|
||||||
|
|
||||||
|
public BaseSignBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) {
|
||||||
|
super();
|
||||||
|
this.font = ctx.getFont();
|
||||||
|
|
||||||
|
//set up a default model
|
||||||
|
model = new SignRenderer.SignModel(ctx.bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(BaseSignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack,
|
public void render(BaseSignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack,
|
||||||
MultiBufferSource provider, int light, int overlay) {
|
MultiBufferSource provider, int light, int overlay) {
|
||||||
BlockState state = signBlockEntity.getBlockState();
|
BlockState state = signBlockEntity.getBlockState();
|
||||||
|
|
||||||
matrixStack.pushPose();
|
matrixStack.pushPose();
|
||||||
|
|
||||||
|
|
||||||
matrixStack.translate(0.5D, 0.5D, 0.5D);
|
matrixStack.translate(0.5D, 0.5D, 0.5D);
|
||||||
float angle = -((float) (state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F);
|
float angle = -((float) (state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F);
|
||||||
|
|
||||||
BlockState blockState = signBlockEntity.getBlockState();
|
BlockState blockState = signBlockEntity.getBlockState();
|
||||||
if (blockState.getValue(BaseSignBlock.FLOOR)) {
|
if (blockState.getValue(BaseSignBlock.FLOOR)) {
|
||||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
|
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
|
||||||
this.model.stick.visible = true;
|
model.stick.visible = true;
|
||||||
} else {
|
} else {
|
||||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
|
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
|
||||||
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
||||||
this.model.stick.visible = false;
|
model.stick.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
matrixStack.pushPose();
|
matrixStack.pushPose();
|
||||||
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||||
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
||||||
model.sign.render(matrixStack, vertexConsumer, light, overlay);
|
|
||||||
model.stick.render(matrixStack, vertexConsumer, light, overlay);
|
model.root.render(matrixStack, vertexConsumer, light, overlay);
|
||||||
|
//model.stick.render(matrixStack, vertexConsumer, light, overlay);
|
||||||
matrixStack.popPose();
|
matrixStack.popPose();
|
||||||
Font textRenderer = renderer.getFont();
|
//Font textRenderer = renderer.getFont();
|
||||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||||
int m = signBlockEntity.getColor().getTextColor();
|
int m = signBlockEntity.getColor().getTextColor();
|
||||||
|
@ -71,21 +87,59 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
|
||||||
int p = (int) (NativeImage.getB(m) * 0.4D);
|
int p = (int) (NativeImage.getB(m) * 0.4D);
|
||||||
int q = NativeImage.combine(0, p, o, n);
|
int q = NativeImage.combine(0, p, o, n);
|
||||||
|
|
||||||
|
FormattedCharSequence[] formattedCharSequences = signBlockEntity
|
||||||
|
.getRenderMessages(Minecraft.getInstance().isTextFilteringEnabled(), (component) -> {
|
||||||
|
List<FormattedCharSequence> list = this.font.split(component, 90);
|
||||||
|
return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0);
|
||||||
|
});
|
||||||
|
int drawColor;
|
||||||
|
boolean drawOutlined;
|
||||||
|
int drawLight;
|
||||||
|
if (signBlockEntity.hasGlowingText()) {
|
||||||
|
drawColor = signBlockEntity.getColor().getTextColor();
|
||||||
|
drawOutlined = isOutlineVisible(signBlockEntity, drawColor);
|
||||||
|
drawLight = 15728880;
|
||||||
|
} else {
|
||||||
|
drawColor = m;
|
||||||
|
drawOutlined = false;
|
||||||
|
drawLight = light;
|
||||||
|
}
|
||||||
|
|
||||||
for (int s = 0; s < 4; ++s) {
|
for (int s = 0; s < 4; ++s) {
|
||||||
FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> {
|
FormattedCharSequence formattedCharSequence = formattedCharSequences[s];
|
||||||
List<FormattedCharSequence> list = textRenderer.split(text, 90);
|
float t = (float) (-this.font.width(formattedCharSequence) / 2);
|
||||||
return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0);
|
if (drawOutlined) {
|
||||||
});
|
this.font.drawInBatch8xOutline(formattedCharSequence, t, (float) (s * 10 - 20), drawColor, m,
|
||||||
if (orderedText != null) {
|
matrixStack.last().pose(), provider, drawLight);
|
||||||
float t = (float) (-textRenderer.width(orderedText) / 2);
|
} else {
|
||||||
textRenderer.drawInBatch(orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light);
|
this.font.drawInBatch((FormattedCharSequence) formattedCharSequence, t, (float) (s * 10 - 20), drawColor, false,
|
||||||
|
matrixStack.last().pose(), provider, false, 0, drawLight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
matrixStack.popPose();
|
matrixStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Material getModelTexture(Block block) {
|
|
||||||
|
|
||||||
|
private static boolean isOutlineVisible(BaseSignBlockEntity signBlockEntity, int i) {
|
||||||
|
if (i == DyeColor.BLACK.getTextColor()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
LocalPlayer localPlayer = minecraft.player;
|
||||||
|
if (localPlayer != null && minecraft.options.getCameraType().isFirstPerson() && localPlayer.isScoping()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Entity entity = minecraft.getCameraEntity();
|
||||||
|
return entity != null && entity.distanceToSqr(
|
||||||
|
Vec3.atCenterOf(signBlockEntity.getBlockPos())) < (double) OUTLINE_RENDER_DISTANCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WoodType getSignType(Block block) {
|
||||||
WoodType signType2;
|
WoodType signType2;
|
||||||
if (block instanceof SignBlock) {
|
if (block instanceof SignBlock) {
|
||||||
signType2 = ((SignBlock) block).type();
|
signType2 = ((SignBlock) block).type();
|
||||||
|
@ -93,7 +147,11 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
|
||||||
signType2 = WoodType.OAK;
|
signType2 = WoodType.OAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Sheets.signTexture(signType2);
|
return signType2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Material getModelTexture(Block block) {
|
||||||
|
return Sheets.getSignMaterial(getSignType(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
|
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue