More wooden materials, gui, mixins, registries

This commit is contained in:
paulevsGitch 2020-09-26 16:36:48 +03:00
parent 6ec2b53edd
commit 720103bd45
97 changed files with 2414 additions and 14 deletions

View 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());
}
}
}
}

View file

@ -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;
}
}

View 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;
}
}

View file

@ -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()));
}
}

View 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;
}
}

View 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;
}
}