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

@ -23,10 +23,8 @@ public class BCLibClient implements ClientModInitializer {
Registry.BLOCK.forEach(block -> {
if (block instanceof IRenderTyped) {
BCLRenderLayer layer = ((IRenderTyped) block).getRenderLayer();
if (layer == BCLRenderLayer.CUTOUT)
BlockRenderLayerMap.INSTANCE.putBlock(block, cutout);
else if (layer == BCLRenderLayer.TRANSLUCENT)
BlockRenderLayerMap.INSTANCE.putBlock(block, translucent);
if (layer == BCLRenderLayer.CUTOUT) BlockRenderLayerMap.INSTANCE.putBlock(block, cutout);
else if (layer == BCLRenderLayer.TRANSLUCENT) BlockRenderLayerMap.INSTANCE.putBlock(block, translucent);
}
});
}

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);

View file

@ -2,90 +2,67 @@ package ru.bclib.client.models;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.model.geom.builders.CubeDeformation;
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.model.geom.builders.PartDefinition;
public class BaseChestBlockModel {
public final ModelPart partA;
public final ModelPart partC;
public final ModelPart partB;
public final ModelPart partRightA;
public final ModelPart partRightC;
public final ModelPart partRightB;
public final ModelPart partLeftA;
public final ModelPart partLeftC;
public final ModelPart partLeftB;
public static LayerDefinition getTexturedModelData() {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
CubeDeformation deformation_partC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partC", CubeListBuilder.create()
.texOffs(0, 19)
.addBox(1.0f, 0.0f, 1.0f, 14.0f, 9.0f, 14.0f, deformation_partC),
PartPose.ZERO);
CubeDeformation deformation_partA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partA", CubeListBuilder.create()
.texOffs(0, 0)
.addBox(1.0f, 0.0f, 0.0f, 14.0f, 5.0f, 14.0f, deformation_partA),
PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partB", CubeListBuilder.create()
.texOffs(0, 0)
.addBox(7.0f, -1.0f, 15.0f, 2.0f, 4.0f, 1.0f, deformation_partB),
PartPose.offset(0.0f, 8.0f, 0.0f));
CubeDeformation deformation_partRightC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightC", CubeListBuilder.create()
.texOffs(0, 19)
.addBox(1.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partRightC),
PartPose.ZERO);
CubeDeformation deformation_partRightA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightA", CubeListBuilder.create()
.texOffs(0, 0)
.addBox(1.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partRightA),
PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partRightB = new CubeDeformation(0.0f);
PartDefinition partRightB = modelPartData.addOrReplaceChild("partRightB", CubeListBuilder.create()
.texOffs(0, 0)
.addBox(15.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partRightB),
PartPose.offset(0.0f, 8.0f, 0.0f));
CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftC", CubeListBuilder.create()
.texOffs(0, 19)
.addBox(0.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partLeftC),
PartPose.ZERO);
CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftA", CubeListBuilder.create()
.texOffs(0, 0)
.addBox(0.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partLeftA),
PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftB", CubeListBuilder.create()
.texOffs(0, 0)
.addBox(0.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partLeftB),
PartPose.offset(0.0f, 8.0f, 0.0f));
return LayerDefinition.create(modelData, 64, 64);
}
public BaseChestBlockModel(ModelPart modelPart) {
super();
partC = modelPart.getChild("partC");
partA = modelPart.getChild("partA");
partB = modelPart.getChild("partB");
partRightC = modelPart.getChild("partRightC");
partRightA = modelPart.getChild("partRightA");
partRightB = modelPart.getChild("partRightB");
partLeftC = modelPart.getChild("partLeftC");
partLeftA = modelPart.getChild("partLeftA");
partLeftB = modelPart.getChild("partLeftB");
}
public final ModelPart partA;
public final ModelPart partC;
public final ModelPart partB;
public final ModelPart partRightA;
public final ModelPart partRightC;
public final ModelPart partRightB;
public final ModelPart partLeftA;
public final ModelPart partLeftC;
public final ModelPart partLeftB;
public static LayerDefinition getTexturedModelData() {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
CubeDeformation deformation_partC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partC", CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 14.0f, 9.0f, 14.0f, deformation_partC), PartPose.ZERO);
CubeDeformation deformation_partA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partA", CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 14.0f, 5.0f, 14.0f, deformation_partA), PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partB", CubeListBuilder.create().texOffs(0, 0).addBox(7.0f, -1.0f, 15.0f, 2.0f, 4.0f, 1.0f, deformation_partB), PartPose.offset(0.0f, 8.0f, 0.0f));
CubeDeformation deformation_partRightC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightC", CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partRightC), PartPose.ZERO);
CubeDeformation deformation_partRightA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightA", CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partRightA), PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partRightB = new CubeDeformation(0.0f);
PartDefinition partRightB = modelPartData.addOrReplaceChild("partRightB", CubeListBuilder.create().texOffs(0, 0).addBox(15.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partRightB), PartPose.offset(0.0f, 8.0f, 0.0f));
CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftC", CubeListBuilder.create().texOffs(0, 19).addBox(0.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partLeftC), PartPose.ZERO);
CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftA", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partLeftA), PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftB", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partLeftB), PartPose.offset(0.0f, 8.0f, 0.0f));
return LayerDefinition.create(modelData, 64, 64);
}
public BaseChestBlockModel(ModelPart modelPart) {
super();
partC = modelPart.getChild("partC");
partA = modelPart.getChild("partA");
partB = modelPart.getChild("partB");
partRightC = modelPart.getChild("partRightC");
partRightA = modelPart.getChild("partRightA");
partRightB = modelPart.getChild("partRightB");
partLeftC = modelPart.getChild("partLeftC");
partLeftA = modelPart.getChild("partLeftA");
partLeftB = modelPart.getChild("partLeftB");
}
}

View file

@ -57,5 +57,5 @@ public class BasePatterns {
public final static ResourceLocation ITEM_GENERATED = BCLib.makeID("patterns/item/pattern_item_generated.json");
public final static ResourceLocation ITEM_HANDHELD = BCLib.makeID("patterns/item/pattern_item_handheld.json");
public final static ResourceLocation ITEM_SPAWN_EGG = BCLib.makeID("patterns/item/pattern_item_spawn_egg.json");
}

View file

@ -1,34 +1,33 @@
package ru.bclib.client.models;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.bclib.BCLib;
import java.util.Map;
import java.util.Optional;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
public interface BlockModelProvider extends ItemModelProvider {
@Environment(EnvType.CLIENT)
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Optional<String> pattern = PatternsHelper.createBlockSimple(resourceLocation);
return ModelsHelper.fromPattern(pattern);
}
@Environment(EnvType.CLIENT)
default UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId);
}
@Environment(EnvType.CLIENT)
default void registerBlockModel(ResourceLocation stateId, ResourceLocation modelId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
if (!modelCache.containsKey(modelId)) {
@ -36,7 +35,8 @@ public interface BlockModelProvider extends ItemModelProvider {
if (model != null) {
model.name = modelId.toString();
modelCache.put(modelId, model);
} else {
}
else {
BCLib.LOGGER.warning("Error loading model: {}", modelId);
modelCache.put(modelId, modelCache.get(MISSING_MODEL_LOCATION));
}

View file

@ -1,12 +1,7 @@
package ru.bclib.client.models;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import com.google.common.collect.Lists;
import com.mojang.math.Transformation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
@ -22,39 +17,43 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@Environment(EnvType.CLIENT)
public class ModelsHelper {
public static BlockModel fromPattern(Optional<String> pattern) {
return pattern.map(BlockModel::fromString).orElse(null);
}
public static BlockModel createItemModel(ResourceLocation resourceLocation) {
return fromPattern(PatternsHelper.createItemGenerated(resourceLocation));
}
public static BlockModel createHandheldItem(ResourceLocation resourceLocation) {
return fromPattern(PatternsHelper.createItemHandheld(resourceLocation));
}
public static BlockModel createBlockItem(ResourceLocation resourceLocation) {
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.ITEM_BLOCK, resourceLocation);
return fromPattern(pattern);
}
public static BlockModel createBlockEmpty(ResourceLocation resourceLocation) {
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_EMPTY, resourceLocation);
return fromPattern(pattern);
}
public static MultiVariant createMultiVariant(ResourceLocation resourceLocation, Transformation transform, boolean uvLock) {
Variant variant = new Variant(resourceLocation, transform, uvLock, 1);
return new MultiVariant(Lists.newArrayList(variant));
}
public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) {
return createMultiVariant(resourceLocation, Transformation.identity(), false);
}
public static MultiVariant createFacingModel(ResourceLocation resourceLocation, Direction facing, boolean uvLock, boolean inverted) {
if (inverted) {
facing = facing.getOpposite();
@ -62,45 +61,45 @@ public class ModelsHelper {
BlockModelRotation rotation = BlockModelRotation.by(0, (int) facing.toYRot());
return createMultiVariant(resourceLocation, rotation.getRotation(), uvLock);
}
public static MultiVariant createRotatedModel(ResourceLocation resourceLocation, Direction.Axis axis) {
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (axis) {
case X: rotation = BlockModelRotation.X90_Y90; break;
case Z: rotation = BlockModelRotation.X90_Y0; break;
default: break;
case X:
rotation = BlockModelRotation.X90_Y90;
break;
case Z:
rotation = BlockModelRotation.X90_Y0;
break;
default:
break;
}
return createMultiVariant(resourceLocation, rotation.getRotation(), false);
}
public static MultiVariant createRandomTopModel(ResourceLocation resourceLocation) {
return new MultiVariant(Lists.newArrayList(
new Variant(resourceLocation, Transformation.identity(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)
));
return new MultiVariant(Lists.newArrayList(new Variant(resourceLocation, Transformation.identity(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)));
}
public static class MultiPartBuilder {
private final static MultiPartBuilder BUILDER = new MultiPartBuilder();
public static MultiPartBuilder create(StateDefinition<Block, BlockState> stateDefinition) {
BUILDER.stateDefinition = stateDefinition;
BUILDER.modelParts.clear();
return BUILDER;
}
private final List<ModelPart> modelParts = Lists.newArrayList();
private StateDefinition<Block, BlockState> stateDefinition;
private MultiPartBuilder() {}
public ModelPart part(ResourceLocation modelId) {
return new ModelPart(modelId);
}
public MultiPart build() {
if (modelParts.size() > 0) {
List<Selector> selectors = Lists.newArrayList();
@ -113,32 +112,32 @@ public class ModelsHelper {
}
throw new IllegalStateException("At least one model part need to be created.");
}
public class ModelPart {
private final ResourceLocation modelId;
private Transformation transform = Transformation.identity();
private Condition condition = Condition.TRUE;
private boolean uvLock = false;
private ModelPart(ResourceLocation modelId) {
this.modelId = modelId;
}
public ModelPart setCondition(Function<BlockState, Boolean> condition) {
this.condition = stateDefinition -> condition::apply;
return this;
}
public ModelPart setTransformation(Transformation transform) {
this.transform = transform;
return this;
}
public ModelPart setUVLock(boolean value) {
this.uvLock = value;
return this;
}
public void add() {
modelParts.add(this);
}

View file

@ -1,5 +1,10 @@
package ru.bclib.client.models;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -8,58 +13,52 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
public class PatternsHelper {
public static Optional<String> createItemGenerated(ResourceLocation itemId) {
return createJson(BasePatterns.ITEM_GENERATED, itemId);
}
public static Optional<String> createItemHandheld(ResourceLocation itemId) {
return createJson(BasePatterns.ITEM_HANDHELD, itemId);
}
public static Optional<String> createBlockSimple(ResourceLocation blockId) {
return createJson(BasePatterns.BLOCK_BASE, blockId);
}
public static Optional<String> createBlockEmpty(ResourceLocation blockId) {
return createJson(BasePatterns.BLOCK_EMPTY, blockId);
}
public static Optional<String> createBlockPillar(ResourceLocation blockId) {
return createJson(BasePatterns.BLOCK_PILLAR, blockId);
}
public static Optional<String> createBlockBottomTop(ResourceLocation blockId) {
return createJson(BasePatterns.BLOCK_BOTTOM_TOP, blockId);
}
public static Optional<String> createBlockColored(ResourceLocation blockId) {
return createJson(BasePatterns.BLOCK_COLORED, blockId);
}
public static Optional<String> createJson(ResourceLocation patternId, ResourceLocation blockId) {
Map<String, String> textures = Maps.newHashMap();
textures.put("%modid%", blockId.getNamespace());
textures.put("%texture%", blockId.getPath());
return createJson(patternId, textures);
}
public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines().collect(Collectors.joining());
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining());
for (Map.Entry<String, String> texture : textures.entrySet()) {
json = json.replace(texture.getKey(), texture.getValue());
}
return Optional.of(json);
} catch (Exception ex) {
}
catch (Exception ex) {
return Optional.empty();
}
}

View file

@ -1,6 +1,5 @@
package ru.bclib.client.render;
public enum BCLRenderLayer {
CUTOUT,
TRANSLUCENT;
CUTOUT, TRANSLUCENT;
}

View file

@ -18,7 +18,11 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.AbstractChestBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
@ -32,17 +36,18 @@ import java.util.HashMap;
public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChestBlockEntity> {
private static final HashMap<Block, RenderType[]> LAYERS = Maps.newHashMap();
private static final RenderType[] defaultLayer;
private static final int ID_NORMAL = 0;
private static final int ID_LEFT = 1;
private static final int ID_RIGHT = 2;
private final BaseChestBlockModel chestModel;
public BaseChestBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) {
super();
chestModel = new BaseChestBlockModel(BaseChestBlockModel.getTexturedModelData().bakeRoot());
}
public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
Level world = entity.getLevel();
boolean worldExists = world != null;
@ -54,40 +59,42 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
boolean isDouble = chestType != ChestType.SINGLE;
float f = ((Direction) blockState.getValue(ChestBlock.FACING)).toYRot();
NeighborCombineResult<? extends ChestBlockEntity> propertySource;
matrices.pushPose();
matrices.translate(0.5D, 0.5D, 0.5D);
matrices.mulPose(Vector3f.YP.rotationDegrees(-f));
matrices.translate(-0.5D, -0.5D, -0.5D);
if (worldExists) {
propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true);
} else {
}
else {
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
}
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(tickDelta);
pitch = 1.0F - pitch;
pitch = 1.0F - pitch * pitch * pitch;
@SuppressWarnings({ "unchecked", "rawtypes" })
int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
@SuppressWarnings({"unchecked", "rawtypes"}) int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
if (isDouble) {
if (chestType == ChestType.LEFT) {
renderParts(matrices, vertexConsumer, chestModel.partLeftA, chestModel.partLeftB, chestModel.partLeftC, pitch, blockLight, overlay);
} else {
}
else {
renderParts(matrices, vertexConsumer, chestModel.partRightA, chestModel.partRightB, chestModel.partRightC, pitch, blockLight, overlay);
}
} else {
}
else {
renderParts(matrices, vertexConsumer, chestModel.partA, chestModel.partB, chestModel.partC, pitch, blockLight, overlay);
}
matrices.popPose();
}
}
private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) {
modelPart.xRot = -(pitch * 1.5707964F);
modelPart2.xRot = modelPart.xRot;
@ -95,7 +102,7 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
modelPart2.render(matrices, vertices, light, overlay);
modelPart3.render(matrices, vertices, light, overlay);
}
private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
return switch (type) {
case LEFT -> layers[ID_LEFT];
@ -103,28 +110,20 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
default -> layers[ID_NORMAL];
};
}
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) {
RenderType[] layers = LAYERS.getOrDefault(block, defaultLayer);
return provider.getBuffer(getChestTexture(chestType, layers));
}
public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block);
String modId = blockId.getNamespace();
String path = blockId.getPath();
LAYERS.put(block, new RenderType[] {
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + ".png")),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_left.png")),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))
});
LAYERS.put(block, new RenderType[] {RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + ".png")), RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_left.png")), RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))});
}
static {
defaultLayer = new RenderType[] {
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))
};
defaultLayer = new RenderType[] {RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")), RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")), RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))};
}
}

View file

@ -39,42 +39,42 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
private static final RenderType defaultLayer;
private final Font font;
private final SignRenderer.SignModel model;
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,
MultiBufferSource provider, int light, int overlay) {
public void render(BaseSignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack, MultiBufferSource provider, int light, int overlay) {
BlockState state = signBlockEntity.getBlockState();
matrixStack.pushPose();
matrixStack.translate(0.5D, 0.5D, 0.5D);
float angle = -((float) (state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F);
BlockState blockState = signBlockEntity.getBlockState();
if (blockState.getValue(BaseSignBlock.FLOOR)) {
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
model.stick.visible = true;
} else {
}
else {
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
model.stick.visible = false;
}
matrixStack.pushPose();
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
model.root.render(matrixStack, vertexConsumer, light, overlay);
//model.stick.render(matrixStack, vertexConsumer, light, overlay);
matrixStack.popPose();
@ -86,12 +86,11 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
int o = (int) (NativeImage.getG(m) * 0.4D);
int p = (int) (NativeImage.getB(m) * 0.4D);
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);
});
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;
@ -99,57 +98,58 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
drawColor = signBlockEntity.getColor().getTextColor();
drawOutlined = isOutlineVisible(signBlockEntity, drawColor);
drawLight = 15728880;
} else {
}
else {
drawColor = m;
drawOutlined = false;
drawLight = light;
}
for (int s = 0; s < 4; ++s) {
FormattedCharSequence formattedCharSequence = formattedCharSequences[s];
float t = (float) (-this.font.width(formattedCharSequence) / 2);
if (drawOutlined) {
this.font.drawInBatch8xOutline(formattedCharSequence, t, (float) (s * 10 - 20), drawColor, m,
matrixStack.last().pose(), provider, drawLight);
} else {
this.font.drawInBatch((FormattedCharSequence) formattedCharSequence, t, (float) (s * 10 - 20), drawColor, false,
matrixStack.last().pose(), provider, false, 0, drawLight);
this.font.drawInBatch8xOutline(formattedCharSequence, t, (float) (s * 10 - 20), drawColor, m, matrixStack.last().pose(), provider, drawLight);
}
else {
this.font.drawInBatch((FormattedCharSequence) formattedCharSequence, t, (float) (s * 10 - 20), drawColor, false, matrixStack.last().pose(), provider, false, 0, drawLight);
}
}
matrixStack.popPose();
}
private static boolean isOutlineVisible(BaseSignBlockEntity signBlockEntity, int i) {
if (i == DyeColor.BLACK.getTextColor()) {
return true;
} else {
}
else {
Minecraft minecraft = Minecraft.getInstance();
LocalPlayer localPlayer = minecraft.player;
if (localPlayer != null && minecraft.options.getCameraType().isFirstPerson() && localPlayer.isScoping()) {
return true;
} else {
}
else {
Entity entity = minecraft.getCameraEntity();
return entity != null && entity.distanceToSqr(
Vec3.atCenterOf(signBlockEntity.getBlockPos())) < (double) OUTLINE_RENDER_DISTANCE;
return entity != null && entity.distanceToSqr(Vec3.atCenterOf(signBlockEntity.getBlockPos())) < (double) OUTLINE_RENDER_DISTANCE;
}
}
}
public static WoodType getSignType(Block block) {
WoodType signType2;
if (block instanceof SignBlock) {
signType2 = ((SignBlock) block).type();
} else {
}
else {
signType2 = WoodType.OAK;
}
return signType2;
}
public static Material getModelTexture(Block block) {
return Sheets.getSignMaterial(getSignType(block));
}
@ -157,14 +157,13 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer));
}
public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block);
RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(),
"textures/entity/sign/" + blockId.getPath() + ".png"));
RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(), "textures/entity/sign/" + blockId.getPath() + ".png"));
LAYERS.put(block, layer);
}
static {
defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/signs/oak.png"));
}

View file

@ -4,10 +4,5 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.SoundType;
public class BlockSounds {
public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F,
SoundEvents.STONE_BREAK,
SoundEvents.WART_BLOCK_STEP,
SoundEvents.STONE_PLACE,
SoundEvents.STONE_HIT,
SoundEvents.STONE_FALL);
public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, SoundEvents.STONE_BREAK, SoundEvents.WART_BLOCK_STEP, SoundEvents.STONE_PLACE, SoundEvents.STONE_HIT, SoundEvents.STONE_FALL);
}