78 lines
2.9 KiB
Java
78 lines
2.9 KiB
Java
package ru.betterend.blocks;
|
|
|
|
import java.io.Reader;
|
|
import java.util.EnumMap;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.Registry;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import ru.betterend.blocks.basis.AttachedBlock;
|
|
import ru.betterend.client.render.ERenderLayer;
|
|
import ru.betterend.interfaces.IRenderTypeable;
|
|
import ru.betterend.patterns.BlockPatterned;
|
|
import ru.betterend.patterns.Patterns;
|
|
|
|
public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, BlockPatterned {
|
|
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
|
|
|
|
public ChandelierBlock(Block source) {
|
|
super(FabricBlockSettings.copyOf(source).luminance(15).noCollission().noOcclusion().requiresCorrectToolForDrops());
|
|
}
|
|
|
|
@Override
|
|
public ERenderLayer getRenderLayer() {
|
|
return ERenderLayer.CUTOUT;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
|
return BOUNDING_SHAPES.get(state.getValue(FACING));
|
|
}
|
|
|
|
@Override
|
|
public String getStatesPattern(Reader data) {
|
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
|
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
|
|
}
|
|
|
|
@Override
|
|
public String getModelPattern(String block) {
|
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
|
if (block.contains("item")) {
|
|
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath());
|
|
}
|
|
else if (block.contains("ceil")) {
|
|
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_CEIL, blockId.getPath());
|
|
}
|
|
else if (block.contains("wall")) {
|
|
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_WALL, blockId.getPath());
|
|
}
|
|
else {
|
|
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_FLOOR, blockId.getPath());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResourceLocation statePatternId() {
|
|
return Patterns.STATE_CHANDELIER;
|
|
}
|
|
|
|
static {
|
|
BOUNDING_SHAPES.put(Direction.UP, Block.box(5, 0, 5, 11, 13, 11));
|
|
BOUNDING_SHAPES.put(Direction.DOWN, Block.box(5, 3, 5, 11, 16, 11));
|
|
BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.0, 0.0, 0.5, 1.0, 1.0, 1.0));
|
|
BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.0, 0.0, 0.0, 1.0, 1.0, 0.5));
|
|
BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.0, 0.0, 1.0, 1.0, 1.0));
|
|
BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0));
|
|
}
|
|
}
|