More wooden materials, gui, mixins, registries
This commit is contained in:
parent
6ec2b53edd
commit
720103bd45
97 changed files with 2414 additions and 14 deletions
85
src/main/java/ru/betterend/blocks/basis/BlockBarrel.java
Normal file
85
src/main/java/ru/betterend/blocks/basis/BlockBarrel.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.BarrelBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.mob.PiglinBrain;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.entities.EBarrelBlockEntity;
|
||||
import ru.betterend.registry.BlockEntityRegistry;
|
||||
|
||||
public class BlockBarrel extends BarrelBlock {
|
||||
public BlockBarrel(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).nonOpaque());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView world) {
|
||||
return BlockEntityRegistry.BARREL.instantiate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
List<ItemStack> drop = super.getDroppedStacks(state, builder);
|
||||
drop.add(new ItemStack(this.asItem()));
|
||||
return drop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
if (world.isClient) {
|
||||
return ActionResult.SUCCESS;
|
||||
} else {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EBarrelBlockEntity) {
|
||||
player.openHandledScreen((EBarrelBlockEntity) blockEntity);
|
||||
player.incrementStat(Stats.OPEN_BARREL);
|
||||
PiglinBrain.onGuardedBlockInteracted(player, true);
|
||||
}
|
||||
|
||||
return ActionResult.CONSUME;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EBarrelBlockEntity) {
|
||||
((EBarrelBlockEntity) blockEntity).tick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer,
|
||||
ItemStack itemStack) {
|
||||
if (itemStack.hasCustomName()) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EBarrelBlockEntity) {
|
||||
((EBarrelBlockEntity) blockEntity).setCustomName(itemStack.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
||||
public class BlockBaseNotFull extends BlockBase {
|
||||
|
||||
public BlockBaseNotFull(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
public boolean canSuffocate(BlockState state, BlockView view, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSimpleFullBlock(BlockState state, BlockView view, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean allowsSpawning(BlockState state, BlockView view, BlockPos pos, EntityType<?> type) {
|
||||
return false;
|
||||
}
|
||||
}
|
36
src/main/java/ru/betterend/blocks/basis/BlockChest.java
Normal file
36
src/main/java/ru/betterend/blocks/basis/BlockChest.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ChestBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.world.BlockView;
|
||||
import ru.betterend.registry.BlockEntityRegistry;
|
||||
|
||||
public class BlockChest extends ChestBlock
|
||||
{
|
||||
public BlockChest(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).nonOpaque(), () -> {
|
||||
return BlockEntityRegistry.CHEST;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView world)
|
||||
{
|
||||
return BlockEntityRegistry.CHEST.instantiate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder)
|
||||
{
|
||||
List<ItemStack> drop = super.getDroppedStacks(state, builder);
|
||||
drop.add(new ItemStack(this.asItem()));
|
||||
return drop;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.CraftingTableBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
|
||||
public class BlockCraftingTable extends CraftingTableBlock
|
||||
{
|
||||
public BlockCraftingTable(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this.asItem()));
|
||||
}
|
||||
}
|
134
src/main/java/ru/betterend/blocks/basis/BlockLadder.java
Normal file
134
src/main/java/ru/betterend/blocks/basis/BlockLadder.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class BlockLadder extends BlockBaseNotFull implements IRenderTypeable {
|
||||
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
||||
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
|
||||
protected static final VoxelShape EAST_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);
|
||||
protected static final VoxelShape WEST_SHAPE = Block.createCuboidShape(13.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);
|
||||
protected static final VoxelShape SOUTH_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D);
|
||||
protected static final VoxelShape NORTH_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D);
|
||||
|
||||
public BlockLadder(Block block) {
|
||||
super(FabricBlockSettings.copyOf(block).nonOpaque());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(FACING);
|
||||
stateManager.add(WATERLOGGED);
|
||||
}
|
||||
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
switch (state.get(FACING)) {
|
||||
case NORTH:
|
||||
return NORTH_SHAPE;
|
||||
case SOUTH:
|
||||
return SOUTH_SHAPE;
|
||||
case WEST:
|
||||
return WEST_SHAPE;
|
||||
case EAST:
|
||||
default:
|
||||
return EAST_SHAPE;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canPlaceOn(BlockView world, BlockPos pos, Direction side) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
return !blockState.emitsRedstonePower() && blockState.isSideSolidFullSquare(world, pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
Direction direction = (Direction) state.get(FACING);
|
||||
return this.canPlaceOn(world, pos.offset(direction.getOpposite()), direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState,
|
||||
WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (facing.getOpposite() == state.get(FACING) && !state.canPlaceAt(world, pos)) {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
} else {
|
||||
if ((Boolean) state.get(WATERLOGGED)) {
|
||||
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
|
||||
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
BlockState blockState2;
|
||||
if (!ctx.canReplaceExisting()) {
|
||||
blockState2 = ctx.getWorld().getBlockState(ctx.getBlockPos().offset(ctx.getSide().getOpposite()));
|
||||
if (blockState2.getBlock() == this && blockState2.get(FACING) == ctx.getSide()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
blockState2 = this.getDefaultState();
|
||||
WorldView worldView = ctx.getWorld();
|
||||
BlockPos blockPos = ctx.getBlockPos();
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
|
||||
Direction[] var6 = ctx.getPlacementDirections();
|
||||
int var7 = var6.length;
|
||||
|
||||
for (int var8 = 0; var8 < var7; ++var8) {
|
||||
Direction direction = var6[var8];
|
||||
if (direction.getAxis().isHorizontal()) {
|
||||
blockState2 = (BlockState) blockState2.with(FACING, direction.getOpposite());
|
||||
if (blockState2.canPlaceAt(worldView, blockPos)) {
|
||||
return (BlockState) blockState2.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, BlockRotation rotation) {
|
||||
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, BlockMirror mirror) {
|
||||
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return (Boolean) state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.CUTOUT;
|
||||
}
|
||||
}
|
143
src/main/java/ru/betterend/blocks/basis/BlockSign.java
Normal file
143
src/main/java/ru/betterend/blocks/basis/BlockSign.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.AbstractSignBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.DyeItem;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SignType;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
|
||||
public class BlockSign extends AbstractSignBlock {
|
||||
public static final IntProperty ROTATION = Properties.ROTATION;
|
||||
public static final BooleanProperty FLOOR = BooleanProperty.of("floor");
|
||||
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {
|
||||
Block.createCuboidShape(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
|
||||
Block.createCuboidShape(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
|
||||
Block.createCuboidShape(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
|
||||
Block.createCuboidShape(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D) };
|
||||
|
||||
public BlockSign(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).noCollision().nonOpaque(), SignType.OAK);
|
||||
this.setDefaultState(
|
||||
this.stateManager.getDefaultState().with(ROTATION, 0).with(FLOOR, true).with(WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(ROTATION, FLOOR, WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
return state.get(FLOOR) ? SHAPE : WALL_SHAPES[state.get(ROTATION) >> 2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView world) {
|
||||
return new ESignBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
ItemStack itemStack = player.getStackInHand(hand);
|
||||
boolean bl = itemStack.getItem() instanceof DyeItem && player.abilities.allowModifyWorld;
|
||||
if (world.isClient) {
|
||||
return bl ? ActionResult.SUCCESS : ActionResult.CONSUME;
|
||||
} else {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof ESignBlockEntity) {
|
||||
ESignBlockEntity signBlockEntity = (ESignBlockEntity) blockEntity;
|
||||
if (bl) {
|
||||
boolean bl2 = signBlockEntity.setTextColor(((DyeItem) itemStack.getItem()).getColor());
|
||||
if (bl2 && !player.isCreative()) {
|
||||
itemStack.decrement(1);
|
||||
}
|
||||
}
|
||||
return signBlockEntity.onActivate(player) ? ActionResult.SUCCESS : ActionResult.PASS;
|
||||
} else {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer,
|
||||
ItemStack itemStack) {
|
||||
if (placer != null && placer instanceof PlayerEntity) {
|
||||
ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos);
|
||||
if (!world.isClient) {
|
||||
sign.setEditor((PlayerEntity) placer);
|
||||
((ServerPlayerEntity) placer).networkHandler.sendPacket(new SignEditorOpenS2CPacket(pos));
|
||||
} else
|
||||
sign.setEditable(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState,
|
||||
WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if ((Boolean) state.get(WATERLOGGED)) {
|
||||
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
|
||||
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
if (ctx.getSide() == Direction.UP) {
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
|
||||
return this.getDefaultState().with(FLOOR, true)
|
||||
.with(ROTATION, MathHelper.floor((180.0 + ctx.getPlayerYaw() * 16.0 / 360.0) + 0.5 - 12) & 15)
|
||||
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
} else if (ctx.getSide() != Direction.DOWN) {
|
||||
BlockState blockState = this.getDefaultState();
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
|
||||
WorldView worldView = ctx.getWorld();
|
||||
BlockPos blockPos = ctx.getBlockPos();
|
||||
Direction[] directions = ctx.getPlacementDirections();
|
||||
Direction[] var7 = directions;
|
||||
int var8 = directions.length;
|
||||
|
||||
for (int var9 = 0; var9 < var8; ++var9) {
|
||||
Direction direction = var7[var9];
|
||||
if (direction.getAxis().isHorizontal()) {
|
||||
Direction direction2 = direction.getOpposite();
|
||||
int rot = MathHelper.floor((180.0 + direction2.asRotation() * 16.0 / 360.0) + 0.5 + 4) & 15;
|
||||
blockState = blockState.with(ROTATION, rot);
|
||||
if (blockState.canPlaceAt(worldView, blockPos)) {
|
||||
return blockState.with(FLOOR, false).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -5,13 +5,18 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.item.Items;
|
||||
import ru.betterend.blocks.basis.BlockBarrel;
|
||||
import ru.betterend.blocks.basis.BlockBase;
|
||||
import ru.betterend.blocks.basis.BlockChest;
|
||||
import ru.betterend.blocks.basis.BlockCraftingTable;
|
||||
import ru.betterend.blocks.basis.BlockDoor;
|
||||
import ru.betterend.blocks.basis.BlockFence;
|
||||
import ru.betterend.blocks.basis.BlockGate;
|
||||
import ru.betterend.blocks.basis.BlockLadder;
|
||||
import ru.betterend.blocks.basis.BlockLogStripable;
|
||||
import ru.betterend.blocks.basis.BlockPillar;
|
||||
import ru.betterend.blocks.basis.BlockPressurePlate;
|
||||
import ru.betterend.blocks.basis.BlockSign;
|
||||
import ru.betterend.blocks.basis.BlockSlab;
|
||||
import ru.betterend.blocks.basis.BlockStairs;
|
||||
import ru.betterend.blocks.basis.BlockTrapdoor;
|
||||
|
@ -38,12 +43,12 @@ public class WoodenMaterial
|
|||
public final Block trapdoor;
|
||||
public final Block door;
|
||||
|
||||
//public final Block crafting_table;
|
||||
//public final Block ladder;
|
||||
//public final Block sign;
|
||||
public final Block crafting_table;
|
||||
public final Block ladder;
|
||||
public final Block sign;
|
||||
|
||||
//public final Block chest;
|
||||
//public final Block barrel;
|
||||
public final Block chest;
|
||||
public final Block barrel;
|
||||
|
||||
public WoodenMaterial(String name, MaterialColor woodColor, MaterialColor planksColor)
|
||||
{
|
||||
|
@ -65,14 +70,14 @@ public class WoodenMaterial
|
|||
trapdoor = BlockRegistry.registerBlock(name + "_trapdoor", new BlockTrapdoor(planks));
|
||||
door = BlockRegistry.registerBlock(name + "_door", new BlockDoor(planks));
|
||||
|
||||
//crafting_table = BlockRegistry.registerBlock("crafting_table_" + name, planks);
|
||||
//ladder = BlockRegistry.registerBlock(name + "_ladder", planks);
|
||||
//sign = BlockRegistry.registerBlock("sign_" + name, planks);
|
||||
crafting_table = BlockRegistry.registerBlock(name + "_crafting_table", new BlockCraftingTable(planks));
|
||||
ladder = BlockRegistry.registerBlock(name + "_ladder", new BlockLadder(planks));
|
||||
sign = BlockRegistry.registerBlock(name + "_sign", new BlockSign(planks));
|
||||
|
||||
//chest = BlockRegistry.registerBlock("chest_" + name, planks);
|
||||
//barrel = BlockRegistry.registerBlock("barrel_" + name, planks, planks_slab);
|
||||
chest = BlockRegistry.registerBlock(name + "_chest", new BlockChest(planks));
|
||||
barrel = BlockRegistry.registerBlock(name + "_barrel", new BlockBarrel(planks));
|
||||
|
||||
RecipeBuilder.make(name + "_planks", planks).setOutputCount(4).setList("#").addMaterial('#', log, bark).setGroup("end_planks").build();
|
||||
RecipeBuilder.make(name + "_planks", planks).setOutputCount(4).setList("#").addMaterial('#', log, bark, log_striped, bark_striped).setGroup("end_planks").build();
|
||||
RecipeBuilder.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', planks).setGroup("end_planks_stairs").build();
|
||||
RecipeBuilder.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', planks).setGroup("end_planks_slabs").build();
|
||||
RecipeBuilder.make(name + "_fence", fence).setOutputCount(3).setShape("#I#", "#I#").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_planks_fences").build();
|
||||
|
@ -81,6 +86,11 @@ public class WoodenMaterial
|
|||
RecipeBuilder.make(name + "_pressure_plate", pressure_plate).setList("##").addMaterial('#', planks).setGroup("end_planks_plates").build();
|
||||
RecipeBuilder.make(name + "_trapdoor", trapdoor).setOutputCount(2).setShape("###", "###").addMaterial('#', planks).setGroup("end_trapdoors").build();
|
||||
RecipeBuilder.make(name + "_door", door).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', planks).setGroup("end_doors").build();
|
||||
RecipeBuilder.make(name + "_crafting_table", crafting_table).setShape("##", "##").addMaterial('#', planks).setGroup("end_tables").build();
|
||||
RecipeBuilder.make(name + "_ladder", ladder).setOutputCount(3).setShape("I I", "I#I", "I I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_ladders").build();
|
||||
RecipeBuilder.make(name + "_sign", sign).setOutputCount(3).setShape("###", "###", " I ").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_signs").build();
|
||||
RecipeBuilder.make(name + "_chest", chest).setShape("###", "# #", "###").addMaterial('#', planks).setGroup("end_chests").build();
|
||||
RecipeBuilder.make(name + "_barrel", barrel).setShape("#S#", "# #", "#S#").addMaterial('#', planks).addMaterial('S', slab).setGroup("end_barrels").build();
|
||||
}
|
||||
|
||||
public boolean isTreeLog(Block block)
|
||||
|
|
|
@ -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