BlockEntities fixes
This commit is contained in:
parent
7ce25e1bd3
commit
d3c3e88614
7 changed files with 386 additions and 372 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,24 +1,11 @@
|
|||
package ru.bclib.client;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
import ru.bclib.blocks.BaseSignBlock;
|
||||
import ru.bclib.client.render.BaseChestBlockEntityRenderer;
|
||||
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
package ru.bclib.client;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import ru.bclib.registry.BaseBlockEntityRenders;
|
||||
|
||||
public class BCLibClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
BaseBlockEntityRenders.register();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,176 +1,176 @@
|
|||
package ru.bclib.client.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
|
||||
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.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.entity.LidBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.ChestType;
|
||||
import ru.bclib.blockentities.BaseChestBlockEntity;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class BaseChestBlockEntityRenderer extends 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 ModelPart partA;
|
||||
private final ModelPart partC;
|
||||
private final ModelPart partB;
|
||||
private final ModelPart partRightA;
|
||||
private final ModelPart partRightC;
|
||||
private final ModelPart partRightB;
|
||||
private final ModelPart partLeftA;
|
||||
private final ModelPart partLeftC;
|
||||
private final ModelPart partLeftB;
|
||||
|
||||
public BaseChestBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||
super(blockEntityRenderDispatcher);
|
||||
|
||||
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.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.y = 9.0F;
|
||||
this.partA.z = 1.0F;
|
||||
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.y = 8.0F;
|
||||
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.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.y = 9.0F;
|
||||
this.partRightA.z = 1.0F;
|
||||
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.y = 8.0F;
|
||||
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.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.y = 9.0F;
|
||||
this.partLeftA.z = 1.0F;
|
||||
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.y = 8.0F;
|
||||
}
|
||||
|
||||
public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
Level world = entity.getLevel();
|
||||
boolean worldExists = world != null;
|
||||
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;
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock) {
|
||||
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
|
||||
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 {
|
||||
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
|
||||
}
|
||||
|
||||
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) 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);
|
||||
|
||||
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
|
||||
|
||||
if (isDouble) {
|
||||
if (chestType == ChestType.LEFT) {
|
||||
renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay);
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay);
|
||||
}
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partA, this.partB, this.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;
|
||||
modelPart.render(matrices, vertices, light, overlay);
|
||||
modelPart2.render(matrices, vertices, light, overlay);
|
||||
modelPart3.render(matrices, vertices, light, overlay);
|
||||
}
|
||||
|
||||
private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
|
||||
switch (type) {
|
||||
case LEFT:
|
||||
return layers[ID_LEFT];
|
||||
case RIGHT:
|
||||
return layers[ID_RIGHT];
|
||||
case SINGLE:
|
||||
default:
|
||||
return 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(BaseChestBlock 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"))
|
||||
});
|
||||
}
|
||||
|
||||
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"))
|
||||
};
|
||||
}
|
||||
}
|
||||
package ru.bclib.client.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
|
||||
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.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.entity.LidBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.ChestType;
|
||||
import ru.bclib.blockentities.BaseChestBlockEntity;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class BaseChestBlockEntityRenderer extends 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 ModelPart partA;
|
||||
private final ModelPart partC;
|
||||
private final ModelPart partB;
|
||||
private final ModelPart partRightA;
|
||||
private final ModelPart partRightC;
|
||||
private final ModelPart partRightB;
|
||||
private final ModelPart partLeftA;
|
||||
private final ModelPart partLeftC;
|
||||
private final ModelPart partLeftB;
|
||||
|
||||
public BaseChestBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||
super(blockEntityRenderDispatcher);
|
||||
|
||||
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.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.y = 9.0F;
|
||||
this.partA.z = 1.0F;
|
||||
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.y = 8.0F;
|
||||
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.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.y = 9.0F;
|
||||
this.partRightA.z = 1.0F;
|
||||
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.y = 8.0F;
|
||||
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.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.y = 9.0F;
|
||||
this.partLeftA.z = 1.0F;
|
||||
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.y = 8.0F;
|
||||
}
|
||||
|
||||
public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
Level world = entity.getLevel();
|
||||
boolean worldExists = world != null;
|
||||
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;
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock) {
|
||||
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
|
||||
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 {
|
||||
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
|
||||
}
|
||||
|
||||
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) 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);
|
||||
|
||||
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
|
||||
|
||||
if (isDouble) {
|
||||
if (chestType == ChestType.LEFT) {
|
||||
renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay);
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay);
|
||||
}
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partA, this.partB, this.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;
|
||||
modelPart.render(matrices, vertices, light, overlay);
|
||||
modelPart2.render(matrices, vertices, light, overlay);
|
||||
modelPart3.render(matrices, vertices, light, overlay);
|
||||
}
|
||||
|
||||
private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
|
||||
switch (type) {
|
||||
case LEFT:
|
||||
return layers[ID_LEFT];
|
||||
case RIGHT:
|
||||
return layers[ID_RIGHT];
|
||||
case SINGLE:
|
||||
default:
|
||||
return 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"))
|
||||
});
|
||||
}
|
||||
|
||||
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"))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,113 +1,113 @@
|
|||
package ru.bclib.client.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
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.SignRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
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.blocks.BaseSignBlock;
|
||||
|
||||
public class BaseSignBlockEntityRenderer extends BlockEntityRenderer<BaseSignBlockEntity> {
|
||||
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
||||
private static final RenderType defaultLayer;
|
||||
private final SignModel model = new SignRenderer.SignModel();
|
||||
|
||||
public BaseSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
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));
|
||||
this.model.stick.visible = true;
|
||||
} else {
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
|
||||
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
||||
this.model.stick.visible = false;
|
||||
}
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
||||
model.sign.render(matrixStack, vertexConsumer, light, overlay);
|
||||
model.stick.render(matrixStack, vertexConsumer, light, overlay);
|
||||
matrixStack.popPose();
|
||||
Font textRenderer = renderer.getFont();
|
||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||
int m = signBlockEntity.getColor().getTextColor();
|
||||
int n = (int) (NativeImage.getR(m) * 0.4D);
|
||||
int o = (int) (NativeImage.getG(m) * 0.4D);
|
||||
int p = (int) (NativeImage.getB(m) * 0.4D);
|
||||
int q = NativeImage.combine(0, p, o, n);
|
||||
|
||||
for (int s = 0; s < 4; ++s) {
|
||||
FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> {
|
||||
List<FormattedCharSequence> list = textRenderer.split(text, 90);
|
||||
return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0);
|
||||
});
|
||||
if (orderedText != null) {
|
||||
float t = (float) (-textRenderer.width(orderedText) / 2);
|
||||
textRenderer.drawInBatch(orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light);
|
||||
}
|
||||
}
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
public static Material getModelTexture(Block block) {
|
||||
WoodType signType2;
|
||||
if (block instanceof SignBlock) {
|
||||
signType2 = ((SignBlock) block).type();
|
||||
} else {
|
||||
signType2 = WoodType.OAK;
|
||||
}
|
||||
|
||||
return Sheets.signTexture(signType2);
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
|
||||
return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer));
|
||||
}
|
||||
|
||||
public static void registerRenderLayer(BaseSignBlock block) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(block);
|
||||
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/sign/oak.png"));
|
||||
}
|
||||
}
|
||||
package ru.bclib.client.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
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.SignRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
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.blocks.BaseSignBlock;
|
||||
|
||||
public class BaseSignBlockEntityRenderer extends BlockEntityRenderer<BaseSignBlockEntity> {
|
||||
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
||||
private static final RenderType defaultLayer;
|
||||
private final SignModel model = new SignRenderer.SignModel();
|
||||
|
||||
public BaseSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
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));
|
||||
this.model.stick.visible = true;
|
||||
} else {
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
|
||||
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
||||
this.model.stick.visible = false;
|
||||
}
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
||||
model.sign.render(matrixStack, vertexConsumer, light, overlay);
|
||||
model.stick.render(matrixStack, vertexConsumer, light, overlay);
|
||||
matrixStack.popPose();
|
||||
Font textRenderer = renderer.getFont();
|
||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||
int m = signBlockEntity.getColor().getTextColor();
|
||||
int n = (int) (NativeImage.getR(m) * 0.4D);
|
||||
int o = (int) (NativeImage.getG(m) * 0.4D);
|
||||
int p = (int) (NativeImage.getB(m) * 0.4D);
|
||||
int q = NativeImage.combine(0, p, o, n);
|
||||
|
||||
for (int s = 0; s < 4; ++s) {
|
||||
FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> {
|
||||
List<FormattedCharSequence> list = textRenderer.split(text, 90);
|
||||
return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0);
|
||||
});
|
||||
if (orderedText != null) {
|
||||
float t = (float) (-textRenderer.width(orderedText) / 2);
|
||||
textRenderer.drawInBatch(orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light);
|
||||
}
|
||||
}
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
public static Material getModelTexture(Block block) {
|
||||
WoodType signType2;
|
||||
if (block instanceof SignBlock) {
|
||||
signType2 = ((SignBlock) block).type();
|
||||
} else {
|
||||
signType2 = WoodType.OAK;
|
||||
}
|
||||
|
||||
return Sheets.signTexture(signType2);
|
||||
}
|
||||
|
||||
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"));
|
||||
LAYERS.put(block, layer);
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/signs/oak.png"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,54 @@
|
|||
package ru.bclib.registry;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.blockentities.BaseBarrelBlockEntity;
|
||||
import ru.bclib.blockentities.BaseChestBlockEntity;
|
||||
import ru.bclib.blockentities.BaseFurnaceBlockEntity;
|
||||
import ru.bclib.blockentities.BaseSignBlockEntity;
|
||||
import ru.bclib.blocks.BaseBarrelBlock;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
import ru.bclib.blocks.BaseFurnaceBlock;
|
||||
import ru.bclib.blocks.BaseSignBlock;
|
||||
|
||||
public class BaseBlockEntities {
|
||||
public static final BlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID("chest"),
|
||||
BlockEntityType.Builder.of(BaseChestBlockEntity::new, getChests()));
|
||||
public static final BlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID("barrel"),
|
||||
BlockEntityType.Builder.of(BaseBarrelBlockEntity::new, getBarrels()));
|
||||
public static final BlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"),
|
||||
BlockEntityType.Builder.of(BaseSignBlockEntity::new, getSigns()));
|
||||
public static final BlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"),
|
||||
BlockEntityType.Builder.of(BaseFurnaceBlockEntity::new, getFurnaces()));
|
||||
|
||||
public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntityType(ResourceLocation blockId, BlockEntityType.Builder<T> builder) {
|
||||
return Registry.register(Registry.BLOCK_ENTITY_TYPE, blockId, builder.build(null));
|
||||
}
|
||||
|
||||
public static void register() {}
|
||||
|
||||
public static Block[] getChests() {
|
||||
return BaseRegistry.getRegisteredBlocks().values().stream()
|
||||
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock)
|
||||
.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)
|
||||
.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)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
package ru.bclib.registry;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.blockentities.*;
|
||||
import ru.bclib.blocks.BaseBarrelBlock;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
import ru.bclib.blocks.BaseFurnaceBlock;
|
||||
import ru.bclib.blocks.BaseSignBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BaseBlockEntities {
|
||||
public static final DynamicBlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID("chest"), BaseChestBlockEntity::new);
|
||||
public static final DynamicBlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID("barrel"), BaseBarrelBlockEntity::new);
|
||||
public static final DynamicBlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"), BaseSignBlockEntity::new);
|
||||
public static final DynamicBlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"), BaseFurnaceBlockEntity::new);
|
||||
|
||||
public static <T extends BlockEntity> DynamicBlockEntityType<T> registerBlockEntityType(ResourceLocation typeId, Supplier<? extends T> supplier) {
|
||||
return Registry.register(Registry.BLOCK_ENTITY_TYPE, typeId, new DynamicBlockEntityType<>(supplier));
|
||||
}
|
||||
|
||||
public static void register() {}
|
||||
|
||||
public static Block[] getChests() {
|
||||
return BaseRegistry.getRegisteredBlocks().values().stream()
|
||||
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock)
|
||||
.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)
|
||||
.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)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
"entrypoints": {
|
||||
"main": [
|
||||
"ru.bclib.BCLib"
|
||||
],
|
||||
"client": [
|
||||
"ru.bclib.client.BCLibClient"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue