[Change] Removed custom sign rendering in favour of vanilla Wood-Types
This commit is contained in:
parent
3ee132e7ff
commit
f38d1e9dde
15 changed files with 188 additions and 503 deletions
|
@ -8,7 +8,6 @@ import org.betterx.bclib.blocks.BaseFurnaceBlock;
|
|||
import org.betterx.bclib.blocks.BaseSignBlock;
|
||||
import org.betterx.bclib.client.render.BCLRenderLayer;
|
||||
import org.betterx.bclib.client.render.BaseChestBlockEntityRenderer;
|
||||
import org.betterx.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.interfaces.Fuel;
|
||||
import org.betterx.bclib.interfaces.PostInitable;
|
||||
|
@ -90,8 +89,6 @@ public class PostInitAPI {
|
|||
}
|
||||
if (block instanceof BaseChestBlock) {
|
||||
BaseChestBlockEntityRenderer.registerRenderLayer(block);
|
||||
} else if (block instanceof BaseSignBlock) {
|
||||
BaseSignBlockEntityRenderer.registerRenderLayer(block);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package org.betterx.bclib.blockentities;
|
||||
|
||||
import org.betterx.bclib.registry.BaseBlockEntities;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BaseSignBlockEntity extends SignBlockEntity {
|
||||
public BaseSignBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
super(blockPos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<?> getType() {
|
||||
return BaseBlockEntities.SIGN;
|
||||
}
|
||||
}
|
|
@ -1,201 +1,46 @@
|
|||
package org.betterx.bclib.blocks;
|
||||
|
||||
import org.betterx.bclib.blockentities.BaseSignBlockEntity;
|
||||
import org.betterx.bclib.client.models.ModelsHelper;
|
||||
import org.betterx.bclib.complexmaterials.BCLWoodTypeWrapper;
|
||||
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
|
||||
import org.betterx.bclib.interfaces.BlockModelProvider;
|
||||
import org.betterx.bclib.interfaces.CustomItemProvider;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.item.SignItem;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
import net.minecraft.world.level.block.WallSignBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.*;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraft.world.level.block.state.properties.RotationSegment;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BaseSignBlock extends SignBlock implements BlockModelProvider, CustomItemProvider {
|
||||
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
|
||||
public static final BooleanProperty FLOOR = BooleanProperty.create("floor");
|
||||
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[]{
|
||||
Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
|
||||
Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
|
||||
Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
|
||||
Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)
|
||||
};
|
||||
public class BaseSignBlock extends StandingSignBlock implements BlockModelProvider, CustomItemProvider {
|
||||
public final WallSignBlock wallSign;
|
||||
|
||||
private final Block parent;
|
||||
|
||||
public BaseSignBlock(Block source) {
|
||||
super(Properties.copy(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK);
|
||||
this.registerDefaultState(this.stateDefinition.any()
|
||||
.setValue(ROTATION, 0)
|
||||
.setValue(FLOOR, false)
|
||||
.setValue(WATERLOGGED, false));
|
||||
this.parent = source;
|
||||
public BaseSignBlock(WoodType type) {
|
||||
this(type, MapColor.WOOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(ROTATION, FLOOR, WATERLOGGED);
|
||||
public BaseSignBlock(BCLWoodTypeWrapper type) {
|
||||
this(type.type, type.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
return state.getValue(FLOOR) ? SHAPE : WALL_SHAPES[state.getValue(ROTATION) >> 2];
|
||||
public BaseSignBlock(WoodType type, MapColor color) {
|
||||
super(BehaviourBuilders.createSign(color), type);
|
||||
this.wallSign = new BaseWallSignBlock(BehaviourBuilders.createWallSign(color, this), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
return new BaseSignBlockEntity(blockPos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYRotationDegrees(BlockState blockState) {
|
||||
return RotationSegment.convertToDegrees(blockState.getValue(ROTATION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
if (placer instanceof Player) {
|
||||
BaseSignBlockEntity sign = (BaseSignBlockEntity) world.getBlockEntity(pos);
|
||||
if (sign != null) {
|
||||
if (!world.isClientSide) {
|
||||
sign.setAllowedPlayerEditor(placer.getUUID());
|
||||
((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos, true));
|
||||
} else {
|
||||
//sign.setEditable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(
|
||||
BlockState state,
|
||||
Direction facing,
|
||||
BlockState neighborState,
|
||||
LevelAccessor world,
|
||||
BlockPos pos,
|
||||
BlockPos neighborPos
|
||||
) {
|
||||
if (state.getValue(WATERLOGGED)) {
|
||||
world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
|
||||
}
|
||||
if (!canSurvive(state, world, pos)) {
|
||||
return state.getValue(WATERLOGGED)
|
||||
? state.getFluidState().createLegacyBlock()
|
||||
: Blocks.AIR.defaultBlockState();
|
||||
}
|
||||
return super.updateShape(state, facing, neighborState, world, pos, neighborPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
if (!state.getValue(FLOOR)) {
|
||||
int index = (((state.getValue(ROTATION) >> 2) + 2)) & 3;
|
||||
return world.getBlockState(pos.relative(BlocksHelper.HORIZONTAL[index])).isSolid();
|
||||
} else {
|
||||
return world.getBlockState(pos.below()).isSolid();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||
if (ctx.getClickedFace() == Direction.UP) {
|
||||
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
|
||||
return this
|
||||
.defaultBlockState()
|
||||
.setValue(FLOOR, true)
|
||||
.setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15)
|
||||
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
|
||||
} else if (ctx.getClickedFace() != Direction.DOWN) {
|
||||
BlockState blockState = this.defaultBlockState();
|
||||
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
|
||||
LevelReader worldView = ctx.getLevel();
|
||||
BlockPos blockPos = ctx.getClickedPos();
|
||||
Direction[] directions = ctx.getNearestLookingDirections();
|
||||
|
||||
for (Direction direction : directions) {
|
||||
if (direction.getAxis().isHorizontal()) {
|
||||
Direction dir = direction.getOpposite();
|
||||
int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15;
|
||||
blockState = blockState.setValue(ROTATION, rot);
|
||||
if (blockState.canSurvive(worldView, blockPos)) {
|
||||
return blockState.setValue(FLOOR, false)
|
||||
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
ResourceLocation parentId = BuiltInRegistries.BLOCK.getKey(parent);
|
||||
return ModelsHelper.createBlockEmpty(parentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||
return state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
|
||||
return super.canPlaceLiquid(world, pos, state, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
|
||||
return super.placeLiquid(world, pos, state, fluidState);
|
||||
return RotationSegment.convertToDegrees(blockState.getValue(StandingSignBlock.ROTATION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItem getCustomItem(ResourceLocation blockID, Item.Properties settings) {
|
||||
return new BlockItem(this, settings.stacksTo(16));
|
||||
return new SignItem(settings.stacksTo(16), this, wallSign);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.betterx.bclib.blocks;
|
||||
|
||||
import net.minecraft.world.level.block.WallSignBlock;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
|
||||
public class BaseWallSignBlock extends WallSignBlock {
|
||||
public BaseWallSignBlock(Properties properties, WoodType woodType) {
|
||||
super(properties, woodType);
|
||||
}
|
||||
}
|
|
@ -1,198 +0,0 @@
|
|||
package org.betterx.bclib.client.render;
|
||||
|
||||
import org.betterx.bclib.blockentities.BaseSignBlockEntity;
|
||||
import org.betterx.bclib.blocks.BaseSignBlock;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FastColor;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
import net.minecraft.world.level.block.entity.SignText;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSignBlockEntity> {
|
||||
private static final HashMap<Block, RenderType> RENDER_TYPES = Maps.newHashMap();
|
||||
private static final int OUTLINE_RENDER_DISTANCE = Mth.square(16);
|
||||
private static final RenderType RENDER_TYPE;
|
||||
private final SignRenderer.SignModel model;
|
||||
private final Font font;
|
||||
|
||||
|
||||
public BaseSignBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) {
|
||||
super();
|
||||
this.font = ctx.getFont();
|
||||
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
|
||||
) {
|
||||
final SignText frontText = signBlockEntity.getFrontText();
|
||||
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(Axis.YP.rotationDegrees(angle));
|
||||
model.stick.visible = true;
|
||||
} else {
|
||||
matrixStack.mulPose(Axis.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);
|
||||
matrixStack.popPose();
|
||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||
int m = frontText.getColor().getTextColor();
|
||||
int n = (int) (FastColor.ARGB32.red(m) * 0.4D);
|
||||
int o = (int) (FastColor.ARGB32.green(m) * 0.4D);
|
||||
int p = (int) (FastColor.ARGB32.blue(m) * 0.4D);
|
||||
int q = FastColor.ARGB32.color(0, p, o, n);
|
||||
|
||||
FormattedCharSequence[] formattedCharSequences = frontText.getRenderMessages(
|
||||
Minecraft.getInstance()
|
||||
.isTextFilteringEnabled(),
|
||||
(component) -> {
|
||||
List<FormattedCharSequence> list = this.font.split(component, 90);
|
||||
return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0);
|
||||
}
|
||||
);
|
||||
int drawColor;
|
||||
boolean drawOutlined;
|
||||
int drawLight;
|
||||
if (frontText.hasGlowingText()) {
|
||||
drawColor = frontText.getColor().getTextColor();
|
||||
drawOutlined = isOutlineVisible(signBlockEntity, drawColor);
|
||||
drawLight = 15728880;
|
||||
} 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);
|
||||
int marginHeight = 4 * signBlockEntity.getTextLineHeight() / 2;
|
||||
if (drawOutlined) {
|
||||
this.font.drawInBatch8xOutline(
|
||||
formattedCharSequence,
|
||||
t,
|
||||
(float) (s * signBlockEntity.getTextLineHeight() - marginHeight),
|
||||
drawColor,
|
||||
m,
|
||||
matrixStack.last().pose(),
|
||||
provider,
|
||||
drawLight
|
||||
);
|
||||
} else {
|
||||
this.font.drawInBatch(
|
||||
formattedCharSequence,
|
||||
t,
|
||||
(float) (s * signBlockEntity.getTextLineHeight() - marginHeight),
|
||||
drawColor,
|
||||
false,
|
||||
matrixStack.last().pose(),
|
||||
provider,
|
||||
Font.DisplayMode.NORMAL,
|
||||
0,
|
||||
drawLight
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
|
||||
private static boolean isOutlineVisible(BaseSignBlockEntity signBlockEntity, int i) {
|
||||
if (i == DyeColor.BLACK.getTextColor()) {
|
||||
return true;
|
||||
} else {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
LocalPlayer localPlayer = minecraft.player;
|
||||
if (localPlayer != null && minecraft.options.getCameraType().isFirstPerson() && localPlayer.isScoping()) {
|
||||
return true;
|
||||
} else {
|
||||
Entity entity = minecraft.getCameraEntity();
|
||||
return entity != null && entity.distanceToSqr(Vec3.atCenterOf(signBlockEntity.getBlockPos())) < (double) OUTLINE_RENDER_DISTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WoodType getSignType(Block block) {
|
||||
WoodType signType2;
|
||||
if (block instanceof SignBlock) {
|
||||
signType2 = ((SignBlock) block).type();
|
||||
} else {
|
||||
signType2 = WoodType.OAK;
|
||||
}
|
||||
|
||||
return signType2;
|
||||
}
|
||||
|
||||
public static Material getModelTexture(Block block) {
|
||||
return Sheets.getSignMaterial(getSignType(block));
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
|
||||
return provider.getBuffer(RENDER_TYPES.getOrDefault(block, RENDER_TYPE));
|
||||
}
|
||||
|
||||
public static void registerRenderLayer(Block block) {
|
||||
ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(block);
|
||||
RenderType layer = RenderType.entitySolid(new ResourceLocation(
|
||||
blockId.getNamespace(),
|
||||
"textures/entity/sign/" + blockId.getPath() + ".png"
|
||||
));
|
||||
RENDER_TYPES.put(block, layer);
|
||||
}
|
||||
|
||||
static {
|
||||
RENDER_TYPE = RenderType.entitySolid(new ResourceLocation("textures/entity/signs/oak.png"));
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package org.betterx.bclib.complexmaterials;
|
||||
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.properties.BlockSetType;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
|
||||
public class BCLWoodType extends WoodType {
|
||||
private String modID;
|
||||
|
||||
protected BCLWoodType(String modID, String string) {
|
||||
super(string, new BlockSetType(modID + "_" + string));
|
||||
this.modID = modID;
|
||||
}
|
||||
|
||||
protected BCLWoodType(String modID, String string, BlockSetType setType) {
|
||||
super(string, setType);
|
||||
this.modID = modID;
|
||||
}
|
||||
|
||||
protected BCLWoodType(
|
||||
String modID,
|
||||
String string,
|
||||
BlockSetType setType,
|
||||
SoundType soundType,
|
||||
SoundType hangingSignSoundType,
|
||||
SoundEvent fenceGateClose,
|
||||
SoundEvent fenceGateOpen
|
||||
) {
|
||||
super(string, setType, soundType, hangingSignSoundType, fenceGateClose, fenceGateOpen);
|
||||
this.modID = modID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package org.betterx.bclib.complexmaterials;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.properties.BlockSetType;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.type.BlockSetTypeRegistry;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.type.WoodTypeRegistry;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class BCLWoodTypeWrapper {
|
||||
public final ResourceLocation id;
|
||||
public final WoodType type;
|
||||
public final MapColor color;
|
||||
|
||||
protected BCLWoodTypeWrapper(ResourceLocation id, WoodType type, MapColor color) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static Builder create(String modID, String string) {
|
||||
return new Builder(new ResourceLocation(modID, string));
|
||||
}
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
public BlockSetType setType() {
|
||||
return type.setType();
|
||||
}
|
||||
|
||||
public ResourceLocation id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public WoodType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public MapColor color() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || obj.getClass() != this.getClass()) return false;
|
||||
var that = (BCLWoodTypeWrapper) obj;
|
||||
return Objects.equals(this.id, that.id) &&
|
||||
Objects.equals(this.type, that.type) &&
|
||||
Objects.equals(this.color, that.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, type, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BCLWoodTypeWrapper[" +
|
||||
"id=" + id + ", " +
|
||||
"type=" + type + ", " +
|
||||
"color=" + color + ']';
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private final ResourceLocation id;
|
||||
private BlockSetType setType;
|
||||
private MapColor color;
|
||||
|
||||
public Builder(ResourceLocation id) {
|
||||
this.id = id;
|
||||
this.color = MapColor.WOOD;
|
||||
}
|
||||
|
||||
public Builder setBlockSetType(BlockSetType setType) {
|
||||
this.setType = setType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setColor(MapColor color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BCLWoodTypeWrapper build() {
|
||||
if (setType == null) setType = BlockSetTypeRegistry.registerWood(id);
|
||||
|
||||
final WoodType type = WoodTypeRegistry.register(id, setType);
|
||||
return new BCLWoodTypeWrapper(id, type, color);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ import net.minecraft.world.item.Items;
|
|||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
@ -47,6 +46,7 @@ public class WoodenComplexMaterial extends ComplexMaterial {
|
|||
public static final String BLOCK_DOOR = "door";
|
||||
public static final String BLOCK_GATE = "gate";
|
||||
public static final String BLOCK_SIGN = "sign";
|
||||
public static final String BLOCK_WALL_SIGN = "wall_sign";
|
||||
public static final String BLOCK_SLAB = "slab";
|
||||
public static final String BLOCK_LOG = "log";
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class WoodenComplexMaterial extends ComplexMaterial {
|
|||
public final MapColor planksColor;
|
||||
public final MapColor woodColor;
|
||||
|
||||
public final WoodType woodType;
|
||||
public final BCLWoodTypeWrapper woodType;
|
||||
|
||||
public WoodenComplexMaterial(
|
||||
String modID,
|
||||
|
@ -67,7 +67,7 @@ public class WoodenComplexMaterial extends ComplexMaterial {
|
|||
super(modID, baseName, receipGroupPrefix);
|
||||
this.planksColor = planksColor;
|
||||
this.woodColor = woodColor;
|
||||
this.woodType = WoodType.register(new BCLWoodType(modID, baseName));
|
||||
this.woodType = BCLWoodTypeWrapper.create(modID, baseName).setColor(planksColor).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -158,7 +158,7 @@ public class WoodenComplexMaterial extends ComplexMaterial {
|
|||
|
||||
addBlockEntry(new BlockEntry(
|
||||
BLOCK_GATE,
|
||||
(complexMaterial, settings) -> new BaseGateBlock(getBlock(BLOCK_PLANKS), this.woodType)
|
||||
(complexMaterial, settings) -> new BaseGateBlock(getBlock(BLOCK_PLANKS), this.woodType.type())
|
||||
)
|
||||
.setBlockTags(BlockTags.FENCE_GATES));
|
||||
|
||||
|
@ -204,10 +204,22 @@ public class WoodenComplexMaterial extends ComplexMaterial {
|
|||
|
||||
addBlockEntry(new BlockEntry(
|
||||
BLOCK_SIGN,
|
||||
(complexMaterial, settings) -> new BaseSignBlock(getBlock(BLOCK_PLANKS))
|
||||
(complexMaterial, settings) -> new BaseSignBlock(woodType)
|
||||
)
|
||||
.setBlockTags(BlockTags.SIGNS)
|
||||
.setItemTags(ItemTags.SIGNS));
|
||||
|
||||
addBlockEntry(new BlockEntry(
|
||||
BLOCK_WALL_SIGN,
|
||||
false,
|
||||
(complexMaterial, settings) -> {
|
||||
if (getBlock(BLOCK_SIGN) instanceof BaseSignBlock sign) {
|
||||
return sign.wallSign;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
)
|
||||
.setBlockTags(BlockTags.WALL_SIGNS));
|
||||
}
|
||||
|
||||
final protected void initStorage(BlockBehaviour.Properties blockSettings, Item.Properties itemSettings) {
|
||||
|
@ -442,4 +454,5 @@ public class WoodenComplexMaterial extends ComplexMaterial {
|
|||
.build();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
|
@ -48,6 +48,7 @@ public class BlockEntry extends ComplexMaterialEntry {
|
|||
public Block init(ComplexMaterial material, BlockBehaviour.Properties blockSettings, BlockRegistry registry) {
|
||||
ResourceLocation location = getLocation(material.getModID(), material.getBaseName());
|
||||
Block block = initFunction.apply(material, blockSettings);
|
||||
if (block == null) return null;
|
||||
if (hasItem) {
|
||||
registry.register(location, block);
|
||||
if (itemTags != null) {
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import org.betterx.bclib.blocks.BaseSignBlock;
|
||||
import org.betterx.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractSignEditScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.SignEditScreen;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(SignEditScreen.class)
|
||||
public abstract class SignEditScreenMixin extends AbstractSignEditScreen {
|
||||
@Final
|
||||
private final SignBlockEntity sign;
|
||||
|
||||
@Shadow
|
||||
private SignRenderer.SignModel signModel;
|
||||
@Unique
|
||||
private boolean bclib_renderStick;
|
||||
@Unique
|
||||
private boolean bclib_isSign;
|
||||
|
||||
public SignEditScreenMixin(SignBlockEntity signBlockEntity, boolean bl, boolean bl2) {
|
||||
super(signBlockEntity, bl, bl2);
|
||||
this.sign = signBlockEntity;
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "offsetSign", at = @At("TAIL"))
|
||||
private void bclib_offsetSign(GuiGraphics guiGraphics, BlockState blockState, CallbackInfo ci) {
|
||||
bclib_isSign = blockState.getBlock() instanceof BaseSignBlock;
|
||||
if (bclib_isSign) {
|
||||
bclib_renderStick = blockState.getValue(BaseSignBlock.FLOOR);
|
||||
if (bclib_renderStick) {
|
||||
guiGraphics.pose().translate(0.0, 0.3125, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyArg(method = "renderSignBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/geom/ModelPart;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;II)V"), index = 1)
|
||||
private VertexConsumer bclib_renderSignBackground(VertexConsumer consumer) {
|
||||
if (bclib_isSign) {
|
||||
signModel.stick.visible = bclib_renderStick;
|
||||
Block block = this.sign.getBlockState().getBlock();
|
||||
MultiBufferSource.BufferSource bufferSource = this.minecraft.renderBuffers().bufferSource();
|
||||
return BaseSignBlockEntityRenderer.getConsumer(bufferSource, block);
|
||||
}
|
||||
return consumer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.betterx.bclib.mixin.common.signs;
|
||||
|
||||
import org.betterx.bclib.blocks.BaseSignBlock;
|
||||
import org.betterx.bclib.blocks.BaseWallSignBlock;
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(BlockEntityType.class)
|
||||
public class BlockEntityTypeMixin {
|
||||
@Inject(method = "isValid", at = @At("HEAD"), cancellable = true)
|
||||
void bcl_isValid(BlockState blockState, CallbackInfoReturnable<Boolean> cir) {
|
||||
final BlockEntityType self = (BlockEntityType) (Object) this;
|
||||
if (self == BlockEntityType.SIGN) {
|
||||
final Block block = blockState.getBlock();
|
||||
if ((block instanceof BaseSignBlock) || (block instanceof BaseWallSignBlock)) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package org.betterx.bclib.registry;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.blockentities.*;
|
||||
import org.betterx.bclib.blockentities.BaseBarrelBlockEntity;
|
||||
import org.betterx.bclib.blockentities.BaseChestBlockEntity;
|
||||
import org.betterx.bclib.blockentities.BaseFurnaceBlockEntity;
|
||||
import org.betterx.bclib.blockentities.DynamicBlockEntityType;
|
||||
import org.betterx.bclib.blockentities.DynamicBlockEntityType.BlockEntitySupplier;
|
||||
import org.betterx.bclib.blocks.BaseBarrelBlock;
|
||||
import org.betterx.bclib.blocks.BaseChestBlock;
|
||||
|
@ -13,15 +16,16 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
|
||||
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(
|
||||
public static final DynamicBlockEntityType<SignBlockEntity> SIGN = registerBlockEntityType(
|
||||
BCLib.makeID("sign"),
|
||||
BaseSignBlockEntity::new
|
||||
SignBlockEntity::new
|
||||
);
|
||||
public static final DynamicBlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID(
|
||||
"furnace"), BaseFurnaceBlockEntity::new);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package org.betterx.bclib.registry;
|
||||
|
||||
import org.betterx.bclib.client.render.BaseChestBlockEntityRenderer;
|
||||
import org.betterx.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
@ -11,6 +12,8 @@ import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
|
|||
public class BaseBlockEntityRenders {
|
||||
public static void register() {
|
||||
BlockEntityRendererRegistry.register(BaseBlockEntities.CHEST, BaseChestBlockEntityRenderer::new);
|
||||
BlockEntityRendererRegistry.register(BaseBlockEntities.SIGN, BaseSignBlockEntityRenderer::new);
|
||||
|
||||
//make sure we can lod signs from older worlds. Can be removed in the future
|
||||
BlockEntityRendererRegistry.register(BaseBlockEntities.SIGN, SignRenderer::new);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
"MinecraftMixin",
|
||||
"ModelManagerMixin",
|
||||
"PresetEditorMixin",
|
||||
"SignEditScreenMixin",
|
||||
"boat.BoatRendererMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
"shears.PumpkinBlockMixin",
|
||||
"shears.SheepMixin",
|
||||
"shears.SnowGolemMixin",
|
||||
"shears.TripWireBlockMixin"
|
||||
"shears.TripWireBlockMixin",
|
||||
"signs.BlockEntityTypeMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue