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

@ -7,33 +7,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.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
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.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.PlayerEntity;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.WorldView;
import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.BlockBase;
@ -49,25 +49,25 @@ import ru.betterend.util.MHelper;
public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IRenderTypeable {
private static final VoxelShape VOXEL_SHAPE_BOTTOM = Block.createCuboidShape(1, 0, 1, 15, 16, 15);
private static final VoxelShape VOXEL_SHAPE_MIDDLE_TOP = Block.createCuboidShape(2, 0, 2, 14, 16, 14);
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
public RespawnObeliskBlock() {
super(FabricBlockSettings.copyOf(Blocks.END_STONE).luminance((state) -> {
return (state.get(SHAPE) == TripleShape.BOTTOM) ? 0 : 15;
return (state.getValue(SHAPE) == TripleShape.BOTTOM) ? 0 : 15;
}));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
return (state.get(SHAPE) == TripleShape.BOTTOM) ? VOXEL_SHAPE_BOTTOM : VOXEL_SHAPE_MIDDLE_TOP;
return (state.getValue(SHAPE) == TripleShape.BOTTOM) ? VOXEL_SHAPE_BOTTOM : VOXEL_SHAPE_MIDDLE_TOP;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
for (int i = 0; i < 3; i++) {
@ -77,64 +77,59 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR
}
return true;
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
state = this.getDefaultState();
public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer,
ItemStack itemStack) {
state = this.defaultBlockState();
BlocksHelper.setWithUpdate(world, pos, state.with(SHAPE, TripleShape.BOTTOM));
BlocksHelper.setWithUpdate(world, pos.up(), state.with(SHAPE, TripleShape.MIDDLE));
BlocksHelper.setWithUpdate(world, pos.up(2), state.with(SHAPE, TripleShape.TOP));
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
TripleShape shape = state.get(SHAPE);
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
BlockPos pos, BlockPos neighborPos) {
TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) {
if (world.getBlockState(pos.up()).isOf(this)) {
if (world.getBlockState(pos.up()).is(this)) {
return state;
} else {
return Blocks.AIR.defaultBlockState();
}
else {
return Blocks.AIR.getDefaultState();
}
}
else if (shape == TripleShape.MIDDLE) {
if (world.getBlockState(pos.up()).isOf(this) && world.getBlockState(pos.down()).isOf(this)) {
} else if (shape == TripleShape.MIDDLE) {
if (world.getBlockState(pos.up()).is(this) && world.getBlockState(pos.below()).is(this)) {
return state;
} else {
return Blocks.AIR.defaultBlockState();
}
else {
return Blocks.AIR.getDefaultState();
}
}
else {
if (world.getBlockState(pos.down()).isOf(this)) {
} else {
if (world.getBlockState(pos.below()).is(this)) {
return state;
}
else {
return Blocks.AIR.getDefaultState();
} else {
return Blocks.AIR.defaultBlockState();
}
}
}
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
public void onBreak(Level world, BlockPos pos, BlockState state, PlayerEntity player) {
if (player.isCreative()) {
TripleShape shape = state.get(SHAPE);
TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.MIDDLE) {
BlocksHelper.setWithUpdate(world, pos.down(), Blocks.AIR);
}
else if (shape == TripleShape.TOP) {
BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR);
} else if (shape == TripleShape.TOP) {
BlocksHelper.setWithUpdate(world, pos.down(2), Blocks.AIR);
}
}
super.onBreak(world, pos, state, player);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
if (state.get(SHAPE) == TripleShape.BOTTOM) {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(SHAPE) == TripleShape.BOTTOM) {
return Lists.newArrayList(new ItemStack(this));
}
else {
} else {
return Lists.newArrayList();
}
}
@ -143,60 +138,59 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR
public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT;
}
@Override
public BlockColorProvider getProvider() {
return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getProvider();
public BlockColor getBlockProvider() {
return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getBlockProvider();
}
@Override
public ItemColorProvider getItemProvider() {
public ItemColor getItemProvider() {
return (stack, tintIndex) -> {
return MHelper.color(255, 255, 255);
};
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
public ActionResult onUse(BlockState state, Level world, BlockPos pos, PlayerEntity player, Hand hand,
BlockHitResult hit) {
ItemStack itemStack = player.getStackInHand(hand);
boolean canActivate = itemStack.getItem() == EndItems.AMBER_GEM && itemStack.getCount() > 5;
if (hand != Hand.MAIN_HAND || !canActivate) {
if (!world.isClient && !(itemStack.getItem() instanceof BlockItem) && !player.isCreative()) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) player;
if (!world.isClientSide && !(itemStack.getItem() instanceof BlockItem) && !player.isCreative()) {
ServerPlayer serverPlayerEntity = (ServerPlayer) player;
serverPlayerEntity.sendMessage(new TranslatableText("message.betterend.fail_spawn"), true);
}
return ActionResult.FAIL;
}
else if (!world.isClient) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) player;
serverPlayerEntity.setSpawnPoint(world.getRegistryKey(), pos, 0.0F, false, false);
} else if (!world.isClientSide) {
ServerPlayer serverPlayerEntity = (ServerPlayer) player;
serverPlayerEntity.setSpawnPoint(world.dimension(), pos, 0.0F, false, false);
serverPlayerEntity.sendMessage(new TranslatableText("message.betterend.set_spawn"), true);
double px = pos.getX() + 0.5;
double py = pos.getY() + 0.5;
double pz = pos.getZ() + 0.5;
InfusionParticleType particle = new InfusionParticleType(new ItemStack(EndItems.AMBER_GEM));
if (world instanceof ServerWorld) {
if (world instanceof ServerLevel) {
double py1 = py;
double py2 = py - 0.2;
if (state.get(SHAPE) == TripleShape.BOTTOM) {
if (state.getValue(SHAPE) == TripleShape.BOTTOM) {
py1 += 1;
py2 += 2;
}
else if (state.get(SHAPE) == TripleShape.MIDDLE) {
} else if (state.getValue(SHAPE) == TripleShape.MIDDLE) {
py1 += 0;
py2 += 1;
}
else {
} else {
py1 -= 2;
}
((ServerWorld) world).spawnParticles(particle, px, py1, pz, 20, 0.14, 0.5, 0.14, 0.1);
((ServerWorld) world).spawnParticles(particle, px, py2, pz, 20, 0.14, 0.3, 0.14, 0.1);
((ServerLevel) world).sendParticles(particle, px, py1, pz, 20, 0.14, 0.5, 0.14, 0.1);
((ServerLevel) world).sendParticles(particle, px, py2, pz, 20, 0.14, 0.3, 0.14, 0.1);
}
world.playLocalSound(null, px, py, py, SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1F,
1F);
if (!player.isCreative()) {
itemStack.decrement(6);
}
world.playSound(null, px, py, py, SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN, SoundCategory.BLOCKS, 1F, 1F);
if (!player.isCreative()) {
itemStack.decrement(6);
}
}
return player.isCreative() ? ActionResult.PASS : ActionResult.success(world.isClient);
return player.isCreative() ? ActionResult.PASS : ActionResult.success(world.isClientSide);
}
}