Items and Blocks registries (WIP)
This commit is contained in:
parent
41df84404b
commit
a3e781b401
34 changed files with 313 additions and 1771 deletions
|
@ -1,138 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.BarrelBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.basis.EndBarrelBlock;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EBarrelBlockEntity extends RandomizableContainerBlockEntity {
|
||||
private NonNullList<ItemStack> inventory;
|
||||
private int viewerCount;
|
||||
|
||||
private EBarrelBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
this.inventory = NonNullList.withSize(27, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public EBarrelBlockEntity() {
|
||||
this(EndBlockEntities.BARREL);
|
||||
}
|
||||
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
super.save(tag);
|
||||
if (!this.trySaveLootTable(tag)) {
|
||||
ContainerHelper.saveAllItems(tag, this.inventory);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void load(BlockState state, CompoundTag tag) {
|
||||
super.load(state, tag);
|
||||
this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||
if (!this.tryLoadLootTable(tag)) {
|
||||
ContainerHelper.loadAllItems(tag, this.inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public int getContainerSize() {
|
||||
return 27;
|
||||
}
|
||||
|
||||
protected NonNullList<ItemStack> getItems() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
protected void setItems(NonNullList<ItemStack> list) {
|
||||
this.inventory = list;
|
||||
}
|
||||
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent("container.barrel");
|
||||
}
|
||||
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return ChestMenu.threeRows(syncId, playerInventory, this);
|
||||
}
|
||||
|
||||
public void startOpen(Player player) {
|
||||
if (!player.isSpectator()) {
|
||||
if (this.viewerCount < 0) {
|
||||
this.viewerCount = 0;
|
||||
}
|
||||
|
||||
++this.viewerCount;
|
||||
BlockState blockState = this.getBlockState();
|
||||
boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN);
|
||||
if (!bl) {
|
||||
this.playSound(blockState, SoundEvents.BARREL_OPEN);
|
||||
this.setOpen(blockState, true);
|
||||
}
|
||||
|
||||
this.scheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleUpdate() {
|
||||
this.level.getBlockTicks().scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), 5);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
int i = this.worldPosition.getX();
|
||||
int j = this.worldPosition.getY();
|
||||
int k = this.worldPosition.getZ();
|
||||
this.viewerCount = ChestBlockEntity.getOpenCount(this.level, this, i, j, k);
|
||||
if (this.viewerCount > 0) {
|
||||
this.scheduleUpdate();
|
||||
} else {
|
||||
BlockState blockState = this.getBlockState();
|
||||
if (!(blockState.getBlock() instanceof EndBarrelBlock)) {
|
||||
this.setRemoved();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN);
|
||||
if (bl) {
|
||||
this.playSound(blockState, SoundEvents.BARREL_CLOSE);
|
||||
this.setOpen(blockState, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopOpen(Player player) {
|
||||
if (!player.isSpectator()) {
|
||||
--this.viewerCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void setOpen(BlockState state, boolean open) {
|
||||
this.level.setBlock(this.getBlockPos(), (BlockState) state.setValue(BarrelBlock.OPEN, open), 3);
|
||||
}
|
||||
|
||||
private void playSound(BlockState blockState, SoundEvent soundEvent) {
|
||||
Vec3i vec3i = ((Direction) blockState.getValue(BarrelBlock.FACING)).getNormal();
|
||||
double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
|
||||
double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
|
||||
double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
|
||||
this.level.playSound((Player) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F,
|
||||
this.level.random.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EChestBlockEntity extends ChestBlockEntity {
|
||||
public EChestBlockEntity() {
|
||||
super(EndBlockEntities.CHEST);
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.FurnaceMenu;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EFurnaceBlockEntity extends AbstractFurnaceBlockEntity {
|
||||
public EFurnaceBlockEntity() {
|
||||
super(EndBlockEntities.FURNACE, RecipeType.SMELTING);
|
||||
}
|
||||
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent("container.furnace");
|
||||
}
|
||||
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return new FurnaceMenu(syncId, playerInventory, this, this.dataAccess);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class ESignBlockEntity extends SignBlockEntity {
|
||||
public ESignBlockEntity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<?> getType() {
|
||||
return EndBlockEntities.SIGN;
|
||||
}
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
package ru.betterend.blocks.entities.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.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.item.BlockItem;
|
||||
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.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndChestBlock;
|
||||
import ru.betterend.blocks.entities.EChestBlockEntity;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlockEntity> {
|
||||
private static final HashMap<Block, RenderType[]> LAYERS = Maps.newHashMap();
|
||||
private static 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 EndChestBlockEntityRenderer(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(EChestBlockEntity 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));
|
||||
}
|
||||
|
||||
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"))
|
||||
};
|
||||
|
||||
EndItems.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof EndChestBlock) {
|
||||
String name = Registry.BLOCK.getKey(block).getPath();
|
||||
LAYERS.put(block, new RenderType[] {
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + ".png")),
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_left.png")),
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_right.png"))
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
package ru.betterend.blocks.entities.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.item.BlockItem;
|
||||
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.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndSignBlock;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndSignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEntity> {
|
||||
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
||||
private static RenderType defaultLayer;
|
||||
private final SignModel model = new SignRenderer.SignModel();
|
||||
|
||||
public EndSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
public void render(ESignBlockEntity 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) ((Integer) state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F);
|
||||
|
||||
BlockState blockState = signBlockEntity.getBlockState();
|
||||
if (blockState.getValue(EndSignBlock.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 : (FormattedCharSequence) list.get(0);
|
||||
});
|
||||
if (orderedText != null) {
|
||||
float t = (float) (-textRenderer.width(orderedText) / 2);
|
||||
textRenderer.drawInBatch((FormattedCharSequence) 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));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/sign/oak.png"));
|
||||
|
||||
EndItems.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof EndSignBlock) {
|
||||
String name = Registry.BLOCK.getKey(block).getPath();
|
||||
RenderType layer = RenderType.entitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png"));
|
||||
LAYERS.put(block, layer);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.EternalPedestal;
|
||||
import ru.betterend.blocks.basis.PedestalBlock;
|
||||
import ru.betterend.blocks.entities.PedestalBlockEntity;
|
||||
import ru.betterend.client.render.BeamRenderer;
|
||||
import ru.betterend.client.render.EndCrystalRenderer;
|
||||
import ru.betterend.client.render.EternalCrystalRenderer;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEntityRenderer<T> {
|
||||
|
||||
public PedestalItemRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(T blockEntity, float tickDelta, PoseStack matrices,
|
||||
MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
|
||||
Level world = blockEntity.getLevel();
|
||||
if (world == null || blockEntity.isEmpty()) return;
|
||||
|
||||
BlockState state = world.getBlockState(blockEntity.getBlockPos());
|
||||
if (!(state.getBlock() instanceof PedestalBlock)) return;
|
||||
|
||||
ItemStack activeItem = blockEntity.getItem(0);
|
||||
|
||||
matrices.pushPose();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null);
|
||||
Vector3f translate = model.getTransforms().ground.translation;
|
||||
PedestalBlock pedestal = (PedestalBlock) state.getBlock();
|
||||
matrices.translate(translate.x(), translate.y(), translate.z());
|
||||
matrices.translate(0.5, pedestal.getHeight(state), 0.5);
|
||||
if (activeItem.getItem() instanceof BlockItem) {
|
||||
matrices.scale(1.5F, 1.5F, 1.5F);
|
||||
} else {
|
||||
matrices.scale(1.25F, 1.25F, 1.25F);
|
||||
}
|
||||
int age = blockEntity.getAge();
|
||||
if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) {
|
||||
float[] colors = EternalCrystalRenderer.colors(age);
|
||||
int y = blockEntity.getBlockPos().getY();
|
||||
|
||||
BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F, 0.16F);
|
||||
float altitude = Mth.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F;
|
||||
matrices.translate(0.0D, altitude, 0.0D);
|
||||
}
|
||||
if (activeItem.getItem() == Items.END_CRYSTAL) {
|
||||
EndCrystalRenderer.render(age, blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light);
|
||||
} else if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) {
|
||||
EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light);
|
||||
} else {
|
||||
float rotation = (age + tickDelta) / 25.0F + 6.0F;
|
||||
matrices.mulPose(Vector3f.YP.rotation(rotation));
|
||||
minecraft.getItemRenderer().render(activeItem, ItemTransforms.TransformType.GROUND, false, matrices, vertexConsumers, light, overlay, model);
|
||||
}
|
||||
matrices.popPose();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue