Версия Minecraft
1.20.1
API
Fabric
Всем привет, пытался создать сундук в сообественном моде, но почему то не правильно работает рендер и логика сундука, сундук не отображается, не открывается и соотвественно не показывает инвентраь, помогите решить данную проблему, сейчас скину все файлы что есть связанные с сундуком
ModBlocks:
public static final Block NORM1AL_ACACIA_PLANKS_COLORED = registerBlock(
"norm1al_acacia_planks_colored",
new AcaciaColoredChestBlock(AbstractBlock.Settings.copy(Blocks.CHEST))
);

ModItemGroups:
entries.add(ModBlocks.NORM1AL_ACACIA_PLANKS_COLORED);

modBlocks/AcaciaColoredChestBlock:
package farllands.farllands_deco.modBlocks;

import farllands.farllands_deco.blockentity.ModBlockEntities;
import net.minecraft.block.Block;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Waterloggable;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

import java.util.function.Supplier;

public class AcaciaColoredChestBlock extends ChestBlock implements Waterloggable {

public AcaciaColoredChestBlock(Settings settings) {
super(settings, () -> ModBlockEntities.ACACIA_COLORED_CHEST);

// Можно оставить — тут мы лишь выставляем дефолтные значения.
this.setDefaultState(
this.stateManager.getDefaultState()
.with(Properties.HORIZONTAL_FACING, net.minecraft.util.math.Direction.NORTH)
.with(ChestBlock.CHEST_TYPE, net.minecraft.block.enums.ChestType.SINGLE)
.with(Properties.WATERLOGGED, false)
);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
}

@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(
World world, BlockState state, BlockEntityType<T> type
) {
return world.isClient
? ChestBlock.checkType(type, ModBlockEntities.ACACIA_COLORED_CHEST, ChestBlockEntity::clientTick)
: null;
}

@Override
public boolean hasComparatorOutput(BlockState state) {
return true; // как обычный сундук
}

@Override
public int getComparatorOutput(BlockState state, net.minecraft.world.World world, BlockPos pos) {
return net.minecraft.screen.ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos));
}
}

blockentity/AcaciaColoredChestBlockEntity:
package farllands.farllands_deco.blockentity;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.block.entity.BlockEntityType;

public class AcaciaColoredChestBlockEntity extends ChestBlockEntity {
public AcaciaColoredChestBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.ACACIA_COLORED_CHEST, pos, state);
}
}

blockentity/ModBlockEntities:
package farllands.farllands_deco.blockentity;

import farllands.farllands_deco.modBlocks.ModBlocks;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

public class ModBlockEntities {
public static final BlockEntityType<AcaciaColoredChestBlockEntity> ACACIA_COLORED_CHEST =
Registry.register(
Registries.BLOCK_ENTITY_TYPE,
new Identifier("farllands_deco", "norm1al_acacia_planks_colored"),
BlockEntityType.Builder.create(AcaciaColoredChestBlockEntity::new, ModBlocks.NORM1AL_ACACIA_PLANKS_COLORED).build(null)
);

public static void init() { /* вызывать из onInitialize() */ }
}

client/render/AcaciaColoredChestRenderer:
package farllands.farllands_deco.client.render;

import com.mojang.blaze3d.systems.RenderSystem;
import farllands.farllands_deco.blockentity.AcaciaColoredChestBlockEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.enums.ChestType;
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.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Direction;
import net.minecraft.client.render.TexturedRenderLayers;


public class AcaciaColoredChestRenderer implements BlockEntityRenderer<AcaciaColoredChestBlockEntity> {

// наши текстуры (ВАЖНО: имена совпадают с png)
private static final Identifier SINGLE_TEX = new Identifier("farllands_deco", "entity/chest/norm1al_acacia_planks_colored");
private static final Identifier LEFT_TEX = new Identifier("farllands_deco", "entity/chest/normal_1left_acacia_planks_colored");
private static final Identifier RIGHT_TEX = new Identifier("farllands_deco", "entity/chest/normal_1right_acacia_planks_colored");

// те же текстуры, но как спрайты из CHEST-атласа
private static final SpriteIdentifier SINGLE_SPRITE = new SpriteIdentifier(TexturedRenderLayers.CHEST_ATLAS_TEXTURE, SINGLE_TEX);
private static final SpriteIdentifier LEFT_SPRITE = new SpriteIdentifier(TexturedRenderLayers.CHEST_ATLAS_TEXTURE, LEFT_TEX);
private static final SpriteIdentifier RIGHT_SPRITE = new SpriteIdentifier(TexturedRenderLayers.CHEST_ATLAS_TEXTURE, RIGHT_TEX);

// модели крышки/замка/дна для single и double (left/right)
private final ModelPart singleLid;
private final ModelPart singleLatch;
private final ModelPart singleBase;

private final ModelPart leftLid;
private final ModelPart leftLatch;
private final ModelPart leftBase;

private final ModelPart rightLid;
private final ModelPart rightLatch;
private final ModelPart rightBase;

public AcaciaColoredChestRenderer(BlockEntityRendererFactory.Context ctx) {
ModelPart singleRoot = ctx.getLayerModelPart(EntityModelLayers.CHEST);
this.singleLid = singleRoot.getChild("lid");
this.singleLatch = singleRoot.getChild("lock");
this.singleBase = singleRoot.getChild("bottom");

ModelPart leftRoot = ctx.getLayerModelPart(EntityModelLayers.DOUBLE_CHEST_LEFT);
this.leftLid = leftRoot.getChild("lid");
this.leftLatch = leftRoot.getChild("lock");
this.leftBase = leftRoot.getChild("bottom");

ModelPart rightRoot = ctx.getLayerModelPart(EntityModelLayers.DOUBLE_CHEST_RIGHT);
this.rightLid = rightRoot.getChild("lid");
this.rightLatch = rightRoot.getChild("lock");
this.rightBase = rightRoot.getChild("bottom");
}

@Override
public void render(AcaciaColoredChestBlockEntity be, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcp, int light, int overlay) {
BlockState state = be.getCachedState();
ChestType type = state.get(ChestBlock.CHEST_TYPE);
Direction facing = state.get(ChestBlock.FACING);

// берём угол открытия как в ванили
float open = be.getAnimationProgress(tickDelta);
open = 1.0F - open;
open = 1.0F - open * open * open; // ease

matrices.push();
matrices.translate(0.5, 0.5, 0.5);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-facing.asRotation()));
matrices.translate(-0.5, -0.5, -0.5);

ModelPart lid, latch, base;
SpriteIdentifier sprite;

if (type == ChestType.LEFT) {
lid = leftLid; latch = leftLatch; base = leftBase; sprite = LEFT_SPRITE;
} else if (type == ChestType.RIGHT) {
lid = rightLid; latch = rightLatch; base = rightBase; sprite = RIGHT_SPRITE;
} else {
lid = singleLid; latch = singleLatch; base = singleBase; sprite = SINGLE_SPRITE;
}

lid.pitch = -(open * 1.5707964F); // PI/2
latch.pitch = lid.pitch;

VertexConsumer vc = sprite.getVertexConsumer(vcp, RenderLayer::getEntityCutout);
base.render(matrices, vc, light, overlay);
lid.render(matrices, vc, light, overlay);
latch.render(matrices, vc, light, overlay);

matrices.pop();
}
}

client/decoClient:
BlockEntityRendererFactories.register(ModBlockEntities.ACACIA_COLORED_CHEST, AcaciaColoredChestRenderer::new);

loot_tables/blocks/chest:
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{ "type": "minecraft:item", "name": "farllands_deco:norm1al_acacia_planks_colored" }
],
"conditions": [
{ "condition": "minecraft:survives_explosion" }
]
}
]
}

в некоторых файлых я прислал просто строки связанные с сундуком, помогите пожалуйста
еще добавлю что у меня три текстуры сундука, основная, правая и левая, для сдвоенного сундука
Подскажите пожалуйста что нужно исправить или что еще найти
Снизу прикрепил фотографии кодов для удобства
 

Вложения

  • AcaciaColoredChestBlockEntity.java
    462 байт · Просмотры: 0
  • ModBlockEntities.java
    819 байт · Просмотры: 1
  • AcaciaColoredChestBlock.java
    2.2 KB · Просмотры: 0
  • ModBlocks.java
    74.2 KB · Просмотры: 0
  • ModItemGroups.java
    33.6 KB · Просмотры: 0
  • norm1al_acacia_planks_colored.json
    301 байт · Просмотры: 0
  • Farllands_decoClient.java
    1.8 KB · Просмотры: 0
  • AcaciaColoredChestRenderer.java
    5 KB · Просмотры: 0
Назад
Сверху