Fixed structure features and code style

This commit is contained in:
paulevsGitch 2021-07-10 16:07:44 +03:00
parent d431f2555c
commit 5a9365e2bb
153 changed files with 2304 additions and 2459 deletions

View file

@ -45,109 +45,108 @@ public class BlockSignEditScreen extends Screen {
Arrays.fill(strings, "");
});
private SignRenderer.SignModel model;
public BlockSignEditScreen(BaseSignBlockEntity sign) {
super(new TranslatableComponent("sign.edit"));
this.sign = sign;
}
protected void init() {
//set up a default model
model = new SignRenderer.SignModel(this.minecraft.getEntityModels().bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
minecraft.keyboardHandler.setSendRepeatsToGui(true);
this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE,
(buttonWidget) -> {
this.finishEditing();
}));
this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, (buttonWidget) -> {
this.finishEditing();
}));
this.sign.setEditable(false);
this.selectionManager = new TextFieldHelper(() -> {
return this.text[this.currentRow];
}, (string) -> {
this.text[this.currentRow] = string;
this.sign.setMessage(this.currentRow, new TextComponent(string));
}, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft),
(string) -> {
return this.minecraft.font.width(string) <= 90;
});
}, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), (string) -> {
return this.minecraft.font.width(string) <= 90;
});
}
public void removed() {
minecraft.keyboardHandler.setSendRepeatsToGui(false);
ClientPacketListener clientPlayNetworkHandler = this.minecraft.getConnection();
if (clientPlayNetworkHandler != null) {
clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1],
this.text[2], this.text[3]));
clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], this.text[2], this.text[3]));
}
this.sign.setEditable(true);
}
public void tick() {
++this.ticksSinceOpened;
if (!this.sign.getType().isValid(this.sign.getBlockState())) {
this.finishEditing();
}
}
private void finishEditing() {
this.sign.setChanged();
this.minecraft.setScreen((Screen) null);
}
public boolean charTyped(char chr, int keyCode) {
this.selectionManager.charTyped(chr);
return true;
}
public void onClose() {
this.finishEditing();
}
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 265) {
this.currentRow = this.currentRow - 1 & 3;
this.selectionManager.setCursorToEnd();
return true;
} else if (keyCode != 264 && keyCode != 257 && keyCode != 335) {
}
else if (keyCode != 264 && keyCode != 257 && keyCode != 335) {
return selectionManager.keyPressed(keyCode) || super.keyPressed(keyCode, scanCode, modifiers);
} else {
}
else {
this.currentRow = this.currentRow + 1 & 3;
this.selectionManager.setCursorToEnd();
return true;
}
}
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
Lighting.setupForFlatItems();
this.renderBackground(matrices);
GuiComponent.drawCenteredString(matrices, this.font, this.title, this.width / 2, 40, 16777215);
matrices.pushPose();
matrices.translate((double) (this.width / 2), 0.0D, 50.0D);
matrices.scale(93.75F, -93.75F, 93.75F);
matrices.translate(0.0D, -1.3125D, 0.0D);
BlockState blockState = this.sign.getBlockState();
boolean bl = blockState.getValue(BaseSignBlock.FLOOR);
if (!bl) {
matrices.translate(0.0D, -0.3125D, 0.0D);
}
boolean bl2 = this.ticksSinceOpened / 6 % 2 == 0;
matrices.pushPose();
matrices.scale(0.6666667F, -0.6666667F, -0.6666667F);
MultiBufferSource.BufferSource immediate = minecraft.renderBuffers().bufferSource();
VertexConsumer vertexConsumer = BaseSignBlockEntityRenderer.getConsumer(immediate, blockState.getBlock());
model.root.getChild("sign").render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY);
if (bl) {
model.stick.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY);
}
matrices.popPose();
matrices.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
matrices.scale(0.010416667F, -0.010416667F, 0.010416667F);
int i = this.sign.getColor().getTextColor();
@ -155,7 +154,7 @@ public class BlockSignEditScreen extends Screen {
int k = this.selectionManager.getSelectionPos();
int l = this.currentRow * 10 - this.text.length * 5;
Matrix4f matrix4f = matrices.last().pose();
int m;
String string2;
int s;
@ -166,29 +165,25 @@ public class BlockSignEditScreen extends Screen {
if (this.font.isBidirectional()) {
string2 = this.font.bidirectionalShaping(string2);
}
float n = (float) (-this.minecraft.font.width(string2) / 2);
this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f,
immediate, false, 0, 15728880, false);
this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, immediate, false, 0, 15728880, false);
if (m == this.currentRow && j >= 0 && bl2) {
s = this.minecraft.font
.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
s = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
t = s - this.minecraft.font.width(string2) / 2;
if (j >= string2.length()) {
this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false,
0, 15728880, false);
this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, 0, 15728880, false);
}
}
}
}
immediate.endBatch();
for (m = 0; m < this.text.length; ++m) {
string2 = this.text[m];
if (string2 != null && m == this.currentRow && j >= 0) {
int r = this.minecraft.font
.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
int r = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
s = r - this.minecraft.font.width(string2) / 2;
if (bl2 && j < string2.length()) {
int var31 = l - 1;
@ -196,14 +191,12 @@ public class BlockSignEditScreen extends Screen {
this.minecraft.font.getClass();
fill(matrices, s, var31, var10003, l + 9, -16777216 | i);
}
if (k != j) {
t = Math.min(j, k);
int u = Math.max(j, k);
int v = this.minecraft.font.width(string2.substring(0, t))
- this.minecraft.font.width(string2) / 2;
int w = this.minecraft.font.width(string2.substring(0, u))
- this.minecraft.font.width(string2) / 2;
int v = this.minecraft.font.width(string2.substring(0, t)) - this.minecraft.font.width(string2) / 2;
int w = this.minecraft.font.width(string2.substring(0, u)) - this.minecraft.font.width(string2) / 2;
int x = Math.min(v, w);
int y = Math.max(v, w);
Tesselator tessellator = Tesselator.getInstance();
@ -225,7 +218,7 @@ public class BlockSignEditScreen extends Screen {
}
}
}
matrices.popPose();
Lighting.setupFor3DItems();
super.render(matrices, mouseX, mouseY, delta);