Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

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.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.state.StateManager;
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.PlayerEntity;
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.tag.BlockTags;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
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.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.blocks.BlockProperties.PedestalState;
import ru.betterend.blocks.InfusionPedestal;
@ -50,14 +50,14 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
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.
@ -78,29 +78,32 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
* @param source
* @return new Pedestal block with specified id.
*/
public static Block registerPedestal(Identifier id, Block source) {
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.get(HAS_LIGHT) ? 12 : 0));
this.setDefaultState(stateManager.getDefaultState().with(STATE, PedestalState.DEFAULT).with(HAS_ITEM, false).with(HAS_LIGHT, false));
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));
this.parent = parent;
}
public float getHeight(BlockState state) {
if (state.getBlock() instanceof PedestalBlock && state.get(STATE) == PedestalState.PEDESTAL_TOP) {
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, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient || !state.isOf(this)) return ActionResult.CONSUME;
public ActionResult onUse(BlockState state, Level world, BlockPos pos, PlayerEntity player, Hand hand,
BlockHitResult hit) {
if (world.isClientSide || !state.is(this))
return ActionResult.CONSUME;
if (!isPlaceable(state)) {
return ActionResult.PASS;
}
@ -109,7 +112,8 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (pedestal.isEmpty()) {
ItemStack itemStack = player.getStackInHand(hand);
if (itemStack.isEmpty()) return ActionResult.CONSUME;
if (itemStack.isEmpty())
return ActionResult.CONSUME;
pedestal.setStack(0, itemStack.split(1));
checkRitual(world, pos);
return ActionResult.SUCCESS;
@ -125,10 +129,10 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return ActionResult.PASS;
}
public void checkRitual(World world, BlockPos pos) {
Mutable posMutable = new Mutable();
for (Point point: InfusionRitual.getMap()) {
public void checkRitual(Level world, BlockPos pos) {
MutableBlockPos posMutable = new MutableBlockPos();
for (Point point : InfusionRitual.getMap()) {
posMutable.set(pos).move(point.x, 0, point.y);
BlockState state = world.getBlockState(posMutable);
if (state.getBlock() instanceof InfusionPedestal) {
@ -137,15 +141,16 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
}
}
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext context) {
World world = context.getWorld();
Level world = context.getLevel();
BlockPos pos = context.getBlockPos();
BlockState upState = world.getBlockState(pos.up());
BlockState downState = world.getBlockState(pos.down());
boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN) || upState.isIn(BlockTags.WALLS);
BlockState downState = world.getBlockState(pos.below());
boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN)
|| upState.isIn(BlockTags.WALLS);
boolean hasPedestalOver = upState.getBlock() instanceof PedestalBlock;
boolean hasPedestalUnder = downState.getBlock() instanceof PedestalBlock;
if (!hasPedestalOver && hasPedestalUnder && upSideSolid) {
@ -161,27 +166,34 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return getDefaultState();
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess 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.isOf(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, WorldAccess world, BlockPos pos, BlockPos posFrom) {
if (!state.isOf(this)) return state.getStateForNeighborUpdate(direction, newState, world, pos, posFrom);
if (direction != Direction.UP && direction != Direction.DOWN) return state;
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());
BlockState downState = world.getBlockState(pos.down());
boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN) || upState.isIn(BlockTags.WALLS);
BlockState downState = world.getBlockState(pos.below());
boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN)
|| upState.isIn(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.isSideSolidFullSquare(world, posFrom, Direction.DOWN)
|| newState.isIn(BlockTags.WALLS);
hasPedestalOver = newState.getBlock() instanceof PedestalBlock;
} else {
hasPedestalUnder = newState.getBlock() instanceof PedestalBlock;
@ -205,13 +217,13 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return updatedState;
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
List<ItemStack> drop = Lists.newArrayList(super.getDroppedStacks(state, builder));
if (state.isOf(this)) {
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(LootContextParameters.BLOCK_ENTITY);
BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (!pedestal.isEmpty()) {
@ -224,10 +236,10 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return drop;
}
private void moveStoredStack(WorldAccess world, BlockState state, BlockPos pos) {
private void moveStoredStack(LevelAccessor world, BlockState state, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PedestalBlockEntity && state.isOf(this)) {
if (blockEntity instanceof PedestalBlockEntity && state.is(this)) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
ItemStack stack = pedestal.removeStack(0);
if (!stack.isEmpty()) {
@ -235,12 +247,12 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
}
}
private void moveStoredStack(BlockEntity blockEntity, WorldAccess world, ItemStack stack, BlockPos pos) {
private void moveStoredStack(BlockEntity blockEntity, LevelAccessor world, ItemStack stack, BlockPos pos) {
BlockState state = world.getBlockState(pos);
if (!state.isOf(this)) {
if (!state.is(this)) {
dropStoredStack(blockEntity, stack, pos);
} else if (state.get(STATE).equals(PedestalState.PILLAR)) {
} else if (state.getValue(STATE).equals(PedestalState.PILLAR)) {
moveStoredStack(blockEntity, world, stack, pos.up());
} else if (!isPlaceable(state)) {
dropStoredStack(blockEntity, stack, pos);
@ -255,15 +267,15 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
dropStoredStack(blockEntity, stack, pos);
}
}
private void dropStoredStack(BlockEntity blockEntity, ItemStack stack, BlockPos pos) {
if (blockEntity != null && blockEntity.getWorld() != null) {
World world = blockEntity.getWorld();
if (blockEntity != null && blockEntity.getLevel() != null) {
Level world = blockEntity.getLevel();
Block.dropStack(world, getDropPos(world, pos), stack);
}
}
private BlockPos getDropPos(WorldAccess world, BlockPos pos) {
private BlockPos getDropPos(LevelAccessor world, BlockPos pos) {
BlockPos dropPos;
if (world.getBlockState(pos).isAir()) {
return pos;
@ -271,51 +283,51 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
if (world.getBlockState(pos.up()).isAir()) {
return pos.up();
}
for(int i = 2; i < Direction.values().length; i++) {
dropPos = pos.offset(Direction.byId(i));
for (int i = 2; i < Direction.values().length; i++) {
dropPos = pos.relative(Direction.byId(i));
if (world.getBlockState(dropPos).isAir()) {
return dropPos.toImmutable();
}
}
return getDropPos(world, pos.up());
}
public boolean isPlaceable(BlockState state) {
if (!state.isOf(this)) return false;
PedestalState currentState = state.get(STATE);
return currentState == PedestalState.DEFAULT ||
currentState == PedestalState.PEDESTAL_TOP;
if (!state.is(this))
return false;
PedestalState currentState = state.getValue(STATE);
return currentState == PedestalState.DEFAULT || currentState == PedestalState.PEDESTAL_TOP;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (state.isOf(this)) {
switch(state.get(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;
}
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;
}
}
}
return super.getOutlineShape(state, world, pos, context);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(STATE, HAS_ITEM, HAS_LIGHT);
}
@ -323,31 +335,31 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
public BlockEntity createBlockEntity(BlockView world) {
return new PedestalBlockEntity();
}
@Override
public boolean hasComparatorOutput(BlockState state) {
return state.getBlock() instanceof PedestalBlock;
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return state.get(HAS_ITEM) ? 15 : 0;
public int getComparatorOutput(BlockState state, Level world, BlockPos pos) {
return state.getValue(HAS_ITEM) ? 15 : 0;
}
@Override
public String getStatesPattern(Reader data) {
String texture = Registry.BLOCK.getId(this).getPath();
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, texture, texture);
}
@Override
public String getModelPattern(String block) {
Identifier blockId = Registry.BLOCK.getId(parent);
ResourceLocation blockId = Registry.BLOCK.getKey(parent);
String name = blockId.getPath();
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");
@ -367,12 +379,12 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
}
@Override
public Identifier statePatternId() {
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);