More wooden materials, gui, mixins, registries
This commit is contained in:
parent
6ec2b53edd
commit
720103bd45
97 changed files with 2414 additions and 14 deletions
|
@ -0,0 +1,138 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.block.BarrelBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import ru.betterend.blocks.basis.BlockBarrel;
|
||||
import ru.betterend.registry.BlockEntityRegistry;
|
||||
|
||||
public class EBarrelBlockEntity extends LootableContainerBlockEntity {
|
||||
private DefaultedList<ItemStack> inventory;
|
||||
private int viewerCount;
|
||||
|
||||
private EBarrelBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public EBarrelBlockEntity() {
|
||||
this(BlockEntityRegistry.BARREL);
|
||||
}
|
||||
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
if (!this.serializeLootTable(tag)) {
|
||||
Inventories.toTag(tag, this.inventory);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
|
||||
if (!this.deserializeLootTable(tag)) {
|
||||
Inventories.fromTag(tag, this.inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 27;
|
||||
}
|
||||
|
||||
protected DefaultedList<ItemStack> getInvStackList() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
protected void setInvStackList(DefaultedList<ItemStack> list) {
|
||||
this.inventory = list;
|
||||
}
|
||||
|
||||
protected Text getContainerName() {
|
||||
return new TranslatableText("container.barrel");
|
||||
}
|
||||
|
||||
protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
return GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, this);
|
||||
}
|
||||
|
||||
public void onOpen(PlayerEntity player) {
|
||||
if (!player.isSpectator()) {
|
||||
if (this.viewerCount < 0) {
|
||||
this.viewerCount = 0;
|
||||
}
|
||||
|
||||
++this.viewerCount;
|
||||
BlockState blockState = this.getCachedState();
|
||||
boolean bl = (Boolean) blockState.get(BarrelBlock.OPEN);
|
||||
if (!bl) {
|
||||
this.playSound(blockState, SoundEvents.BLOCK_BARREL_OPEN);
|
||||
this.setOpen(blockState, true);
|
||||
}
|
||||
|
||||
this.scheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleUpdate() {
|
||||
this.world.getBlockTickScheduler().schedule(this.getPos(), this.getCachedState().getBlock(), 5);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
int i = this.pos.getX();
|
||||
int j = this.pos.getY();
|
||||
int k = this.pos.getZ();
|
||||
this.viewerCount = ChestBlockEntity.countViewers(this.world, this, i, j, k);
|
||||
if (this.viewerCount > 0) {
|
||||
this.scheduleUpdate();
|
||||
} else {
|
||||
BlockState blockState = this.getCachedState();
|
||||
if (!(blockState.getBlock() instanceof BlockBarrel)) {
|
||||
this.markRemoved();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean bl = (Boolean) blockState.get(BarrelBlock.OPEN);
|
||||
if (bl) {
|
||||
this.playSound(blockState, SoundEvents.BLOCK_BARREL_CLOSE);
|
||||
this.setOpen(blockState, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onClose(PlayerEntity player) {
|
||||
if (!player.isSpectator()) {
|
||||
--this.viewerCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void setOpen(BlockState state, boolean open) {
|
||||
this.world.setBlockState(this.getPos(), (BlockState) state.with(BarrelBlock.OPEN, open), 3);
|
||||
}
|
||||
|
||||
private void playSound(BlockState blockState, SoundEvent soundEvent) {
|
||||
Vec3i vec3i = ((Direction) blockState.get(BarrelBlock.FACING)).getVector();
|
||||
double d = (double) this.pos.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
|
||||
double e = (double) this.pos.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
|
||||
double f = (double) this.pos.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
|
||||
this.world.playSound((PlayerEntity) null, d, e, f, soundEvent, SoundCategory.BLOCKS, 0.5F,
|
||||
this.world.random.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.block.entity.ChestBlockEntity;
|
||||
import ru.betterend.registry.BlockEntityRegistry;
|
||||
|
||||
public class EChestBlockEntity extends ChestBlockEntity {
|
||||
public EChestBlockEntity() {
|
||||
super(BlockEntityRegistry.CHEST);
|
||||
}
|
||||
}
|
168
src/main/java/ru/betterend/blocks/entities/ESignBlockEntity.java
Normal file
168
src/main/java/ru/betterend/blocks/entities/ESignBlockEntity.java
Normal file
|
@ -0,0 +1,168 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.server.command.CommandOutput;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.OrderedText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.Texts;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import ru.betterend.registry.BlockEntityRegistry;
|
||||
|
||||
public class ESignBlockEntity extends BlockEntity {
|
||||
private final Text[] text;
|
||||
private boolean editable;
|
||||
private PlayerEntity editor;
|
||||
private final OrderedText[] textBeingEdited;
|
||||
private DyeColor textColor;
|
||||
|
||||
public ESignBlockEntity() {
|
||||
super(BlockEntityRegistry.SIGN);
|
||||
this.text = new Text[] { LiteralText.EMPTY, LiteralText.EMPTY, LiteralText.EMPTY, LiteralText.EMPTY };
|
||||
this.editable = true;
|
||||
this.textBeingEdited = new OrderedText[4];
|
||||
this.textColor = DyeColor.BLACK;
|
||||
}
|
||||
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
String string = Text.Serializer.toJson(this.text[i]);
|
||||
tag.putString("Text" + (i + 1), string);
|
||||
}
|
||||
|
||||
tag.putString("Color", this.textColor.getName());
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
this.editable = false;
|
||||
super.fromTag(state, tag);
|
||||
this.textColor = DyeColor.byName(tag.getString("Color"), DyeColor.BLACK);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
String string = tag.getString("Text" + (i + 1));
|
||||
Text text = Text.Serializer.fromJson(string.isEmpty() ? "\"\"" : string);
|
||||
if (this.world instanceof ServerWorld) {
|
||||
try {
|
||||
this.text[i] = Texts.parse(this.getCommandSource((ServerPlayerEntity) null), text, (Entity) null,
|
||||
0);
|
||||
} catch (CommandSyntaxException var7) {
|
||||
this.text[i] = text;
|
||||
}
|
||||
} else {
|
||||
this.text[i] = text;
|
||||
}
|
||||
|
||||
this.textBeingEdited[i] = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setTextOnRow(int row, Text text) {
|
||||
this.text[row] = text;
|
||||
this.textBeingEdited[row] = null;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public OrderedText getTextBeingEditedOnRow(int row, Function<Text, OrderedText> function) {
|
||||
if (this.textBeingEdited[row] == null && this.text[row] != null) {
|
||||
this.textBeingEdited[row] = (OrderedText) function.apply(this.text[row]);
|
||||
}
|
||||
|
||||
return this.textBeingEdited[row];
|
||||
}
|
||||
|
||||
public BlockEntityUpdateS2CPacket toUpdatePacket() {
|
||||
return new BlockEntityUpdateS2CPacket(this.pos, 9, this.toInitialChunkDataTag());
|
||||
}
|
||||
|
||||
public CompoundTag toInitialChunkDataTag() {
|
||||
return this.toTag(new CompoundTag());
|
||||
}
|
||||
|
||||
public boolean copyItemDataRequiresOperator() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEditable() {
|
||||
return this.editable;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void setEditable(boolean bl) {
|
||||
this.editable = bl;
|
||||
if (!bl) {
|
||||
this.editor = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setEditor(PlayerEntity player) {
|
||||
this.editor = player;
|
||||
}
|
||||
|
||||
public PlayerEntity getEditor() {
|
||||
return this.editor;
|
||||
}
|
||||
|
||||
public boolean onActivate(PlayerEntity player) {
|
||||
Text[] var2 = this.text;
|
||||
int var3 = var2.length;
|
||||
|
||||
for (int var4 = 0; var4 < var3; ++var4) {
|
||||
Text text = var2[var4];
|
||||
Style style = text == null ? null : text.getStyle();
|
||||
if (style != null && style.getClickEvent() != null) {
|
||||
ClickEvent clickEvent = style.getClickEvent();
|
||||
if (clickEvent.getAction() == ClickEvent.Action.RUN_COMMAND) {
|
||||
player.getServer().getCommandManager().execute(this.getCommandSource((ServerPlayerEntity) player),
|
||||
clickEvent.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ServerCommandSource getCommandSource(ServerPlayerEntity player) {
|
||||
String string = player == null ? "Sign" : player.getName().getString();
|
||||
Text text = player == null ? new LiteralText("Sign") : player.getDisplayName();
|
||||
return new ServerCommandSource(CommandOutput.DUMMY, Vec3d.ofCenter(this.pos), Vec2f.ZERO,
|
||||
(ServerWorld) this.world, 2, string, (Text) text, this.world.getServer(), player);
|
||||
}
|
||||
|
||||
public DyeColor getTextColor() {
|
||||
return this.textColor;
|
||||
}
|
||||
|
||||
public boolean setTextColor(DyeColor value) {
|
||||
if (value != this.getTextColor()) {
|
||||
this.textColor = value;
|
||||
this.markDirty();
|
||||
this.world.updateListeners(this.getPos(), this.getCachedState(), this.getCachedState(), 3);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import net.minecraft.block.AbstractChestBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.ChestBlock;
|
||||
import net.minecraft.block.DoubleBlockProperties;
|
||||
import net.minecraft.block.DoubleBlockProperties.PropertySource;
|
||||
import net.minecraft.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.block.enums.ChestType;
|
||||
import net.minecraft.client.block.ChestAnimationProgress;
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.LightmapCoordinatesRetriever;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.BlockChest;
|
||||
import ru.betterend.blocks.entities.EChestBlockEntity;
|
||||
import ru.betterend.registry.ItemRegistry;
|
||||
|
||||
public class EChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlockEntity> {
|
||||
private static final HashMap<Integer, RenderLayer[]> LAYERS = Maps.newHashMap();
|
||||
private static RenderLayer[] 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 EChestBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||
super(blockEntityRenderDispatcher);
|
||||
|
||||
this.partC = new ModelPart(64, 64, 0, 19);
|
||||
this.partC.addCuboid(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F);
|
||||
this.partA = new ModelPart(64, 64, 0, 0);
|
||||
this.partA.addCuboid(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partA.pivotY = 9.0F;
|
||||
this.partA.pivotZ = 1.0F;
|
||||
this.partB = new ModelPart(64, 64, 0, 0);
|
||||
this.partB.addCuboid(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partB.pivotY = 8.0F;
|
||||
this.partRightC = new ModelPart(64, 64, 0, 19);
|
||||
this.partRightC.addCuboid(1.0F, 0.0F, 1.0F, 15.0F, 10.0F, 14.0F, 0.0F);
|
||||
this.partRightA = new ModelPart(64, 64, 0, 0);
|
||||
this.partRightA.addCuboid(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partRightA.pivotY = 9.0F;
|
||||
this.partRightA.pivotZ = 1.0F;
|
||||
this.partRightB = new ModelPart(64, 64, 0, 0);
|
||||
this.partRightB.addCuboid(15.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partRightB.pivotY = 8.0F;
|
||||
this.partLeftC = new ModelPart(64, 64, 0, 19);
|
||||
this.partLeftC.addCuboid(0.0F, 0.0F, 1.0F, 15.0F, 10.0F, 14.0F, 0.0F);
|
||||
this.partLeftA = new ModelPart(64, 64, 0, 0);
|
||||
this.partLeftA.addCuboid(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partLeftA.pivotY = 9.0F;
|
||||
this.partLeftA.pivotZ = 1.0F;
|
||||
this.partLeftB = new ModelPart(64, 64, 0, 0);
|
||||
this.partLeftB.addCuboid(0.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partLeftB.pivotY = 8.0F;
|
||||
}
|
||||
|
||||
public void render(EChestBlockEntity entity, float tickDelta, MatrixStack matrices,
|
||||
VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
||||
World world = entity.getWorld();
|
||||
boolean worldExists = world != null;
|
||||
BlockState blockState = worldExists ? entity.getCachedState()
|
||||
: (BlockState) Blocks.CHEST.getDefaultState().with(ChestBlock.FACING, Direction.SOUTH);
|
||||
ChestType chestType = blockState.contains(ChestBlock.CHEST_TYPE)
|
||||
? (ChestType) blockState.get(ChestBlock.CHEST_TYPE) : ChestType.SINGLE;
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock) {
|
||||
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
|
||||
boolean isDouble = chestType != ChestType.SINGLE;
|
||||
float f = ((Direction) blockState.get(ChestBlock.FACING)).asRotation();
|
||||
PropertySource<? extends ChestBlockEntity> propertySource;
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(0.5D, 0.5D, 0.5D);
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-f));
|
||||
matrices.translate(-0.5D, -0.5D, -0.5D);
|
||||
|
||||
if (worldExists) {
|
||||
propertySource = abstractChestBlock.getBlockEntitySource(blockState, world, entity.getPos(), true);
|
||||
} else {
|
||||
propertySource = DoubleBlockProperties.PropertyRetriever::getFallback;
|
||||
}
|
||||
|
||||
float pitch = ((Float2FloatFunction) propertySource
|
||||
.apply(ChestBlock.getAnimationProgressRetriever((ChestAnimationProgress) entity))).get(tickDelta);
|
||||
pitch = 1.0F - pitch;
|
||||
pitch = 1.0F - pitch * pitch * pitch;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
int blockLight = ((Int2IntFunction) propertySource.apply(new LightmapCoordinatesRetriever()))
|
||||
.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.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private void renderParts(MatrixStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2,
|
||||
ModelPart modelPart3, float pitch, int light, int overlay) {
|
||||
modelPart.pitch = -(pitch * 1.5707964F);
|
||||
modelPart2.pitch = modelPart.pitch;
|
||||
modelPart.render(matrices, vertices, light, overlay);
|
||||
modelPart2.render(matrices, vertices, light, overlay);
|
||||
modelPart3.render(matrices, vertices, light, overlay);
|
||||
}
|
||||
|
||||
private static RenderLayer getChestTexture(ChestType type, RenderLayer[] 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(VertexConsumerProvider provider, Block block, ChestType chestType) {
|
||||
RenderLayer[] layers = LAYERS.getOrDefault(Block.getRawIdFromState(block.getDefaultState()), defaultLayer);
|
||||
return provider.getBuffer(getChestTexture(chestType, layers));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = new RenderLayer[] {
|
||||
RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "entity/chest/normal.png")),
|
||||
RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "entity/chest/normal_left.png")),
|
||||
RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "entity/chest/normal_right.png"))
|
||||
};
|
||||
|
||||
ItemRegistry.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof BlockChest) {
|
||||
String name = Registry.BLOCK.getId(block).getPath();
|
||||
LAYERS.put(Block.getRawIdFromState(block.getDefaultState()), new RenderLayer[] {
|
||||
RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "textures/entity/chest/" + name + ".png")),
|
||||
RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "textures/entity/chest/" + name + "_left.png")),
|
||||
RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "textures/entity/chest/" + name + "_right.png"))
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.AbstractSignBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SignBlock;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.SignBlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.SignBlockEntityRenderer.SignModel;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.text.OrderedText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.SignType;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.BlockSign;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
import ru.betterend.registry.ItemRegistry;
|
||||
|
||||
public class ESignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEntity> {
|
||||
private static final HashMap<Integer, RenderLayer> LAYERS = Maps.newHashMap();
|
||||
private static RenderLayer defaultLayer;
|
||||
private final SignModel model = new SignBlockEntityRenderer.SignModel();
|
||||
|
||||
public ESignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
public void render(ESignBlockEntity signBlockEntity, float tickDelta, MatrixStack matrixStack,
|
||||
VertexConsumerProvider provider, int light, int overlay) {
|
||||
BlockState state = signBlockEntity.getCachedState();
|
||||
matrixStack.push();
|
||||
|
||||
matrixStack.translate(0.5D, 0.5D, 0.5D);
|
||||
float angle = -((float) ((Integer) state.get(SignBlock.ROTATION) * 360) / 16.0F);
|
||||
|
||||
BlockState blockState = signBlockEntity.getCachedState();
|
||||
if (blockState.get(BlockSign.FLOOR)) {
|
||||
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle));
|
||||
this.model.foot.visible = true;
|
||||
} else {
|
||||
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle + 180));
|
||||
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
||||
this.model.foot.visible = false;
|
||||
}
|
||||
|
||||
matrixStack.push();
|
||||
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
||||
model.field.render(matrixStack, vertexConsumer, light, overlay);
|
||||
model.foot.render(matrixStack, vertexConsumer, light, overlay);
|
||||
matrixStack.pop();
|
||||
TextRenderer textRenderer = dispatcher.getTextRenderer();
|
||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||
int m = signBlockEntity.getTextColor().getSignColor();
|
||||
int n = (int) (NativeImage.getRed(m) * 0.4D);
|
||||
int o = (int) (NativeImage.getGreen(m) * 0.4D);
|
||||
int p = (int) (NativeImage.getBlue(m) * 0.4D);
|
||||
int q = NativeImage.getAbgrColor(0, p, o, n);
|
||||
|
||||
for (int s = 0; s < 4; ++s) {
|
||||
OrderedText orderedText = signBlockEntity.getTextBeingEditedOnRow(s, (text) -> {
|
||||
List<OrderedText> list = textRenderer.wrapLines(text, 90);
|
||||
return list.isEmpty() ? OrderedText.EMPTY : (OrderedText) list.get(0);
|
||||
});
|
||||
if (orderedText != null) {
|
||||
float t = (float) (-textRenderer.getWidth(orderedText) / 2);
|
||||
textRenderer.draw((OrderedText) orderedText, t, (float) (s * 10 - 20), q, false,
|
||||
matrixStack.peek().getModel(), provider, false, 0, light);
|
||||
}
|
||||
}
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
|
||||
public static SpriteIdentifier getModelTexture(Block block) {
|
||||
SignType signType2;
|
||||
if (block instanceof AbstractSignBlock) {
|
||||
signType2 = ((AbstractSignBlock) block).getSignType();
|
||||
} else {
|
||||
signType2 = SignType.OAK;
|
||||
}
|
||||
|
||||
return TexturedRenderLayers.getSignTextureId(signType2);
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(VertexConsumerProvider provider, Block block) {
|
||||
return provider.getBuffer(LAYERS.getOrDefault(Block.getRawIdFromState(block.getDefaultState()), defaultLayer));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "entity/chest/normal.png"));
|
||||
|
||||
ItemRegistry.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof BlockSign) {
|
||||
String name = Registry.BLOCK.getId(block).getPath();
|
||||
RenderLayer layer = RenderLayer.getEntitySolid(new Identifier(BetterEnd.MOD_ID, "textures/entity/sign/" + name + ".png"));
|
||||
LAYERS.put(Block.getRawIdFromState(block.getDefaultState()), layer);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue