BlockEntities fixes

This commit is contained in:
Aleksey 2021-06-03 17:00:32 +03:00
parent 7ce25e1bd3
commit d3c3e88614
7 changed files with 386 additions and 372 deletions

View file

@ -8,7 +8,7 @@ yarn_mappings=6
loader_version=0.11.3 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version = 0.1.13 mod_version = 0.1.14
maven_group = ru.bclib maven_group = ru.bclib
archives_base_name = bclib archives_base_name = bclib

View file

@ -0,0 +1,28 @@
package ru.bclib.blockentities;
import com.google.common.collect.Sets;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import java.util.Collections;
import java.util.Set;
import java.util.function.Supplier;
public class DynamicBlockEntityType<T extends BlockEntity> extends BlockEntityType<T> {
private final Set<Block> validBlocks = Sets.newHashSet();
public DynamicBlockEntityType(Supplier<? extends T> supplier) {
super(supplier, Collections.emptySet(), null);
}
@Override
public boolean isValid(Block block) {
return validBlocks.contains(block);
}
public void registerBlock(Block block) {
validBlocks.add(block);
}
}

View file

@ -1,24 +1,11 @@
package ru.bclib.client; package ru.bclib.client;
import java.util.Arrays; import net.fabricmc.api.ClientModInitializer;
import ru.bclib.registry.BaseBlockEntityRenders;
import net.fabricmc.api.ClientModInitializer;
import ru.bclib.blocks.BaseChestBlock; public class BCLibClient implements ClientModInitializer {
import ru.bclib.blocks.BaseSignBlock; @Override
import ru.bclib.client.render.BaseChestBlockEntityRenderer; public void onInitializeClient() {
import ru.bclib.client.render.BaseSignBlockEntityRenderer; BaseBlockEntityRenders.register();
import ru.bclib.registry.BaseBlockEntities; }
import ru.bclib.registry.BaseBlockEntityRenders; }
public class BCLibClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BaseBlockEntityRenders.register();
Arrays.stream(BaseBlockEntities.getChests()).forEach(chest -> {
BaseChestBlockEntityRenderer.registerRenderLayer((BaseChestBlock) chest);
});
Arrays.stream(BaseBlockEntities.getSigns()).forEach(sign -> {
BaseSignBlockEntityRenderer.registerRenderLayer((BaseSignBlock) sign);
});
}
}

View file

@ -1,176 +1,176 @@
package ru.bclib.client.render; package ru.bclib.client.render;
import java.util.HashMap; import java.util.HashMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
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 it.unimi.dsi.fastutil.floats.Float2FloatFunction; import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import it.unimi.dsi.fastutil.ints.Int2IntFunction; import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.ModelPart;
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.blockentity.BlockEntityRenderDispatcher; 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.BrightnessCombiner; import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractChestBlock; import net.minecraft.world.level.block.AbstractChestBlock;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChestBlock; import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.DoubleBlockCombiner; import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult; import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult;
import net.minecraft.world.level.block.entity.ChestBlockEntity; import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.ChestType; import net.minecraft.world.level.block.state.properties.ChestType;
import ru.bclib.blockentities.BaseChestBlockEntity; import ru.bclib.blockentities.BaseChestBlockEntity;
import ru.bclib.blocks.BaseChestBlock; import ru.bclib.blocks.BaseChestBlock;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class BaseChestBlockEntityRenderer extends BlockEntityRenderer<BaseChestBlockEntity> { public class BaseChestBlockEntityRenderer extends BlockEntityRenderer<BaseChestBlockEntity> {
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 static final int ID_NORMAL = 0; private static final int ID_NORMAL = 0;
private static final int ID_LEFT = 1; private static final int ID_LEFT = 1;
private static final int ID_RIGHT = 2; private static final int ID_RIGHT = 2;
private final ModelPart partA; private final ModelPart partA;
private final ModelPart partC; private final ModelPart partC;
private final ModelPart partB; private final ModelPart partB;
private final ModelPart partRightA; private final ModelPart partRightA;
private final ModelPart partRightC; private final ModelPart partRightC;
private final ModelPart partRightB; private final ModelPart partRightB;
private final ModelPart partLeftA; private final ModelPart partLeftA;
private final ModelPart partLeftC; private final ModelPart partLeftC;
private final ModelPart partLeftB; private final ModelPart partLeftB;
public BaseChestBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) { public BaseChestBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
super(blockEntityRenderDispatcher); super(blockEntityRenderDispatcher);
this.partC = new ModelPart(64, 64, 0, 19); this.partC = new ModelPart(64, 64, 0, 19);
this.partC.addBox(1.0F, 0.0F, 1.0F, 14.0F, 9.0F, 14.0F, 0.0F); this.partC.addBox(1.0F, 0.0F, 1.0F, 14.0F, 9.0F, 14.0F, 0.0F);
this.partA = new ModelPart(64, 64, 0, 0); this.partA = new ModelPart(64, 64, 0, 0);
this.partA.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F); this.partA.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
this.partA.y = 9.0F; this.partA.y = 9.0F;
this.partA.z = 1.0F; this.partA.z = 1.0F;
this.partB = new ModelPart(64, 64, 0, 0); this.partB = new ModelPart(64, 64, 0, 0);
this.partB.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F); this.partB.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
this.partB.y = 8.0F; this.partB.y = 8.0F;
this.partRightC = new ModelPart(64, 64, 0, 19); this.partRightC = new ModelPart(64, 64, 0, 19);
this.partRightC.addBox(1.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F); this.partRightC.addBox(1.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
this.partRightA = new ModelPart(64, 64, 0, 0); this.partRightA = new ModelPart(64, 64, 0, 0);
this.partRightA.addBox(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F); this.partRightA.addBox(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
this.partRightA.y = 9.0F; this.partRightA.y = 9.0F;
this.partRightA.z = 1.0F; this.partRightA.z = 1.0F;
this.partRightB = new ModelPart(64, 64, 0, 0); this.partRightB = new ModelPart(64, 64, 0, 0);
this.partRightB.addBox(15.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F); this.partRightB.addBox(15.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
this.partRightB.y = 8.0F; this.partRightB.y = 8.0F;
this.partLeftC = new ModelPart(64, 64, 0, 19); this.partLeftC = new ModelPart(64, 64, 0, 19);
this.partLeftC.addBox(0.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F); this.partLeftC.addBox(0.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
this.partLeftA = new ModelPart(64, 64, 0, 0); this.partLeftA = new ModelPart(64, 64, 0, 0);
this.partLeftA.addBox(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F); this.partLeftA.addBox(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
this.partLeftA.y = 9.0F; this.partLeftA.y = 9.0F;
this.partLeftA.z = 1.0F; this.partLeftA.z = 1.0F;
this.partLeftB = new ModelPart(64, 64, 0, 0); this.partLeftB = new ModelPart(64, 64, 0, 0);
this.partLeftB.addBox(0.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F); this.partLeftB.addBox(0.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
this.partLeftB.y = 8.0F; this.partLeftB.y = 8.0F;
} }
public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) { public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
Level world = entity.getLevel(); Level world = entity.getLevel();
boolean worldExists = world != null; boolean worldExists = world != null;
BlockState blockState = worldExists ? entity.getBlockState() : (BlockState) Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH); BlockState blockState = worldExists ? entity.getBlockState() : (BlockState) Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? (ChestType) blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE; ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? (ChestType) blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
Block block = blockState.getBlock(); Block block = blockState.getBlock();
if (block instanceof AbstractChestBlock) { if (block instanceof AbstractChestBlock) {
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block; AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
boolean isDouble = chestType != ChestType.SINGLE; boolean isDouble = chestType != ChestType.SINGLE;
float f = ((Direction) blockState.getValue(ChestBlock.FACING)).toYRot(); float f = ((Direction) blockState.getValue(ChestBlock.FACING)).toYRot();
NeighborCombineResult<? extends ChestBlockEntity> propertySource; NeighborCombineResult<? extends ChestBlockEntity> propertySource;
matrices.pushPose(); matrices.pushPose();
matrices.translate(0.5D, 0.5D, 0.5D); matrices.translate(0.5D, 0.5D, 0.5D);
matrices.mulPose(Vector3f.YP.rotationDegrees(-f)); matrices.mulPose(Vector3f.YP.rotationDegrees(-f));
matrices.translate(-0.5D, -0.5D, -0.5D); matrices.translate(-0.5D, -0.5D, -0.5D);
if (worldExists) { if (worldExists) {
propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true); propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true);
} else { } else {
propertySource = DoubleBlockCombiner.Combiner::acceptNone; propertySource = DoubleBlockCombiner.Combiner::acceptNone;
} }
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) entity))).get(tickDelta); float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) entity))).get(tickDelta);
pitch = 1.0F - pitch; pitch = 1.0F - pitch;
pitch = 1.0F - pitch * pitch * pitch; pitch = 1.0F - pitch * pitch * pitch;
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light); int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType); VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
if (isDouble) { if (isDouble) {
if (chestType == ChestType.LEFT) { if (chestType == ChestType.LEFT) {
renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay); renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay);
} else { } else {
renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay); renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay);
} }
} else { } else {
renderParts(matrices, vertexConsumer, this.partA, this.partB, this.partC, pitch, blockLight, overlay); renderParts(matrices, vertexConsumer, this.partA, this.partB, this.partC, pitch, blockLight, overlay);
} }
matrices.popPose(); matrices.popPose();
} }
} }
private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) { private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) {
modelPart.xRot = -(pitch * 1.5707964F); modelPart.xRot = -(pitch * 1.5707964F);
modelPart2.xRot = modelPart.xRot; modelPart2.xRot = modelPart.xRot;
modelPart.render(matrices, vertices, light, overlay); modelPart.render(matrices, vertices, light, overlay);
modelPart2.render(matrices, vertices, light, overlay); modelPart2.render(matrices, vertices, light, overlay);
modelPart3.render(matrices, vertices, light, overlay); modelPart3.render(matrices, vertices, light, overlay);
} }
private static RenderType getChestTexture(ChestType type, RenderType[] layers) { private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
switch (type) { switch (type) {
case LEFT: case LEFT:
return layers[ID_LEFT]; return layers[ID_LEFT];
case RIGHT: case RIGHT:
return layers[ID_RIGHT]; return layers[ID_RIGHT];
case SINGLE: case SINGLE:
default: default:
return layers[ID_NORMAL]; return layers[ID_NORMAL];
} }
} }
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) { public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) {
RenderType[] layers = LAYERS.getOrDefault(block, defaultLayer); RenderType[] layers = LAYERS.getOrDefault(block, defaultLayer);
return provider.getBuffer(getChestTexture(chestType, layers)); return provider.getBuffer(getChestTexture(chestType, layers));
} }
public static void registerRenderLayer(BaseChestBlock block) { public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block); ResourceLocation blockId = Registry.BLOCK.getKey(block);
String modId = blockId.getNamespace(); String modId = blockId.getNamespace();
String path = blockId.getPath(); String path = blockId.getPath();
LAYERS.put(block, new RenderType[] { LAYERS.put(block, new RenderType[] {
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + ".png")), 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 + "_left.png")),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png")) RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))
}); });
} }
static { static {
defaultLayer = new RenderType[] { defaultLayer = new RenderType[] {
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")), 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_left.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png")) RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))
}; };
} }
} }

View file

@ -1,113 +1,113 @@
package ru.bclib.client.render; package ru.bclib.client.render;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; 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.gui.Font; import net.minecraft.client.gui.Font;
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.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
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.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.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 ru.bclib.blockentities.BaseSignBlockEntity; import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.blocks.BaseSignBlock; import ru.bclib.blocks.BaseSignBlock;
public class BaseSignBlockEntityRenderer extends BlockEntityRenderer<BaseSignBlockEntity> { public class BaseSignBlockEntityRenderer extends 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 SignModel model = new SignRenderer.SignModel();
public BaseSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) { public BaseSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
super(dispatcher); super(dispatcher);
} }
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; this.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; this.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.sign.render(matrixStack, vertexConsumer, light, overlay);
model.stick.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();
int n = (int) (NativeImage.getR(m) * 0.4D); int n = (int) (NativeImage.getR(m) * 0.4D);
int o = (int) (NativeImage.getG(m) * 0.4D); int o = (int) (NativeImage.getG(m) * 0.4D);
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);
for (int s = 0; s < 4; ++s) { for (int s = 0; s < 4; ++s) {
FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> { FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> {
List<FormattedCharSequence> list = textRenderer.split(text, 90); List<FormattedCharSequence> list = textRenderer.split(text, 90);
return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0); return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0);
}); });
if (orderedText != null) { if (orderedText != null) {
float t = (float) (-textRenderer.width(orderedText) / 2); float t = (float) (-textRenderer.width(orderedText) / 2);
textRenderer.drawInBatch(orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light); textRenderer.drawInBatch(orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light);
} }
} }
matrixStack.popPose(); matrixStack.popPose();
} }
public static Material getModelTexture(Block block) { public static Material getModelTexture(Block block) {
WoodType signType2; WoodType signType2;
if (block instanceof SignBlock) { if (block instanceof SignBlock) {
signType2 = ((SignBlock) block).type(); signType2 = ((SignBlock) block).type();
} else { } else {
signType2 = WoodType.OAK; signType2 = WoodType.OAK;
} }
return Sheets.signTexture(signType2); return Sheets.signTexture(signType2);
} }
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) { public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer)); return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer));
} }
public static void registerRenderLayer(BaseSignBlock block) { public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block); ResourceLocation blockId = Registry.BLOCK.getKey(block);
RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(), RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(),
"textures/entity/sign/" + blockId.getPath() + ".png")); "textures/entity/sign/" + blockId.getPath() + ".png"));
LAYERS.put(block, layer); LAYERS.put(block, layer);
} }
static { static {
defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/sign/oak.png")); defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/signs/oak.png"));
} }
} }

View file

@ -1,58 +1,54 @@
package ru.bclib.registry; package ru.bclib.registry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.blockentities.BaseBarrelBlockEntity; import ru.bclib.blockentities.*;
import ru.bclib.blockentities.BaseChestBlockEntity; import ru.bclib.blocks.BaseBarrelBlock;
import ru.bclib.blockentities.BaseFurnaceBlockEntity; import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blockentities.BaseSignBlockEntity; import ru.bclib.blocks.BaseFurnaceBlock;
import ru.bclib.blocks.BaseBarrelBlock; import ru.bclib.blocks.BaseSignBlock;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseFurnaceBlock; import java.util.Arrays;
import ru.bclib.blocks.BaseSignBlock; import java.util.function.Supplier;
public class BaseBlockEntities { public class BaseBlockEntities {
public static final BlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID("chest"), public static final DynamicBlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID("chest"), BaseChestBlockEntity::new);
BlockEntityType.Builder.of(BaseChestBlockEntity::new, getChests())); public static final DynamicBlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID("barrel"), BaseBarrelBlockEntity::new);
public static final BlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID("barrel"), public static final DynamicBlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"), BaseSignBlockEntity::new);
BlockEntityType.Builder.of(BaseBarrelBlockEntity::new, getBarrels())); public static final DynamicBlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"), BaseFurnaceBlockEntity::new);
public static final BlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"),
BlockEntityType.Builder.of(BaseSignBlockEntity::new, getSigns())); public static <T extends BlockEntity> DynamicBlockEntityType<T> registerBlockEntityType(ResourceLocation typeId, Supplier<? extends T> supplier) {
public static final BlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"), return Registry.register(Registry.BLOCK_ENTITY_TYPE, typeId, new DynamicBlockEntityType<>(supplier));
BlockEntityType.Builder.of(BaseFurnaceBlockEntity::new, getFurnaces())); }
public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntityType(ResourceLocation blockId, BlockEntityType.Builder<T> builder) { public static void register() {}
return Registry.register(Registry.BLOCK_ENTITY_TYPE, blockId, builder.build(null));
} public static Block[] getChests() {
return BaseRegistry.getRegisteredBlocks().values().stream()
public static void register() {} .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
public static Block[] getChests() { }
return BaseRegistry.getRegisteredBlocks().values().stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock) private static Block[] getBarrels() {
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); return BaseRegistry.getRegisteredBlocks().values().stream()
} .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
private static Block[] getBarrels() { }
return BaseRegistry.getRegisteredBlocks().values().stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock) public static Block[] getSigns() {
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); return BaseRegistry.getRegisteredBlocks().values().stream()
} .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
public static Block[] getSigns() { }
return BaseRegistry.getRegisteredBlocks().values().stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock) private static Block[] getFurnaces() {
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); return BaseRegistry.getRegisteredBlocks().values().stream()
} .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
private static Block[] getFurnaces() { }
return BaseRegistry.getRegisteredBlocks().values().stream() }
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
}
}

View file

@ -22,6 +22,9 @@
"entrypoints": { "entrypoints": {
"main": [ "main": [
"ru.bclib.BCLib" "ru.bclib.BCLib"
],
"client": [
"ru.bclib.client.BCLibClient"
] ]
}, },
"mixins": [ "mixins": [