Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -1,45 +1,45 @@
package ru.betterend.blocks.basis;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.BlockMirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import ru.betterend.util.BlocksHelper;
public abstract class AttachedBlock extends BlockBaseNotFull {
public static final DirectionProperty FACING = Properties.FACING;
public AttachedBlock(net.minecraft.world.level.block.state.BlockBehaviour.Properties settings) {
public static final DirectionProperty FACING = BlockStateProperties.FACING;
public AttachedBlock(Properties settings) {
super(settings);
this.setDefaultState(this.defaultBlockState().with(FACING, Direction.UP));
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.UP));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(FACING);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
BlockState blockState = this.defaultBlockState();
WorldView worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos();
Direction[] directions = ctx.getPlacementDirections();
LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getClickedPos();
Direction[] directions = ctx.getNearestLookingDirections();
for (int i = 0; i < directions.length; ++i) {
Direction direction = directions[i];
Direction direction2 = direction.getOpposite();
blockState = (BlockState) blockState.with(FACING, direction2);
if (blockState.canPlaceAt(worldView, blockPos)) {
blockState = (BlockState) blockState.setValue(FACING, direction2);
if (blockState.canSurvive(worldView, blockPos)) {
return blockState;
}
}
@ -47,30 +47,30 @@ public abstract class AttachedBlock extends BlockBaseNotFull {
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
Direction direction = (Direction) state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite());
return sideCoversSmallSquare(world, blockPos, direction)
|| world.getBlockState(blockPos).isIn(BlockTags.LEAVES);
return canSupportCenter(world, blockPos, direction) || world.getBlockState(blockPos).is(BlockTags.LEAVES);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
}
}

View file

@ -1,28 +1,27 @@
package ru.betterend.blocks.basis;
import java.io.Reader;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.patterns.Patterns;
public class BarkBlock extends EndPillarBlock {
public BarkBlock(Properties settings) {
super(settings);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, getName(blockId), blockId.getPath());
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, getName(blockId), blockId.getPath());
}
private String getName(ResourceLocation blockId) {
String name = blockId.getPath();
return name.replace("_bark", "_log_side");

View file

@ -2,24 +2,23 @@ package ru.betterend.blocks.basis;
import java.util.Collections;
import java.util.List;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.BlockWithEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
public class BaseBlockWithEntity extends BlockWithEntity {
public class BaseBlockWithEntity extends BaseEntityBlock {
public BaseBlockWithEntity(Properties settings) {
super(settings);
}
@Override
public BlockEntity createBlockEntity(BlockView world) {
public BlockEntity newBlockEntity(BlockGetter world) {
return null;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));

View file

@ -3,10 +3,9 @@ package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections;
import java.util.List;
import net.minecraft.core.Registry;
import net.minecraft.world.item.ItemStack;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
@ -17,24 +16,24 @@ public class BlockBase extends Block implements BlockPatterned {
public BlockBase(Properties settings) {
super(settings);
}
@Override
public List<ItemStack> getDrops(BlockState blockState, LootContext.Builder builder) {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;

View file

@ -1,9 +1,9 @@
package ru.betterend.blocks.basis;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.EntityType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
public class BlockBaseNotFull extends BlockBase {
@ -11,15 +11,15 @@ public class BlockBaseNotFull extends BlockBase {
super(settings);
}
public boolean canSuffocate(BlockState state, BlockView view, BlockPos pos) {
public boolean canSuffocate(BlockState state, BlockGetter view, BlockPos pos) {
return false;
}
public boolean isSimpleFullBlock(BlockState state, BlockView view, BlockPos pos) {
public boolean isSimpleFullBlock(BlockState state, BlockGetter view, BlockPos pos) {
return false;
}
public boolean allowsSpawning(BlockState state, BlockView view, BlockPos pos, EntityType<?> type) {
public boolean allowsSpawning(BlockState state, BlockGetter view, BlockPos pos, EntityType<?> type) {
return false;
}
}

View file

@ -7,143 +7,147 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.AbstractBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Fertilizable;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.registry.EndTags;
import ru.betterend.util.BlocksHelper;
public class DoublePlantBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable {
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 2, 4, 12, 16, 12);
public class DoublePlantBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12);
public static final IntegerProperty ROTATION = BlockProperties.ROTATION;
public static final BooleanProperty TOP = BooleanProperty.of("top");
public static final BooleanProperty TOP = BooleanProperty.create("top");
public DoublePlantBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS)
.breakByHand(true).noCollision());
this.setDefaultState(this.stateManager.defaultBlockState().with(TOP, false));
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
}
public DoublePlantBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS)
.luminance((state) -> {
return state.getValue(TOP) ? light : 0;
}).breakByHand(true).noCollision());
this.setDefaultState(this.stateManager.defaultBlockState().with(TOP, false));
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.lightLevel((state) -> state.getValue(TOP) ? light : 0)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(TOP, ROTATION);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos);
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3 vec3d = state.getOffset(view, pos);
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.XZ;
public BlockBehaviour.OffsetType getOffsetType() {
return BlockBehaviour.OffsetType.XZ;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below());
BlockState up = world.getBlockState(pos.up());
BlockState up = world.getBlockState(pos.above());
return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getMaterial().isReplaceable());
}
public boolean canStayAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canStayAt(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below());
BlockState up = world.getBlockState(pos.up());
BlockState up = world.getBlockState(pos.above());
return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getBlock() == this);
}
protected boolean isTerrain(BlockState state) {
return state.isIn(EndTags.END_GROUND);
return state.is(EndTags.END_GROUND);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canStayAt(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(TOP)) {
return Lists.newArrayList();
}
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
} else {
}
else {
return Lists.newArrayList();
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) {
return true;
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return true;
}
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
new ItemStack(this));
world.spawnEntity(item);
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
world.addFreshEntity(item);
}
@Override
public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
int rot = world.random.nextInt(4);
BlockState bs = this.defaultBlockState().with(ROTATION, rot);
BlockState bs = this.defaultBlockState().setValue(ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, pos, bs);
BlocksHelper.setWithoutUpdate(world, pos.up(), bs.with(TOP, true));
BlocksHelper.setWithoutUpdate(world, pos.above(), bs.setValue(TOP, true));
}
}

View file

@ -8,17 +8,17 @@ import java.util.Map;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.AnvilBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
@ -26,37 +26,37 @@ import ru.betterend.patterns.Patterns;
public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
protected final int level;
public EndAnvilBlock(MaterialColor color, int level) {
super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(color));
this.level = level;
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(DESTRUCTION);
}
public IntegerProperty getDESTRUCTION() {
public IntegerProperty getDestructionProperty() {
return DESTRUCTION;
}
public int getCraftingLevel() {
return level;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@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);
@ -73,7 +73,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
char last = block.charAt(block.length() - 1);
return blockId.getPath() + "_top_" + last;
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_ANVIL;

View file

@ -5,26 +5,26 @@ import java.util.List;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.BarrelBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BlockRenderType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.mob.PiglinBrain;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.stat.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.piglin.PiglinAi;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BarrelBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.BlockHitResult;
import ru.betterend.blocks.entities.EBarrelBlockEntity;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
@ -32,12 +32,12 @@ import ru.betterend.registry.EndBlockEntities;
public class EndBarrelBlock extends BarrelBlock implements BlockPatterned {
public EndBarrelBlock(Block source) {
super(FabricBlockSettings.copyOf(source).nonOpaque());
super(FabricBlockSettings.copyOf(source).noOcclusion());
}
@Override
public BlockEntity createBlockEntity(BlockView world) {
return EndBlockEntities.BARREL.instantiate();
public BlockEntity newBlockEntity(BlockGetter world) {
return EndBlockEntities.BARREL.create();
}
@Override
@ -48,24 +48,24 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned {
}
@Override
public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand,
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
BlockHitResult hit) {
if (world.isClientSide) {
return ActionResult.SUCCESS;
return InteractionResult.SUCCESS;
} else {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof EBarrelBlockEntity) {
player.openHandledScreen((EBarrelBlockEntity) blockEntity);
player.incrementStat(Stats.OPEN_BARREL);
PiglinBrain.onGuardedBlockInteracted(player, true);
player.openMenu((EBarrelBlockEntity) blockEntity);
player.awardStat(Stats.OPEN_BARREL);
PiglinAi.angerNearbyPiglins(player, true);
}
return ActionResult.CONSUME;
return InteractionResult.CONSUME;
}
}
@Override
public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof EBarrelBlockEntity) {
((EBarrelBlockEntity) blockEntity).tick();
@ -73,26 +73,27 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned {
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}
@Override
public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (itemStack.hasCustomName()) {
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer,
ItemStack itemStack) {
if (itemStack.hasCustomHoverName()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof EBarrelBlockEntity) {
((EBarrelBlockEntity) blockEntity).setCustomName(itemStack.getName());
((EBarrelBlockEntity) blockEntity).setCustomName(itemStack.getHoverName());
}
}
}
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
String texture = Registry.BLOCK.getKey(this).getPath();
@ -101,7 +102,7 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned {
}
return Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BARREL;

View file

@ -2,42 +2,40 @@ package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.entity.player.Player;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
public class EndBlockStripableLogLog extends EndPillarBlock {
private final Block striped;
public EndBlockStripableLogLog(MaterialColor color, Block striped) {
super(FabricBlockSettings.copyOf(striped).materialColor(color));
this.striped = striped;
}
@Override
public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand,
BlockHitResult hit) {
if (player.getMainHandStack().getItem().isIn(FabricToolTags.AXES)) {
world.playLocalSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (player.getMainHandItem().getItem().is(FabricToolTags.AXES)) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlockAndUpdate(pos, striped.defaultBlockState().with(RotatedPillarBlock.AXIS,
state.getValue(RotatedPillarBlock.AXIS)), 11);
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
if (player != null && !player.isCreative()) {
player.getMainHandStack().damage(1, world.random, (ServerPlayer) player);
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}
}
return ActionResult.SUCCESS;
return InteractionResult.SUCCESS;
}
return ActionResult.FAIL;
return InteractionResult.FAIL;
}
}

View file

@ -5,23 +5,23 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.patterns.Patterns;
public class EndBookshelfBlock extends BlockBase {
public EndBookshelfBlock(Block source) {
super(FabricBlockSettings.copyOf(source));
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@ -33,24 +33,24 @@ public class EndBookshelfBlock extends BlockBase {
}
return Collections.singletonList(new ItemStack(Items.BOOK, 3));
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BOOKSHELF, getName(blockId), blockId.getPath());
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, getName(blockId), blockId.getPath());
}
private String getName(ResourceLocation blockId) {
String name = blockId.getPath();
return name.replace("_bookshelf", "");

View file

@ -5,14 +5,14 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChainBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned;
@ -22,18 +22,18 @@ public class EndChainBlock extends ChainBlock implements BlockPatterned, IRender
public EndChainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.CHAIN).materialColor(color));
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@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);
@ -42,12 +42,12 @@ public class EndChainBlock extends ChainBlock implements BlockPatterned, IRender
}
return Patterns.createJson(Patterns.BLOCK_CHAIN, blockId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_CHAIN;
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;

View file

@ -4,48 +4,50 @@ import java.io.Reader;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
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.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.world.level.BlockGetter;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
import ru.betterend.registry.EndBlockEntities;
public class EndChestBlock extends ChestBlock implements BlockPatterned {
private final Block parent;
public EndChestBlock(Block source) {
super(FabricBlockSettings.copyOf(source).nonOpaque(), () -> {
super(FabricBlockSettings.copyOf(source).noOcclusion(), () -> {
return EndBlockEntities.CHEST;
});
this.parent = source;
}
@Override
public BlockEntity createBlockEntity(BlockView world) {
return EndBlockEntities.CHEST.instantiate();
public BlockEntity newBlockEntity(BlockGetter world)
{
return EndBlockEntities.CHEST.create();
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder)
{
List<ItemStack> drop = super.getDrops(state, builder);
drop.add(new ItemStack(this.asItem()));
return drop;
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String path) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -55,7 +57,7 @@ public class EndChestBlock extends ChestBlock implements BlockPatterned {
}
return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;

View file

@ -5,13 +5,13 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
@ -19,25 +19,25 @@ public class EndComposterBlock extends ComposterBlock implements BlockPatterned
public EndComposterBlock(Block source) {
super(FabricBlockSettings.copyOf(source));
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this.asItem()));
}
@Override
public String getStatesPattern(Reader data) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, blockId, blockId);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
String blockName = blockId.getPath();
return Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockName);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_COMPOSTER;

View file

@ -6,13 +6,13 @@ import java.util.HashMap;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.CraftingTableBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CraftingTableBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
@ -25,13 +25,13 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPa
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this.asItem()));
}
@Override
public String getStatesPattern(Reader data) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, blockId, blockId);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -49,7 +49,7 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPa
}
});
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;

View file

@ -8,59 +8,63 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.AbstractBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class EndCropBlock extends EndPlantBlock {
private static final VoxelShape SHAPE = Block.createCuboidShape(2, 0, 2, 14, 14, 14);
public static final IntegerProperty AGE = IntegerProperty.of("age", 0, 3);
private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14);
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
private final Block[] terrain;
private final Item drop;
public EndCropBlock(Item drop, Block... terrain) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.HOES).sounds(SoundType.GRASS)
.breakByHand(true).ticksRandomly().noCollision());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.HOES)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
this.drop = drop;
this.terrain = terrain;
this.setDefaultState(getDefaultState().with(AGE, 0));
this.registerDefaultState(defaultBlockState().setValue(AGE, 0));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(AGE);
}
@Override
protected boolean isTerrain(BlockState state) {
for (Block block : terrain) {
for (Block block: terrain) {
if (state.is(block)) {
return true;
}
}
return false;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(AGE) < 3) {
@ -79,40 +83,40 @@ public class EndCropBlock extends EndPlantBlock {
int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM);
return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops));
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE;
public BlockBehaviour.OffsetType getOffsetType() {
return BlockBehaviour.OffsetType.NONE;
}
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
int age = state.getValue(AGE);
if (age < 3) {
BlocksHelper.setWithUpdate(world, pos, state.with(AGE, age + 1));
BlocksHelper.setWithUpdate(world, pos, state.setValue(AGE, age + 1));
}
}
@Override
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) {
return state.getValue(AGE) < 3;
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return state.getValue(AGE) < 3;
}
@Override
public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.scheduledTick(state, world, pos, random);
if (canGrow(world, random, pos, state) && random.nextInt(8) == 0) {
grow(world, random, pos, state);
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (isBonemealSuccess(world, random, pos, state) && random.nextInt(8) == 0) {
performBonemeal(world, random, pos, state);
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE;
}
}

View file

@ -5,14 +5,14 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.enums.DoubleBlockHalf;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned;
@ -20,7 +20,7 @@ import ru.betterend.patterns.Patterns;
public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPatterned {
public EndDoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3F, 3F).nonOpaque());
super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion());
}
@Override
@ -35,13 +35,13 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPat
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public String getStatesPattern(Reader data) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, blockId, blockId);
}
@Override
public String getModelPattern(String block) {
String blockId = Registry.BLOCK.getKey(this).getPath();
@ -59,7 +59,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPat
}
return Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockId, blockId);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_DOOR;

View file

@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndFenceBlock extends FenceBlock implements BlockPatterned {
private final Block parent;
public EndFenceBlock(Block source) {
super(FabricBlockSettings.copyOf(source).nonOpaque());
super(FabricBlockSettings.copyOf(source).noOcclusion());
this.parent = source;
}
@ -27,14 +27,14 @@ public class EndFenceBlock extends FenceBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -47,7 +47,7 @@ public class EndFenceBlock extends FenceBlock implements BlockPatterned {
}
return Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_FENCE;

View file

@ -8,21 +8,21 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.FurnaceBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.stat.Stats;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.stats.Stats;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FurnaceBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.betterend.blocks.entities.EFurnaceBlockEntity;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
@ -31,31 +31,31 @@ import ru.betterend.patterns.Patterns;
public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRenderTypeable {
public EndFurnaceBlock(Block source) {
super(FabricBlockSettings.copyOf(source).luminance((state) -> {
super(FabricBlockSettings.copyOf(source).lightLevel((state) -> {
return state.getValue(LIT) ? 13 : 0;
}));
}
@Override
public BlockEntity createBlockEntity(BlockView world) {
public BlockEntity newBlockEntity(BlockGetter world) {
return new EFurnaceBlockEntity();
}
@Override
protected void openScreen(Level world, BlockPos pos, Player player) {
protected void openContainer(Level world, BlockPos pos, Player player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof EFurnaceBlockEntity) {
player.openHandledScreen((NamedScreenHandlerFactory) blockEntity);
player.incrementStat(Stats.INTERACT_WITH_FURNACE);
player.openMenu((MenuProvider) blockEntity);
player.awardStat(Stats.INTERACT_WITH_FURNACE);
}
}
@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);
@ -66,12 +66,13 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRe
map.put("%front%", blockId.getPath() + "_front_on");
map.put("%glow%", blockId.getPath() + "_glow");
return Patterns.createJson(Patterns.BLOCK_FURNACE_GLOW, map);
} else {
}
else {
map.put("%front%", blockId.getPath() + "_front");
return Patterns.createJson(Patterns.BLOCK_FURNACE, map);
}
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_FURNACE;
@ -81,15 +82,15 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRe
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drop = Lists.newArrayList(new ItemStack(this));
BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY);
BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof EFurnaceBlockEntity) {
EFurnaceBlockEntity entity = (EFurnaceBlockEntity) blockEntity;
for (int i = 0; i < entity.size(); i++) {
drop.add(entity.getStack(i));
for (int i = 0; i < entity.getContainerSize(); i++) {
drop.add(entity.getItem(i));
}
}
return drop;

View file

@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndGateBlock extends FenceGateBlock implements BlockPatterned {
private final Block parent;
public EndGateBlock(Block source) {
super(FabricBlockSettings.copyOf(source).nonOpaque());
super(FabricBlockSettings.copyOf(source).noOcclusion());
this.parent = source;
}
@ -27,14 +27,14 @@ public class EndGateBlock extends FenceGateBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -51,7 +51,7 @@ public class EndGateBlock extends FenceGateBlock implements BlockPatterned {
}
return Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_GATE;

View file

@ -3,28 +3,28 @@ package ru.betterend.blocks.basis;
import java.io.Reader;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalFacingBlock;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.level.block.state.StateDefinition;
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.world.level.block.Rotation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned;
@ -32,15 +32,15 @@ import ru.betterend.patterns.Patterns;
import ru.betterend.util.BlocksHelper;
public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, BlockPatterned {
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 static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape EAST_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);
protected static final VoxelShape WEST_SHAPE = Block.box(13.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);
protected static final VoxelShape SOUTH_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D);
protected static final VoxelShape NORTH_SHAPE = Block.box(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D);
public EndLadderBlock(Block block) {
super(FabricBlockSettings.copyOf(block).nonOpaque());
super(FabricBlockSettings.copyOf(block).noOcclusion());
}
@Override
@ -49,7 +49,7 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
stateManager.add(WATERLOGGED);
}
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
switch (state.getValue(FACING)) {
case SOUTH:
return SOUTH_SHAPE;
@ -62,25 +62,25 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
}
}
private boolean canPlaceOn(BlockView world, BlockPos pos, Direction side) {
private boolean canPlaceOn(BlockGetter world, BlockPos pos, Direction side) {
BlockState blockState = world.getBlockState(pos);
return !blockState.emitsRedstonePower() && blockState.isSideSolidFullSquare(world, pos, side);
return !blockState.isSignalSource() && blockState.isFaceSturdy(world, pos, side);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
Direction direction = (Direction) state.getValue(FACING);
return this.canPlaceOn(world, pos.relative(direction.getOpposite()), direction);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (facing.getOpposite() == state.getValue(FACING) && !state.canPlaceAt(world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState,
LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (facing.getOpposite() == state.getValue(FACING) && !state.canSurvive(world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
if ((Boolean) state.getValue(WATERLOGGED)) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
return super.updateShape(state, facing, neighborState, world, pos, neighborPos);
@ -88,28 +88,28 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
BlockState blockState2;
if (!ctx.canReplaceExisting()) {
blockState2 = ctx.getLevel().getBlockState(ctx.getBlockPos().offset(ctx.getSide().getOpposite()));
if (blockState2.getBlock() == this && blockState2.get(FACING) == ctx.getSide()) {
if (!ctx.replacingClickedOnBlock()) {
blockState2 = ctx.getLevel().getBlockState(ctx.getClickedPos().relative(ctx.getClickedFace().getOpposite()));
if (blockState2.getBlock() == this && blockState2.getValue(FACING) == ctx.getClickedFace()) {
return null;
}
}
blockState2 = this.defaultBlockState();
WorldView worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos();
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getBlockPos());
Direction[] var6 = ctx.getPlacementDirections();
LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getClickedPos();
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
Direction[] var6 = ctx.getNearestLookingDirections();
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);
blockState2 = (BlockState) blockState2.setValue(FACING, direction.getOpposite());
if (blockState2.canSurvive(worldView, blockPos)) {
return (BlockState) blockState2.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}
}
@ -123,26 +123,26 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
}
@Override
public FluidState getFluidState(BlockState state) {
return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public String getStatesPattern(Reader data) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, blockId, blockId);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -151,7 +151,7 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
}
return Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_LADDER;

View file

@ -1,110 +1,119 @@
package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FluidFillable;
import net.minecraft.world.level.block.Waterloggable;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import ru.betterend.blocks.BlockProperties;
public class EndLanternBlock extends BlockBaseNotFull implements Waterloggable, FluidFillable {
public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer {
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public EndLanternBlock(Block source) {
this(FabricBlockSettings.copyOf(source).luminance(15).nonOpaque());
this(FabricBlockSettings.copyOf(source).luminance(15).noOcclusion());
}
public EndLanternBlock(FabricBlockSettings settings) {
super(settings.nonOpaque());
public EndLanternBlock(Properties settings) {
super(settings.noOcclusion());
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(IS_FLOOR, WATERLOGGED);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
WorldView worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos();
Direction dir = ctx.getSide();
boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER;
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getClickedPos();
Direction dir = ctx.getClickedFace();
boolean water = worldView.getFluidState(blockPos).getType() == Fluids.WATER;
if (dir != Direction.DOWN && dir != Direction.UP) {
if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
} else if (sideCoversSmallSquare(worldView, blockPos.below(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
} else {
if (canSupportCenter(worldView, blockPos.above(), Direction.DOWN)) {
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
}
else if (canSupportCenter(worldView, blockPos.below(), Direction.UP)) {
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
}
else {
return null;
}
} else if (dir == Direction.DOWN) {
if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
} else if (sideCoversSmallSquare(worldView, blockPos.below(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
} else {
}
else if (dir == Direction.DOWN) {
if (canSupportCenter(worldView, blockPos.above(), Direction.DOWN)) {
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
}
else if (canSupportCenter(worldView, blockPos.below(), Direction.UP)) {
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
}
else {
return null;
}
} else {
if (sideCoversSmallSquare(worldView, blockPos.below(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
} else if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
} else {
}
else {
if (canSupportCenter(worldView, blockPos.below(), Direction.UP)) {
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
}
else if (canSupportCenter(worldView, blockPos.above(), Direction.DOWN)) {
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
}
else {
return null;
}
}
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
if (state.getValue(IS_FLOOR)) {
return sideCoversSmallSquare(world, pos.below(), Direction.UP);
} else {
return sideCoversSmallSquare(world, pos.up(), Direction.DOWN);
return canSupportCenter(world, pos.below(), Direction.UP);
}
else {
return canSupportCenter(world, pos.above(), Direction.DOWN);
}
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
Boolean water = state.getValue(WATERLOGGED);
if (water) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
if (!canPlaceAt(state, world, pos)) {
if (!canSurvive(state, world, pos)) {
return water ? Blocks.WATER.defaultBlockState() : Blocks.AIR.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
return false;
}
@Override
public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
return false;
}
@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState();
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
}
}

View file

@ -8,18 +8,18 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned;
@ -28,57 +28,58 @@ import ru.betterend.util.MHelper;
public class EndLeavesBlock extends LeavesBlock implements BlockPatterned, IRenderTypeable {
private final Block sapling;
public EndLeavesBlock(Block sapling, MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning((state, world, pos, type) -> {
return false;
}).suffocates((state, world, pos) -> {
return false;
}).blockVision((state, world, pos) -> {
return false;
}).materialColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true));
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.materialColor(color)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
this.sapling = sapling;
}
public EndLeavesBlock(Block sapling, MaterialColor color, int light) {
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning((state, world, pos, type) -> {
return false;
}).suffocates((state, world, pos) -> {
return false;
}).blockVision((state, world, pos) -> {
return false;
}).materialColor(color).luminance(light).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS));
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.materialColor(color)
.luminance(light)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
this.sapling = sapling;
}
@Override
public String getStatesPattern(Reader data) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, blockId, blockId);
}
@Override
public String getModelPattern(String block) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(Patterns.BLOCK_BASE, blockId, blockId);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) {
if (tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this));
}
int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool);

View file

@ -7,35 +7,35 @@ import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.PaneBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.IronBarsBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndMetalPaneBlock extends PaneBlock implements BlockPatterned, IRenderTypeable {
public class EndMetalPaneBlock extends IronBarsBlock implements BlockPatterned, IRenderTypeable {
public EndMetalPaneBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).nonOpaque());
super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion());
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@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);
@ -44,24 +44,25 @@ public class EndMetalPaneBlock extends PaneBlock implements BlockPatterned, IRen
}
if (block.contains("post")) {
return Patterns.createJson(Patterns.BLOCK_BARS_POST, blockId.getPath(), blockId.getPath());
} else {
}
else {
return Patterns.createJson(Patterns.BLOCK_BARS_SIDE, blockId.getPath(), blockId.getPath());
}
}
@Environment(EnvType.CLIENT)
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) {
if (direction.getAxis().isVertical() && stateFrom.getBlock().is(this) && !stateFrom.equals(state)) {
return false;
}
return super.isSideInvisible(state, stateFrom, direction);
return super.skipRendering(state, stateFrom, direction);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BARS;
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;

View file

@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.WeightedPressurePlateBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeightedPressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements BlockPatterned {
private final Block parent;
public EndMetalPlateBlock(Block source) {
super(15, FabricBlockSettings.copyOf(source).noCollision().nonOpaque().requiresTool().strength(0.5F));
super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F));
this.parent = source;
}
@ -27,14 +27,14 @@ public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements Bl
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -44,7 +44,7 @@ public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements Bl
}
return Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_PLATE;

View file

@ -6,20 +6,20 @@ import java.util.List;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.OreBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.OreBlock;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.core.Registry;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
import ru.betterend.util.MHelper;
@ -29,18 +29,21 @@ public class EndOreBlock extends OreBlock implements BlockPatterned {
private final int minCount;
private final int maxCount;
private final int expirience;
public EndOreBlock(Item drop, int minCount, int maxCount, int expirience) {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND).hardness(3F).resistance(9F).requiresTool()
.sounds(SoundType.STONE));
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.hardness(3F)
.resistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE));
this.dropItem = drop;
this.minCount = minCount;
this.maxCount = maxCount;
this.expirience = expirience;
}
@Override
protected int getExperienceWhenMined(Random random) {
protected int xpOnDrop(Random random) {
return this.expirience > 0 ? random.nextInt(expirience) + 1 : 0;
}
@ -67,19 +70,19 @@ public class EndOreBlock extends OreBlock implements BlockPatterned {
}
return Collections.emptyList();
}
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;

View file

@ -5,13 +5,13 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
@ -19,28 +19,28 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockPatterned
public EndPillarBlock(Properties settings) {
super(settings);
}
public EndPillarBlock(Block block) {
super(FabricBlockSettings.copyOf(block));
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, texture, texture);
}
@Override
public String getModelPattern(String block) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(Patterns.BLOCK_PILLAR, texture, texture);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_PILLAR;

View file

@ -7,120 +7,125 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.AbstractBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Fertilizable;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.registry.EndTags;
public class EndPlantBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable {
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 14, 12);
public class EndPlantBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public EndPlantBlock() {
this(false);
}
public EndPlantBlock(int light) {
this(false, light);
}
public EndPlantBlock(boolean replaceable) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).breakByHand(true).noCollision());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
public EndPlantBlock(boolean replaceable, int light) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).luminance(light).breakByHand(true)
.noCollision());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
}
public EndPlantBlock(Properties settings) {
super(settings);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos);
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3 vec3d = state.getOffset(view, pos);
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.XZ;
public BlockBehaviour.OffsetType getOffsetType() {
return BlockBehaviour.OffsetType.XZ;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below());
return isTerrain(down);
}
protected boolean isTerrain(BlockState state) {
return state.isIn(EndTags.END_GROUND);
return state.is(EndTags.END_GROUND);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
} else {
}
else {
return Lists.newArrayList();
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) {
return true;
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return true;
}
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
new ItemStack(this));
world.spawnEntity(item);
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
world.addFreshEntity(item);
}
}

View file

@ -4,57 +4,62 @@ import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.BlockProperties;
public abstract class EndPlantWithAgeBlock extends EndPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE;
public EndPlantWithAgeBlock() {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
.breakByHand(true).ticksRandomly().noCollision());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
}
public EndPlantWithAgeBlock(FabricBlockSettings settings) {
public EndPlantWithAgeBlock(Properties settings) {
super(settings);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(AGE);
}
public abstract void growAdult(WorldGenLevel world, Random random, BlockPos pos);
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
int age = state.getValue(AGE);
if (age < 3) {
world.setBlockAndUpdate(pos, state.with(AGE, age + 1));
} else {
world.setBlockAndUpdate(pos, state.setValue(AGE, age + 1));
}
else {
growAdult(world, random, pos);
}
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return true;
}
@Override
public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.scheduledTick(state, world, pos, random);
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (random.nextInt(8) == 0) {
grow(world, random, pos, state);
performBonemeal(world, random, pos, state);
}
}
}

View file

@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned {
private final Block parent;
public EndPlateBlock(ActivationRule rule, Block source) {
super(rule, FabricBlockSettings.copyOf(source).noCollision().nonOpaque().strength(0.5F));
public EndPlateBlock(Sensitivity rule, Block source) {
super(rule, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().strength(0.5F));
this.parent = source;
}
@ -27,14 +27,14 @@ public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -44,9 +44,9 @@ public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned
}
return Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return this.stateManager.getProperty("facing") != null ? Patterns.STATE_PLATE_ROTATED : Patterns.STATE_PLATE;
return this.stateDefinition.getProperty("facing") != null ? Patterns.STATE_PLATE_ROTATED : Patterns.STATE_PLATE;
}
}

View file

@ -5,39 +5,39 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.SignBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.SignType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SignBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.blocks.entities.ESignBlockEntity;
import ru.betterend.interfaces.ISpetialItem;
import ru.betterend.patterns.BlockPatterned;
@ -45,20 +45,20 @@ import ru.betterend.patterns.Patterns;
import ru.betterend.util.BlocksHelper;
public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialItem {
public static final IntegerProperty ROTATION = Properties.ROTATION;
public static final BooleanProperty FLOOR = BooleanProperty.of("floor");
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final BooleanProperty FLOOR = BooleanProperty.create("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) };
Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)
};
private final Block parent;
public EndSignBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollision().nonOpaque(), SignType.OAK);
this.setDefaultState(
this.stateManager.defaultBlockState().with(ROTATION, 0).with(FLOOR, false).with(WATERLOGGED, false));
super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK);
this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false));
this.parent = source;
}
@ -68,72 +68,74 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return state.getValue(FLOOR) ? SHAPE : WALL_SHAPES[state.getValue(ROTATION) >> 2];
}
@Override
public BlockEntity createBlockEntity(BlockView world) {
public BlockEntity newBlockEntity(BlockGetter world) {
return new ESignBlockEntity();
}
@Override
public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (placer != null && placer instanceof Player) {
ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos);
if (!world.isClientSide) {
sign.setEditor((Player) placer);
((ServerPlayer) placer).networkHandler.sendPacket(new SignEditorOpenS2CPacket(pos));
} else {
sign.setAllowedPlayerEditor((Player) placer);
((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos));
}
else {
sign.setEditable(true);
}
}
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if ((Boolean) state.getValue(WATERLOGGED)) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
if (!canPlaceAt(state, world, pos)) {
return state.getValue(WATERLOGGED) ? state.getFluidState().getBlockState() : Blocks.AIR.defaultBlockState();
if (!canSurvive(state, world, pos)) {
return state.getValue(WATERLOGGED) ? state.getFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState();
}
return super.updateShape(state, facing, neighborState, world, pos, neighborPos);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
if (!state.getValue(FLOOR)) {
int index = (((state.getValue(ROTATION) >> 2) + 2)) & 3;
return world.getBlockState(pos.relative(BlocksHelper.HORIZONTAL[index])).getMaterial().isSolid();
} else {
}
else {
return world.getBlockState(pos.below()).getMaterial().isSolid();
}
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
if (ctx.getSide() == Direction.UP) {
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getBlockPos());
return this.defaultBlockState().with(FLOOR, true)
.with(ROTATION, Mth.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) {
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
if (ctx.getClickedFace() == Direction.UP) {
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
return this.defaultBlockState().setValue(FLOOR, true)
.setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15)
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
else if (ctx.getClickedFace() != Direction.DOWN) {
BlockState blockState = this.defaultBlockState();
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getBlockPos());
WorldView worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos();
Direction[] directions = ctx.getPlacementDirections();
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getClickedPos();
Direction[] directions = ctx.getNearestLookingDirections();
for (int i = 0; i < directions.length; ++i) {
Direction direction = directions[i];
if (direction.getAxis().isHorizontal()) {
Direction dir = direction.getOpposite();
int rot = Mth.floor((180.0 + dir.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);
int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15;
blockState = blockState.setValue(ROTATION, rot);
if (blockState.canSurvive(worldView, blockPos)) {
return blockState.setValue(FLOOR, false).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}
}
@ -141,14 +143,14 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI
return null;
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String path) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
@ -157,41 +159,41 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI
}
return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override
public BlockState rotate(BlockState state, Rotation rotation) {
return (BlockState) state.with(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16));
return (BlockState) state.setValue(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16));
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return (BlockState) state.with(ROTATION, mirror.mirror((Integer) state.getValue(ROTATION), 16));
public BlockState mirror(BlockState state, Mirror mirror) {
return (BlockState) state.setValue(ROTATION, mirror.mirror((Integer) state.getValue(ROTATION), 16));
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public Fluid tryDrainFluid(LevelAccessor world, BlockPos pos, BlockState state) {
public Fluid takeLiquid(LevelAccessor world, BlockPos pos, BlockState state) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
// TODO Auto-generated method stub
return false;
}

View file

@ -5,19 +5,19 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndSlabBlock extends SlabBlock implements BlockPatterned {
private final Block parent;
public EndSlabBlock(Block source) {
super(FabricBlockSettings.copyOf(source));
this.parent = source;
@ -27,21 +27,21 @@ public class EndSlabBlock extends SlabBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SLAB;

View file

@ -5,38 +5,37 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.StairsBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndStairsBlock extends StairsBlock implements BlockPatterned {
public class EndStairsBlock extends StairBlock implements BlockPatterned {
private final Block parent;
public EndStairsBlock(Block source) {
super(source.defaultBlockState(), FabricBlockSettings.copyOf(source));
this.parent = source;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -49,7 +48,7 @@ public class EndStairsBlock extends StairsBlock implements BlockPatterned {
}
return Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_STAIRS;

View file

@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.StoneButtonBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.StoneButtonBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatterned {
private final Block parent;
public EndStoneButtonBlock(Block source) {
super(FabricBlockSettings.copyOf(source).nonOpaque());
super(FabricBlockSettings.copyOf(source).noOcclusion());
this.parent = source;
}
@ -27,14 +27,14 @@ public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatter
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -47,7 +47,7 @@ public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatter
}
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BUTTON;

View file

@ -4,6 +4,6 @@ import net.minecraft.world.level.block.Block;
public class EndStonelateBlock extends EndPlateBlock {
public EndStonelateBlock(Block source) {
super(ActivationRule.MOBS, source);
super(Sensitivity.MOBS, source);
}
}

View file

@ -6,39 +6,39 @@ import java.util.HashMap;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.TrapdoorBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndTrapdoorBlock extends TrapdoorBlock implements IRenderTypeable, BlockPatterned {
public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable, BlockPatterned {
public EndTrapdoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).nonOpaque());
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion());
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -51,7 +51,7 @@ public class EndTrapdoorBlock extends TrapdoorBlock implements IRenderTypeable,
}
});
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_TRAPDOOR;

View file

@ -2,51 +2,58 @@ package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.FluidFillable;
import net.minecraft.world.level.material.Material;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
public class EndUnderwaterWallPlantBlock extends EndWallPlantBlock implements FluidFillable {
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material;
public class EndUnderwaterWallPlantBlock extends EndWallPlantBlock implements LiquidBlockContainer {
public EndUnderwaterWallPlantBlock() {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(SoundType.WET_GRASS).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public EndUnderwaterWallPlantBlock(int light) {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(SoundType.WET_GRASS).luminance(light).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public EndUnderwaterWallPlantBlock(Properties settings) {
super(settings);
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
return false;
}
@Override
public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
return false;
}
@Override
public FluidState getFluidState(BlockState state) {
return Fluids.WATER.getStill(false);
return Fluids.WATER.getSource(false);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getFluidState(pos).getFluid() == Fluids.WATER && super.canPlaceAt(state, world, pos);
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return world.getFluidState(pos).getType() == Fluids.WATER && super.canSurvive(state, world, pos);
}
}

View file

@ -5,22 +5,22 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndWallBlock extends WallBlock implements BlockPatterned {
private final Block parent;
public EndWallBlock(Block source) {
super(FabricBlockSettings.copyOf(source).nonOpaque());
super(FabricBlockSettings.copyOf(source).noOcclusion());
this.parent = source;
}
@ -28,14 +28,14 @@ public class EndWallBlock extends WallBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -51,7 +51,7 @@ public class EndWallBlock extends WallBlock implements BlockPatterned {
}
return Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_WALL;

View file

@ -7,87 +7,95 @@ import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.AbstractBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalFacingBlock;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.BlockMirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.util.BlocksHelper;
public class EndWallPlantBlock extends EndPlantBlock {
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(Direction.NORTH,
Block.createCuboidShape(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.createCuboidShape(1, 1, 0, 15, 15, 8),
Direction.WEST, Block.createCuboidShape(8, 1, 1, 16, 15, 15), Direction.EAST,
Block.createCuboidShape(0, 1, 1, 8, 15, 15)));
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(
Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16),
Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8),
Direction.WEST, Block.box(8, 1, 1, 16, 15, 15),
Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)));
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public EndWallPlantBlock() {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
.breakByHand(true).noCollision());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
public EndWallPlantBlock(int light) {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
.luminance(light).breakByHand(true).noCollision());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
}
public EndWallPlantBlock(Properties settings) {
super(settings);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPES.get(state.getValue(FACING));
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE;
public BlockBehaviour.OffsetType getOffsetType() {
return BlockBehaviour.OffsetType.NONE;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
Direction direction = (Direction) state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite());
BlockState blockState = world.getBlockState(blockPos);
return isSupport(world, blockPos, blockState, direction);
}
public boolean isSupport(WorldView world, BlockPos pos, BlockState blockState, Direction direction) {
return blockState.getMaterial().isSolid() && blockState.isSideSolidFullSquare(world, pos, direction);
public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) {
return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
BlockState blockState = this.defaultBlockState();
WorldView worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos();
Direction[] directions = ctx.getPlacementDirections();
LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getClickedPos();
Direction[] directions = ctx.getNearestLookingDirections();
for (int i = 0; i < directions.length; ++i) {
Direction direction = directions[i];
if (direction.getAxis().isHorizontal()) {
Direction direction2 = direction.getOpposite();
blockState = blockState.with(FACING, direction2);
if (blockState.canPlaceAt(worldView, blockPos)) {
blockState = blockState.setValue(FACING, direction2);
if (blockState.canSurvive(worldView, blockPos)) {
return blockState;
}
}
@ -96,22 +104,22 @@ public class EndWallPlantBlock extends EndPlantBlock {
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
}
}

View file

@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.WoodenButtonBlock;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WoodButtonBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndWoodenButtonBlock extends WoodenButtonBlock implements BlockPatterned {
public class EndWoodenButtonBlock extends WoodButtonBlock implements BlockPatterned {
private final Block parent;
public EndWoodenButtonBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).nonOpaque());
super(FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion());
this.parent = source;
}
@ -27,14 +27,14 @@ public class EndWoodenButtonBlock extends WoodenButtonBlock implements BlockPatt
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -47,7 +47,7 @@ public class EndWoodenButtonBlock extends WoodenButtonBlock implements BlockPatt
}
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BUTTON;

View file

@ -4,6 +4,6 @@ import net.minecraft.world.level.block.Block;
public class EndWoodenPlateBlock extends EndPlateBlock {
public EndWoodenPlateBlock(Block source) {
super(ActivationRule.EVERYTHING, source);
super(Sensitivity.EVERYTHING, source);
}
}

View file

@ -4,97 +4,105 @@ import java.io.Reader;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Fertilizable;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.Patterns;
import ru.betterend.registry.EndTags;
public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements Fertilizable, IRenderTypeable {
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 14, 12);
public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements BonemealableBlock, IRenderTypeable {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public FeatureSaplingBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).breakInstantly()
.sounds(SoundType.GRASS).ticksRandomly());
super(FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
.collidable(false)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks());
}
public FeatureSaplingBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).breakInstantly()
.sounds(SoundType.GRASS).luminance(light).ticksRandomly());
super(FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
.collidable(false)
.luminance(light)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks());
}
protected abstract Feature<?> getFeature();
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.below()).isIn(EndTags.END_GROUND);
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return world.getBlockState(pos.below()).is(EndTags.END_GROUND);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos))
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos))
return Blocks.AIR.defaultBlockState();
else
return state;
}
@Override
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) {
return true;
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return random.nextInt(16) == 0;
}
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
getFeature().place(world, world.getChunkManager().getChunkGenerator(), random, pos, null);
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
getFeature().place(world, world.getChunkSource().getGenerator(), random, pos, null);
}
@Override
public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.scheduledTick(state, world, pos, random);
if (canGrow(world, random, pos, state)) {
grow(world, random, pos, state);
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (isBonemealSuccess(world, random, pos, state)) {
performBonemeal(world, random, pos, state);
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@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) {
if (block.contains("item")) {
@ -103,7 +111,7 @@ public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements Fe
}
return Patterns.createJson(Patterns.BLOCK_CROSS, block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SAPLING;

View file

@ -8,21 +8,21 @@ import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.util.MHelper;
@ -31,50 +31,58 @@ public class FurBlock extends AttachedBlock implements IRenderTypeable {
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
private final ItemLike drop;
private final int dropChance;
public FurBlock(ItemLike drop, int light, int dropChance, boolean wet) {
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(wet ? SoundType.WET_GRASS : SoundType.GRASS).luminance(light).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(wet ? SoundType.WET_GRASS : SoundType.GRASS)
.noCollission());
this.drop = drop;
this.dropChance = dropChance;
}
public FurBlock(ItemLike drop, int dropChance) {
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(SoundType.GRASS).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
this.drop = drop;
this.dropChance = dropChance;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return BOUNDING_SHAPES.get(state.getValue(FACING));
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
} else if (dropChance < 1 || MHelper.RANDOM.nextInt(dropChance) == 0) {
}
else if (dropChance < 1 || MHelper.RANDOM.nextInt(dropChance) == 0) {
return Lists.newArrayList(new ItemStack(drop));
} else {
}
else {
return Lists.newArrayList();
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
static {
BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 0.5, 1.0));
BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.0, 0.5, 0.0, 1.0, 1.0, 1.0));
BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.0, 0.0, 0.5, 1.0, 1.0, 1.0));
BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 1.0, 0.5));
BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.5, 0.0, 0.0, 1.0, 1.0, 1.0));
BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.0, 0.0, 0.5, 1.0, 1.0));
BOUNDING_SHAPES.put(Direction.UP, Shapes.box(0.0, 0.0, 0.0, 1.0, 0.5, 1.0));
BOUNDING_SHAPES.put(Direction.DOWN, Shapes.box(0.0, 0.5, 0.0, 1.0, 1.0, 1.0));
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));
}
}

View file

@ -11,33 +11,33 @@ import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BlockEntityProvider;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
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.BlockProperties;
import ru.betterend.blocks.BlockProperties.PedestalState;
import ru.betterend.blocks.InfusionPedestal;
@ -46,18 +46,18 @@ import ru.betterend.patterns.Patterns;
import ru.betterend.registry.EndBlocks;
import ru.betterend.rituals.InfusionRitual;
public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvider {
public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
public final static EnumProperty<PedestalState> STATE = BlockProperties.PEDESTAL_STATE;
public static final BooleanProperty HAS_ITEM = BlockProperties.HAS_ITEM;
public static final BooleanProperty HAS_LIGHT = BlockProperties.HAS_LIGHT;
private static final VoxelShape SHAPE_DEFAULT;
private static final VoxelShape SHAPE_COLUMN;
private static final VoxelShape SHAPE_PILLAR;
private static final VoxelShape SHAPE_PEDESTAL_TOP;
private static final VoxelShape SHAPE_COLUMN_TOP;
private static final VoxelShape SHAPE_BOTTOM;
/**
*
* Register new Pedestal block with Better End mod id.
@ -69,7 +69,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
public static Block registerPedestal(String name, Block source) {
return EndBlocks.registerBlock(name, new PedestalBlock(source));
}
/**
*
* Register new Pedestal block with specified mod id.
@ -81,58 +81,54 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
public static Block registerPedestal(ResourceLocation id, Block source) {
return EndBlocks.registerBlock(id, new PedestalBlock(source));
}
protected final Block parent;
protected float height = 1.0F;
public PedestalBlock(Block parent) {
super(FabricBlockSettings.copyOf(parent).luminance(state -> state.getValue(HAS_LIGHT) ? 12 : 0));
this.setDefaultState(stateManager.defaultBlockState().with(STATE, PedestalState.DEFAULT).with(HAS_ITEM, false)
.with(HAS_LIGHT, false));
super(FabricBlockSettings.copyOf(parent).lightLevel(state -> state.getValue(HAS_LIGHT) ? 12 : 0));
this.registerDefaultState(stateDefinition.any().setValue(STATE, PedestalState.DEFAULT).setValue(HAS_ITEM, false).setValue(HAS_LIGHT, false));
this.parent = parent;
}
public float getHeight(BlockState state) {
if (state.getBlock() instanceof PedestalBlock && state.getValue(STATE) == PedestalState.PEDESTAL_TOP) {
return this.height - 0.2F;
}
return this.height;
}
@Override
public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand,
BlockHitResult hit) {
if (world.isClientSide || !state.is(this))
return ActionResult.CONSUME;
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (world.isClientSide || !state.is(this)) return InteractionResult.CONSUME;
if (!isPlaceable(state)) {
return ActionResult.PASS;
return InteractionResult.PASS;
}
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (pedestal.isEmpty()) {
ItemStack itemStack = player.getStackInHand(hand);
if (itemStack.isEmpty())
return ActionResult.CONSUME;
pedestal.setStack(0, itemStack.split(1));
ItemStack itemStack = player.getItemInHand(hand);
if (itemStack.isEmpty()) return InteractionResult.CONSUME;
pedestal.setItem(0, itemStack.split(1));
checkRitual(world, pos);
return ActionResult.SUCCESS;
return InteractionResult.SUCCESS;
} else {
ItemStack itemStack = pedestal.getStack(0);
if (player.giveItemStack(itemStack)) {
pedestal.removeStack(0);
ItemStack itemStack = pedestal.getItem(0);
if (player.addItem(itemStack)) {
pedestal.removeItemNoUpdate(0);
checkRitual(world, pos);
return ActionResult.SUCCESS;
return InteractionResult.SUCCESS;
}
return ActionResult.FAIL;
return InteractionResult.FAIL;
}
}
return ActionResult.PASS;
return InteractionResult.PASS;
}
public void checkRitual(Level world, BlockPos pos) {
MutableBlockPos posMutable = new MutableBlockPos();
for (Point point : InfusionRitual.getMap()) {
for (Point point: InfusionRitual.getMap()) {
posMutable.set(pos).move(point.x, 0, point.y);
BlockState state = world.getBlockState(posMutable);
if (state.getBlock() instanceof InfusionPedestal) {
@ -141,93 +137,85 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
}
}
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext context) {
public BlockState getStateForPlacement(BlockPlaceContext context) {
Level world = context.getLevel();
BlockPos pos = context.getBlockPos();
BlockState upState = world.getBlockState(pos.up());
BlockPos pos = context.getClickedPos();
BlockState upState = world.getBlockState(pos.above());
BlockState downState = world.getBlockState(pos.below());
boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN)
|| upState.isIn(BlockTags.WALLS);
boolean upSideSolid = upState.isFaceSturdy(world, pos.above(), Direction.DOWN) || upState.is(BlockTags.WALLS);
boolean hasPedestalOver = upState.getBlock() instanceof PedestalBlock;
boolean hasPedestalUnder = downState.getBlock() instanceof PedestalBlock;
if (!hasPedestalOver && hasPedestalUnder && upSideSolid) {
return getDefaultState().with(STATE, PedestalState.COLUMN_TOP);
return defaultBlockState().setValue(STATE, PedestalState.COLUMN_TOP);
} else if (!hasPedestalOver && !hasPedestalUnder && upSideSolid) {
return getDefaultState().with(STATE, PedestalState.COLUMN);
return defaultBlockState().setValue(STATE, PedestalState.COLUMN);
} else if (hasPedestalUnder && hasPedestalOver) {
return getDefaultState().with(STATE, PedestalState.PILLAR);
return defaultBlockState().setValue(STATE, PedestalState.PILLAR);
} else if (hasPedestalUnder) {
return getDefaultState().with(STATE, PedestalState.PEDESTAL_TOP);
return defaultBlockState().setValue(STATE, PedestalState.PEDESTAL_TOP);
} else if (hasPedestalOver) {
return getDefaultState().with(STATE, PedestalState.BOTTOM);
return defaultBlockState().setValue(STATE, PedestalState.BOTTOM);
}
return getDefaultState();
return defaultBlockState();
}
@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world,
BlockPos pos, BlockPos posFrom) {
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
BlockState updated = getUpdatedState(state, direction, newState, world, pos, posFrom);
if (!updated.is(this))
return updated;
if (!updated.is(this)) return updated;
if (!isPlaceable(updated)) {
moveStoredStack(world, updated, pos);
}
return updated;
}
private BlockState getUpdatedState(BlockState state, Direction direction, BlockState newState, LevelAccessor world,
BlockPos pos, BlockPos posFrom) {
if (!state.is(this))
return state.updateShape(direction, newState, world, pos, posFrom);
if (direction != Direction.UP && direction != Direction.DOWN)
return state;
BlockState upState = world.getBlockState(pos.up());
private BlockState getUpdatedState(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
if (!state.is(this)) return state.updateShape(direction, newState, world, pos, posFrom);
if (direction != Direction.UP && direction != Direction.DOWN) return state;
BlockState upState = world.getBlockState(pos.above());
BlockState downState = world.getBlockState(pos.below());
boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN)
|| upState.isIn(BlockTags.WALLS);
boolean upSideSolid = upState.isFaceSturdy(world, pos.above(), Direction.DOWN) || upState.is(BlockTags.WALLS);
boolean hasPedestalOver = upState.getBlock() instanceof PedestalBlock;
boolean hasPedestalUnder = downState.getBlock() instanceof PedestalBlock;
if (direction == Direction.UP) {
upSideSolid = newState.isSideSolidFullSquare(world, posFrom, Direction.DOWN)
|| newState.isIn(BlockTags.WALLS);
upSideSolid = newState.isFaceSturdy(world, posFrom, Direction.DOWN) || newState.is(BlockTags.WALLS);
hasPedestalOver = newState.getBlock() instanceof PedestalBlock;
} else {
hasPedestalUnder = newState.getBlock() instanceof PedestalBlock;
}
BlockState updatedState;
if (!hasPedestalOver && hasPedestalUnder && upSideSolid) {
updatedState = state.with(STATE, PedestalState.COLUMN_TOP);
updatedState = state.setValue(STATE, PedestalState.COLUMN_TOP);
} else if (!hasPedestalOver && !hasPedestalUnder && upSideSolid) {
updatedState = state.with(STATE, PedestalState.COLUMN);
updatedState = state.setValue(STATE, PedestalState.COLUMN);
} else if (hasPedestalUnder && hasPedestalOver) {
updatedState = state.with(STATE, PedestalState.PILLAR);
updatedState = state.setValue(STATE, PedestalState.PILLAR);
} else if (hasPedestalUnder) {
updatedState = state.with(STATE, PedestalState.PEDESTAL_TOP);
updatedState = state.setValue(STATE, PedestalState.PEDESTAL_TOP);
} else if (hasPedestalOver) {
updatedState = state.with(STATE, PedestalState.BOTTOM);
updatedState = state.setValue(STATE, PedestalState.BOTTOM);
} else {
updatedState = state.with(STATE, PedestalState.DEFAULT);
updatedState = state.setValue(STATE, PedestalState.DEFAULT);
}
if (!isPlaceable(updatedState)) {
updatedState = updatedState.with(HAS_ITEM, false).with(HAS_LIGHT, false);
updatedState = updatedState.setValue(HAS_ITEM, false).setValue(HAS_LIGHT, false);
}
return updatedState;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drop = Lists.newArrayList(super.getDrops(state, builder));
if (state.is(this)) {
if (isPlaceable(state)) {
BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY);
BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (!pedestal.isEmpty()) {
drop.add(pedestal.getStack(0));
drop.add(pedestal.getItem(0));
}
}
} else {
@ -236,30 +224,30 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return drop;
}
private void moveStoredStack(LevelAccessor world, BlockState state, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PedestalBlockEntity && state.is(this)) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
ItemStack stack = pedestal.removeStack(0);
ItemStack stack = pedestal.removeItemNoUpdate(0);
if (!stack.isEmpty()) {
moveStoredStack(blockEntity, world, stack, pos.up());
moveStoredStack(blockEntity, world, stack, pos.above());
}
}
}
private void moveStoredStack(BlockEntity blockEntity, LevelAccessor world, ItemStack stack, BlockPos pos) {
BlockState state = world.getBlockState(pos);
if (!state.is(this)) {
dropStoredStack(blockEntity, stack, pos);
} else if (state.getValue(STATE).equals(PedestalState.PILLAR)) {
moveStoredStack(blockEntity, world, stack, pos.up());
moveStoredStack(blockEntity, world, stack, pos.above());
} else if (!isPlaceable(state)) {
dropStoredStack(blockEntity, stack, pos);
} else if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (pedestal.isEmpty()) {
pedestal.setStack(0, stack);
pedestal.setItem(0, stack);
} else {
dropStoredStack(blockEntity, stack, pos);
}
@ -267,91 +255,91 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
dropStoredStack(blockEntity, stack, pos);
}
}
private void dropStoredStack(BlockEntity blockEntity, ItemStack stack, BlockPos pos) {
if (blockEntity != null && blockEntity.getLevel() != null) {
Level world = blockEntity.getLevel();
Block.dropStack(world, getDropPos(world, pos), stack);
Block.popResource(world, getDropPos(world, pos), stack);
}
}
private BlockPos getDropPos(LevelAccessor world, BlockPos pos) {
BlockPos dropPos;
if (world.getBlockState(pos).isAir()) {
return pos;
}
if (world.getBlockState(pos.up()).isAir()) {
return pos.up();
if (world.getBlockState(pos.above()).isAir()) {
return pos.above();
}
for (int i = 2; i < Direction.values().length; i++) {
dropPos = pos.relative(Direction.byId(i));
for(int i = 2; i < Direction.values().length; i++) {
dropPos = pos.relative(Direction.from3DDataValue(i));
if (world.getBlockState(dropPos).isAir()) {
return dropPos.immutable();
}
}
return getDropPos(world, pos.up());
return getDropPos(world, pos.above());
}
public boolean isPlaceable(BlockState state) {
if (!state.is(this))
return false;
if (!state.is(this)) return false;
PedestalState currentState = state.getValue(STATE);
return currentState == PedestalState.DEFAULT || currentState == PedestalState.PEDESTAL_TOP;
return currentState == PedestalState.DEFAULT ||
currentState == PedestalState.PEDESTAL_TOP;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
if (state.is(this)) {
switch (state.getValue(STATE)) {
case BOTTOM: {
return SHAPE_BOTTOM;
}
case PEDESTAL_TOP: {
return SHAPE_PEDESTAL_TOP;
}
case COLUMN_TOP: {
return SHAPE_COLUMN_TOP;
}
case PILLAR: {
return SHAPE_PILLAR;
}
case COLUMN: {
return SHAPE_COLUMN;
}
default: {
return SHAPE_DEFAULT;
}
switch(state.getValue(STATE)) {
case BOTTOM: {
return SHAPE_BOTTOM;
}
case PEDESTAL_TOP: {
return SHAPE_PEDESTAL_TOP;
}
case COLUMN_TOP: {
return SHAPE_COLUMN_TOP;
}
case PILLAR: {
return SHAPE_PILLAR;
}
case COLUMN: {
return SHAPE_COLUMN;
}
default: {
return SHAPE_DEFAULT;
}
}
}
return super.getOutlineShape(state, world, pos, context);
return super.getShape(state, world, pos, context);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(STATE, HAS_ITEM, HAS_LIGHT);
}
@Override
public BlockEntity createBlockEntity(BlockView world) {
public BlockEntity newBlockEntity(BlockGetter world) {
return new PedestalBlockEntity();
}
@Override
public boolean hasComparatorOutput(BlockState state) {
public boolean hasAnalogOutputSignal(BlockState state) {
return state.getBlock() instanceof PedestalBlock;
}
@Override
public int getComparatorOutput(BlockState state, Level world, BlockPos pos) {
public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
return state.getValue(HAS_ITEM) ? 15 : 0;
}
@Override
public String getStatesPattern(Reader data) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, texture, texture);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(parent);
@ -359,7 +347,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
Map<String, String> textures = new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("%mod%", blockId.getNamespace());
put("%mod%", blockId.getNamespace() );
put("%top%", name + "_top");
put("%base%", name + "_base");
put("%pillar%", name + "_pillar");
@ -379,28 +367,28 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_PEDESTAL;
}
static {
VoxelShape basinUp = Block.createCuboidShape(2, 3, 2, 14, 4, 14);
VoxelShape basinDown = Block.createCuboidShape(0, 0, 0, 16, 3, 16);
VoxelShape columnTopUp = Block.createCuboidShape(1, 14, 1, 15, 16, 15);
VoxelShape columnTopDown = Block.createCuboidShape(2, 13, 2, 14, 14, 14);
VoxelShape pedestalTop = Block.createCuboidShape(1, 8, 1, 15, 10, 15);
VoxelShape pedestalDefault = Block.createCuboidShape(1, 12, 1, 15, 14, 15);
VoxelShape pillar = Block.createCuboidShape(3, 0, 3, 13, 8, 13);
VoxelShape pillarDefault = Block.createCuboidShape(3, 0, 3, 13, 12, 13);
VoxelShape columnTop = VoxelShapes.union(columnTopDown, columnTopUp);
VoxelShape basin = VoxelShapes.union(basinDown, basinUp);
SHAPE_PILLAR = Block.createCuboidShape(3, 0, 3, 13, 16, 13);
SHAPE_DEFAULT = VoxelShapes.union(basin, pillarDefault, pedestalDefault);
SHAPE_PEDESTAL_TOP = VoxelShapes.union(pillar, pedestalTop);
SHAPE_COLUMN_TOP = VoxelShapes.union(SHAPE_PILLAR, columnTop);
SHAPE_COLUMN = VoxelShapes.union(basin, SHAPE_PILLAR, columnTop);
SHAPE_BOTTOM = VoxelShapes.union(basin, SHAPE_PILLAR);
VoxelShape basinUp = Block.box(2, 3, 2, 14, 4, 14);
VoxelShape basinDown = Block.box(0, 0, 0, 16, 3, 16);
VoxelShape columnTopUp = Block.box(1, 14, 1, 15, 16, 15);
VoxelShape columnTopDown = Block.box(2, 13, 2, 14, 14, 14);
VoxelShape pedestalTop = Block.box(1, 8, 1, 15, 10, 15);
VoxelShape pedestalDefault = Block.box(1, 12, 1, 15, 14, 15);
VoxelShape pillar = Block.box(3, 0, 3, 13, 8, 13);
VoxelShape pillarDefault = Block.box(3, 0, 3, 13, 12, 13);
VoxelShape columnTop = Shapes.or(columnTopDown, columnTopUp);
VoxelShape basin = Shapes.or(basinDown, basinUp);
SHAPE_PILLAR = Block.box(3, 0, 3, 13, 16, 13);
SHAPE_DEFAULT = Shapes.or(basin, pillarDefault, pedestalDefault);
SHAPE_PEDESTAL_TOP = Shapes.or(pillar, pedestalTop);
SHAPE_COLUMN_TOP = Shapes.or(SHAPE_PILLAR, columnTop);
SHAPE_COLUMN = Shapes.or(basin, SHAPE_PILLAR, columnTop);
SHAPE_BOTTOM = Shapes.or(basin, SHAPE_PILLAR);
}
}

View file

@ -3,50 +3,51 @@ package ru.betterend.blocks.basis;
import java.io.Reader;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.Patterns;
public class SimpleLeavesBlock extends BlockBaseNotFull implements IRenderTypeable {
public SimpleLeavesBlock(MaterialColor color) {
super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).sounds(SoundType.GRASS).nonOpaque()
.allowsSpawning((state, world, pos, type) -> {
return false;
}).suffocates((state, world, pos) -> {
return false;
}).blockVision((state, world, pos) -> {
return false;
}).materialColor(color));
super(FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F)
.materialColor(color)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
}
public SimpleLeavesBlock(MaterialColor color, int light) {
super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).sounds(SoundType.GRASS).nonOpaque()
.luminance(light).allowsSpawning((state, world, pos, type) -> {
return false;
}).suffocates((state, world, pos) -> {
return false;
}).blockVision((state, world, pos) -> {
return false;
}).materialColor(color));
super(FabricBlockSettings.of(Material.LEAVES)
.luminance(light)
.materialColor(color)
.strength(0.2F)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
}
@Override
public String getStatesPattern(Reader data) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, texture, texture);
}
@Override
public String getModelPattern(String block) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(Patterns.BLOCK_BASE, texture, texture);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;

View file

@ -1,48 +1,47 @@
package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FluidFillable;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.level.block.Waterloggable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.Patterns;
public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, FluidFillable, IRenderTypeable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTypeable {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
public static final IntegerProperty SIZE = BlockProperties.SIZE;
private static final VoxelShape[] SHAPES;
public StalactiteBlock(Block source) {
super(FabricBlockSettings.copy(source).nonOpaque());
this.setDefaultState(
getStateManager().defaultBlockState().with(SIZE, 0).with(IS_FLOOR, true).with(WATERLOGGED, false));
super(FabricBlockSettings.copy(source).noOcclusion());
this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false));
}
@Override
@ -51,137 +50,147 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPES[state.getValue(SIZE)];
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
WorldView world = ctx.getLevel();
BlockPos pos = ctx.getBlockPos();
Direction dir = ctx.getSide();
boolean water = world.getFluidState(pos).getFluid() == Fluids.WATER;
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
LevelReader world = ctx.getLevel();
BlockPos pos = ctx.getClickedPos();
Direction dir = ctx.getClickedFace();
boolean water = world.getFluidState(pos).getType() == Fluids.WATER;
if (dir == Direction.DOWN) {
if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
} else if (isThis(world, pos.below()) || sideCoversSmallSquare(world, pos.below(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
} else {
if (isThis(world, pos.above()) || canSupportCenter(world, pos.above(), Direction.DOWN)) {
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
}
else if (isThis(world, pos.below()) || canSupportCenter(world, pos.below(), Direction.UP)) {
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
}
else {
return null;
}
} else {
if (isThis(world, pos.below()) || sideCoversSmallSquare(world, pos.below(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
} else if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
} else {
}
else {
if (isThis(world, pos.below()) || canSupportCenter(world, pos.below(), Direction.UP)) {
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
}
else if (isThis(world, pos.above()) || canSupportCenter(world, pos.above(), Direction.DOWN)) {
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
}
else {
return null;
}
}
}
@Override
public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
boolean hasUp = isThis(world, pos.up());
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
boolean hasUp = isThis(world, pos.above());
boolean hasDown = isThis(world, pos.below());
MutableBlockPos mut = new MutableBlockPos();
if (hasUp && hasDown) {
boolean floor = state.getValue(IS_FLOOR);
BlockPos second = floor ? pos.up() : pos.below();
BlockPos second = floor ? pos.above() : pos.below();
BlockState bState = world.getBlockState(second);
world.setBlockAndUpdate(pos, state.with(SIZE, 1).with(IS_FLOOR, floor));
world.setBlockAndUpdate(second, bState.with(SIZE, 1).with(IS_FLOOR, !floor));
world.setBlockAndUpdate(pos, state.setValue(SIZE, 1).setValue(IS_FLOOR, floor));
world.setBlockAndUpdate(second, bState.setValue(SIZE, 1).setValue(IS_FLOOR, !floor));
bState = state;
int startSize = floor ? 1 : 2;
mut.set(pos.getX(), pos.getY() + 1, pos.getZ());
for (int i = 0; i < 8 && isThis(bState); i++) {
world.setBlockAndUpdate(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, false));
world.setBlockAndUpdate(mut, bState.setValue(SIZE, startSize++).setValue(IS_FLOOR, false));
mut.setY(mut.getY() + 1);
bState = world.getBlockState(mut);
}
bState = state;
startSize = floor ? 2 : 1;
mut.set(pos.getX(), pos.getY() - 1, pos.getZ());
for (int i = 0; i < 8 && isThis(bState); i++) {
world.setBlockAndUpdate(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, true));
world.setBlockAndUpdate(mut, bState.setValue(SIZE, startSize++).setValue(IS_FLOOR, true));
mut.setY(mut.getY() - 1);
bState = world.getBlockState(mut);
}
} else if (hasDown) {
}
else if (hasDown) {
mut.setX(pos.getX());
mut.setZ(pos.getZ());
for (int i = 1; i < 8; i++) {
mut.setY(pos.getY() - i);
if (isThis(world, mut)) {
BlockState state2 = world.getBlockState(mut);
int size = state2.get(SIZE);
int size = state2.getValue(SIZE);
if (size < i) {
world.setBlockAndUpdate(mut, state2.with(SIZE, i).with(IS_FLOOR, true));
} else {
world.setBlockAndUpdate(mut, state2.setValue(SIZE, i).setValue(IS_FLOOR, true));
}
else {
break;
}
} else {
}
else {
break;
}
}
} else if (hasUp) {
}
else if (hasUp) {
mut.setX(pos.getX());
mut.setZ(pos.getZ());
for (int i = 1; i < 8; i++) {
mut.setY(pos.getY() + i);
if (isThis(world, mut)) {
BlockState state2 = world.getBlockState(mut);
int size = state2.get(SIZE);
int size = state2.getValue(SIZE);
if (size < i) {
world.setBlockAndUpdate(mut, state2.with(SIZE, i).with(IS_FLOOR, false));
} else {
world.setBlockAndUpdate(mut, state2.setValue(SIZE, i).setValue(IS_FLOOR, false));
}
else {
break;
}
} else {
}
else {
break;
}
}
}
}
private boolean isThis(WorldView world, BlockPos pos) {
private boolean isThis(LevelReader world, BlockPos pos) {
return isThis(world.getBlockState(pos));
}
private boolean isThis(BlockState state) {
return state.getBlock() instanceof StalactiteBlock;
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
}
return state;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
int size = state.getValue(SIZE);
return checkUp(world, pos, size) || checkDown(world, pos, size);
}
private boolean checkUp(BlockView world, BlockPos pos, int size) {
BlockPos p = pos.up();
private boolean checkUp(BlockGetter world, BlockPos pos, int size) {
BlockPos p = pos.above();
BlockState state = world.getBlockState(p);
return (isThis(state) && state.getValue(SIZE) >= size) || state.isFullCube(world, p);
return (isThis(state) && state.getValue(SIZE) >= size) || state.isCollisionShapeFullBlock(world, p);
}
private boolean checkDown(BlockView world, BlockPos pos, int size) {
private boolean checkDown(BlockGetter world, BlockPos pos, int size) {
BlockPos p = pos.below();
BlockState state = world.getBlockState(p);
return (isThis(state) && state.getValue(SIZE) >= size) || state.isFullCube(world, p);
return (isThis(state) && state.getValue(SIZE) >= size) || state.isCollisionShapeFullBlock(world, p);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -190,25 +199,25 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
}
return Patterns.createJson(Patterns.BLOCK_CROSS_SHADED, block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_STALACTITE;
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
return false;
}
@Override
public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
return false;
}
@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState();
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
}
@Override
@ -222,7 +231,7 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
SHAPES = new VoxelShape[8];
for (int i = 0; i < 8; i++) {
int side = Mth.floor(Mth.lerp(i / 7F, start, end) * 8F + 0.5F);
SHAPES[i] = Block.createCuboidShape(side, 0, side, 16 - side, 16, 16 - side);
SHAPES[i] = Block.box(side, 0, side, 16 - side, 16, 16 - side);
}
}
}

View file

@ -3,34 +3,34 @@ package ru.betterend.blocks.basis;
import java.io.Reader;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.core.Vec3i;
import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
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.VoxelShape;
import ru.betterend.blocks.AuroraCrystalBlock;
import ru.betterend.interfaces.IColorProvider;
import ru.betterend.patterns.Patterns;
import ru.betterend.util.MHelper;
public class StoneLanternBlock extends EndLanternBlock implements IColorProvider {
private static final VoxelShape SHAPE_CEIL = Block.createCuboidShape(3, 1, 3, 13, 16, 13);
private static final VoxelShape SHAPE_FLOOR = Block.createCuboidShape(3, 0, 3, 13, 15, 13);
private static final VoxelShape SHAPE_CEIL = Block.box(3, 1, 3, 13, 16, 13);
private static final VoxelShape SHAPE_FLOOR = Block.box(3, 0, 3, 13, 15, 13);
private static final Vec3i[] COLORS = AuroraCrystalBlock.COLORS;
public StoneLanternBlock(Block source) {
super(FabricBlockSettings.copyOf(source).luminance(15));
}
@Override
public BlockColor getBlockProvider() {
public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> {
long i = (long) pos.getX() + (long) pos.getY() + (long) pos.getZ();
double delta = i * 0.1;
@ -38,14 +38,14 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
int index2 = (index + 1) & 3;
delta -= index;
index &= 3;
Vec3i color1 = COLORS[index];
Vec3i color2 = COLORS[index2];
int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX()));
int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY()));
int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ()));
return MHelper.color(r, g, b);
};
}
@ -56,17 +56,17 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
return MHelper.color(COLORS[3].getX(), COLORS[3].getY(), COLORS[3].getZ());
};
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return state.getValue(IS_FLOOR) ? SHAPE_FLOOR : SHAPE_CEIL;
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_STONE_LANTERN;
}
@Override
public String getModelPattern(String block) {
String texture = Registry.BLOCK.getKey(this).getPath();
@ -75,7 +75,7 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
}
return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, texture, texture);
}
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();

View file

@ -2,42 +2,40 @@ package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.entity.player.Player;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
public class StrippableBarkBlock extends BarkBlock {
private final Block striped;
public StrippableBarkBlock(MaterialColor color, Block striped) {
super(FabricBlockSettings.copyOf(striped).materialColor(color));
this.striped = striped;
}
@Override
public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand,
BlockHitResult hit) {
if (player.getMainHandStack().getItem().isIn(FabricToolTags.AXES)) {
world.playLocalSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (player.getMainHandItem().getItem().is(FabricToolTags.AXES)) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlockAndUpdate(pos, striped.defaultBlockState().with(RotatedPillarBlock.AXIS,
state.getValue(RotatedPillarBlock.AXIS)), 11);
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
if (player != null && !player.isCreative()) {
player.getMainHandStack().damage(1, world.random, (ServerPlayer) player);
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}
}
return ActionResult.SUCCESS;
return InteractionResult.SUCCESS;
}
return ActionResult.FAIL;
return InteractionResult.FAIL;
}
}

View file

@ -2,27 +2,25 @@ package ru.betterend.blocks.basis;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemPlacementContext;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.BlockHitResult;
import com.google.common.collect.Maps;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.blocks.EndTerrainBlock;
@ -30,25 +28,24 @@ import ru.betterend.patterns.Patterns;
public class TripleTerrainBlock extends EndTerrainBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
public TripleTerrainBlock(MaterialColor color) {
super(color);
this.setDefaultState(this.defaultBlockState().with(SHAPE, TripleShape.BOTTOM));
this.registerDefaultState(this.defaultBlockState().setValue(SHAPE, TripleShape.BOTTOM));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
Direction dir = ctx.getSide();
TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM
: dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE;
return this.defaultBlockState().with(SHAPE, shape);
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
Direction dir = ctx.getClickedFace();
TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE;
return this.defaultBlockState().setValue(SHAPE, shape);
}
@Override
public String getModelPattern(String block) {
String name = Registry.BLOCK.getKey(this).getPath();
@ -61,59 +58,64 @@ public class TripleTerrainBlock extends EndTerrainBlock {
map.put("%bottom%", "minecraft:block/end_stone");
return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_TRIPLE_ROTATED_TOP;
}
@Override
public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand,
BlockHitResult hit) {
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) {
return super.onUse(state, world, pos, player, hand, hit);
return super.use(state, world, pos, player, hand, hit);
}
return ActionResult.FAIL;
return InteractionResult.FAIL;
}
@Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) {
super.randomTick(state, world, pos, random);
return;
} else if (random.nextInt(16) == 0) {
}
else if (random.nextInt(16) == 0) {
boolean bottom = canSurviveBottom(world, pos);
if (shape == TripleShape.TOP) {
if (!bottom) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
}
} else {
boolean top = canSurvive(state, world, pos) || isMiddle(world.getBlockState(pos.up()));
}
else {
boolean top = canSurvive(state, world, pos) || isMiddle(world.getBlockState(pos.above()));
if (!top && !bottom) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
} else if (top && !bottom) {
world.setBlockAndUpdate(pos, state.with(SHAPE, TripleShape.BOTTOM));
} else if (!top && bottom) {
world.setBlockAndUpdate(pos, state.with(SHAPE, TripleShape.TOP));
}
else if (top && !bottom) {
world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM));
}
else if (!top && bottom) {
world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP));
}
}
}
}
protected boolean canSurviveBottom(WorldView world, BlockPos pos) {
protected boolean canSurviveBottom(LevelReader world, BlockPos pos) {
BlockPos blockPos = pos.below();
BlockState blockState = world.getBlockState(blockPos);
if (isMiddle(blockState)) {
return true;
} else if (blockState.getFluidState().getLevel() == 8) {
}
else if (blockState.getFluidState().getAmount() == 8) {
return false;
} else {
return !blockState.isSideSolidFullSquare(world, blockPos, Direction.UP);
}
else {
return !blockState.isFaceSturdy(world, blockPos, Direction.UP);
}
}
protected boolean isMiddle(BlockState state) {
return state.is(this) && state.getValue(SHAPE) == TripleShape.MIDDLE;
}

View file

@ -7,133 +7,139 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.AbstractBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Fertilizable;
import net.minecraft.world.level.block.FluidFillable;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndTags;
public class UnderwaterPlantBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable, FluidFillable {
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 14, 12);
public class UnderwaterPlantBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public UnderwaterPlantBlock() {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(SoundType.WET_GRASS).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public UnderwaterPlantBlock(int light) {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(SoundType.WET_GRASS).luminance(light).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public UnderwaterPlantBlock(Properties settings) {
super(settings);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos);
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3 vec3d = state.getOffset(view, pos);
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.XZ;
public BlockBehaviour.OffsetType getOffsetType() {
return BlockBehaviour.OffsetType.XZ;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below());
state = world.getBlockState(pos);
return isTerrain(down) && state.getFluidState().getFluid().equals(Fluids.WATER.getStill());
return isTerrain(down) && state.getFluidState().getType().equals(Fluids.WATER.getSource());
}
protected boolean isTerrain(BlockState state) {
return state.isIn(EndTags.END_GROUND) || state.getBlock() == EndBlocks.ENDSTONE_DUST;
return state.is(EndTags.END_GROUND) || state.getBlock() == EndBlocks.ENDSTONE_DUST;
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
world.breakBlock(pos, true);
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
world.destroyBlock(pos, true);
return Blocks.WATER.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
} else {
}
else {
return Lists.newArrayList();
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) {
return true;
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return true;
}
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
new ItemStack(this));
world.spawnEntity(item);
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
world.addFreshEntity(item);
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
return false;
}
@Override
public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
return false;
}
@Override
public FluidState getFluidState(BlockState state) {
return Fluids.WATER.getStill(false);
return Fluids.WATER.getSource(false);
}
}

View file

@ -4,49 +4,54 @@ import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.BlockProperties;
public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock() {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS)
.sounds(SoundType.WET_GRASS).breakByHand(true).ticksRandomly().noCollision());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.randomTicks()
.noCollission());
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(AGE);
}
public abstract void grow(WorldGenLevel world, Random random, BlockPos pos);
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
if (random.nextInt(4) == 0) {
int age = state.getValue(AGE);
if (age < 3) {
world.setBlockAndUpdate(pos, state.with(AGE, age + 1));
} else {
world.setBlockAndUpdate(pos, state.setValue(AGE, age + 1));
}
else {
grow(world, random, pos);
}
}
}
@Override
public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.scheduledTick(state, world, pos, random);
if (canGrow(world, random, pos, state)) {
grow(world, random, pos, state);
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (isBonemealSuccess(world, random, pos, state)) {
performBonemeal(world, random, pos, state);
}
}
}

View file

@ -6,88 +6,90 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.registry.EndTags;
public class UpDownPlantBlock extends BlockBaseNotFull implements IRenderTypeable {
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 16, 12);
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12);
public UpDownPlantBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
.breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below());
BlockState up = world.getBlockState(pos.up());
BlockState up = world.getBlockState(pos.above());
return (isTerrain(down) || down.getBlock() == this) && (isSupport(up, world, pos) || up.getBlock() == this);
}
protected boolean isTerrain(BlockState state) {
return state.isIn(EndTags.END_GROUND);
return state.is(EndTags.END_GROUND);
}
protected boolean isSupport(BlockState state, WorldView world, BlockPos pos) {
return sideCoversSmallSquare(world, pos.up(), Direction.UP);
protected boolean isSupport(BlockState state, LevelReader world, BlockPos pos) {
return canSupportCenter(world, pos.above(), Direction.UP);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
}
else {
return state;
}
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
} else {
}
else {
return Lists.newArrayList();
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public void afterBreak(Level world, Player player, BlockPos pos, BlockState state, BlockEntity blockEntity,
ItemStack stack) {
super.afterBreak(world, player, pos, state, blockEntity, stack);
world.updateNeighbor(pos, Blocks.AIR, pos.below());
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, BlockEntity blockEntity, ItemStack stack) {
super.playerDestroy(world, player, pos, state, blockEntity, stack);
world.neighborChanged(pos, Blocks.AIR, pos.below());
}
}

View file

@ -7,119 +7,121 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.AbstractBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Fertilizable;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.ShapeContext;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.tags.BlockTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.util.BlocksHelper;
public class VineBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable {
public class VineBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape VOXEL_SHAPE = Block.createCuboidShape(2, 0, 2, 14, 16, 14);
private static final VoxelShape VOXEL_SHAPE = Block.box(2, 0, 2, 14, 16, 14);
public VineBlock() {
this(0, false);
}
public VineBlock(int light) {
this(light, false);
}
public VineBlock(int light, boolean bottomOnly) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
.luminance((state) -> {
return bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light;
}).breakByHand(true).noCollision());
this.setDefaultState(this.stateManager.defaultBlockState().with(SHAPE, TripleShape.BOTTOM));
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos);
return VOXEL_SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3 vec3d = state.getOffset(view, pos);
return VOXEL_SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
}
@Override
public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.XZ;
public BlockBehaviour.OffsetType getOffsetType() {
return BlockBehaviour.OffsetType.XZ;
}
public boolean canGenerate(BlockState state, WorldView world, BlockPos pos) {
public boolean canGenerate(BlockState state, LevelReader world, BlockPos pos) {
return isSupport(state, world, pos);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return isSupport(state, world, pos);
}
protected boolean isSupport(BlockState state, WorldView world, BlockPos pos) {
BlockState up = world.getBlockState(pos.up());
return up.is(this) || up.isIn(BlockTags.LEAVES) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN);
protected boolean isSupport(BlockState state, LevelReader world, BlockPos pos) {
BlockState up = world.getBlockState(pos.above());
return up.is(this) || up.is(BlockTags.LEAVES) || canSupportCenter(world, pos.above(), Direction.DOWN);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState();
} else {
}
else {
if (world.getBlockState(pos.below()).getBlock() != this)
return state.with(SHAPE, TripleShape.BOTTOM);
else if (world.getBlockState(pos.up()).getBlock() != this)
return state.with(SHAPE, TripleShape.TOP);
return state.with(SHAPE, TripleShape.MIDDLE);
return state.setValue(SHAPE, TripleShape.BOTTOM);
else if (world.getBlockState(pos.above()).getBlock() != this)
return state.setValue(SHAPE, TripleShape.TOP);
return state.setValue(SHAPE, TripleShape.MIDDLE);
}
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS)
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
} else {
}
else {
return Lists.newArrayList();
}
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) {
while (world.getBlockState(pos).getBlock() == this) {
pos = pos.below();
}
@ -127,19 +129,19 @@ public class VineBlock extends BlockBaseNotFull implements IRenderTypeable, Fert
}
@Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
while (world.getBlockState(pos).getBlock() == this) {
pos = pos.below();
}
return world.isAir(pos);
return world.isEmptyBlock(pos);
}
@Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) {
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
while (world.getBlockState(pos).getBlock() == this) {
pos = pos.below();
}
world.setBlockAndUpdate(pos, getDefaultState());
BlocksHelper.setWithoutUpdate(world, pos, getDefaultState());
world.setBlockAndUpdate(pos, defaultBlockState());
BlocksHelper.setWithoutUpdate(world, pos, defaultBlockState());
}
}

View file

@ -6,28 +6,34 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.WorldView;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
public class WallMushroomBlock extends EndWallPlantBlock {
public WallMushroomBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.AXES).sounds(SoundType.GRASS)
.luminance(light).sounds(SoundType.WOOD).hardness(0.2F).breakByHand(true).noCollision());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.AXES)
.breakByHand(true)
.luminance(light)
.hardness(0.2F)
.sound(SoundType.GRASS)
.sound(SoundType.WOOD)
.noCollission());
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Lists.newArrayList(new ItemStack(this));
}
@Override
public boolean isSupport(WorldView world, BlockPos pos, BlockState blockState, Direction direction) {
return blockState.getMaterial().isSolid() && blockState.isSideSolidFullSquare(world, pos, direction);
public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) {
return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction);
}
}