91 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.world.level.block;
 | |
| 
 | |
| import com.mojang.serialization.MapCodec;
 | |
| import net.minecraft.core.BlockPos;
 | |
| import net.minecraft.core.particles.ParticleTypes;
 | |
| import net.minecraft.util.Mth;
 | |
| import net.minecraft.world.InteractionResult;
 | |
| import net.minecraft.world.entity.player.Player;
 | |
| import net.minecraft.world.level.BlockGetter;
 | |
| import net.minecraft.world.level.Level;
 | |
| import net.minecraft.world.level.block.state.BlockBehaviour;
 | |
| import net.minecraft.world.level.block.state.BlockState;
 | |
| import net.minecraft.world.level.border.WorldBorder;
 | |
| import net.minecraft.world.level.pathfinder.PathComputationType;
 | |
| import net.minecraft.world.phys.BlockHitResult;
 | |
| import net.minecraft.world.phys.shapes.CollisionContext;
 | |
| import net.minecraft.world.phys.shapes.VoxelShape;
 | |
| 
 | |
| public class DragonEggBlock extends FallingBlock {
 | |
| 	public static final MapCodec<DragonEggBlock> CODEC = simpleCodec(DragonEggBlock::new);
 | |
| 	private static final VoxelShape SHAPE = Block.column(14.0, 0.0, 16.0);
 | |
| 
 | |
| 	@Override
 | |
| 	public MapCodec<DragonEggBlock> codec() {
 | |
| 		return CODEC;
 | |
| 	}
 | |
| 
 | |
| 	public DragonEggBlock(BlockBehaviour.Properties properties) {
 | |
| 		super(properties);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
 | |
| 		return SHAPE;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
 | |
| 		this.teleport(state, level, pos);
 | |
| 		return InteractionResult.SUCCESS;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected void attack(BlockState state, Level level, BlockPos pos, Player player) {
 | |
| 		this.teleport(state, level, pos);
 | |
| 	}
 | |
| 
 | |
| 	private void teleport(BlockState state, Level level, BlockPos pos) {
 | |
| 		WorldBorder worldBorder = level.getWorldBorder();
 | |
| 
 | |
| 		for (int i = 0; i < 1000; i++) {
 | |
| 			BlockPos blockPos = pos.offset(
 | |
| 				level.random.nextInt(16) - level.random.nextInt(16), level.random.nextInt(8) - level.random.nextInt(8), level.random.nextInt(16) - level.random.nextInt(16)
 | |
| 			);
 | |
| 			if (level.getBlockState(blockPos).isAir() && worldBorder.isWithinBounds(blockPos)) {
 | |
| 				if (level.isClientSide) {
 | |
| 					for (int j = 0; j < 128; j++) {
 | |
| 						double d = level.random.nextDouble();
 | |
| 						float f = (level.random.nextFloat() - 0.5F) * 0.2F;
 | |
| 						float g = (level.random.nextFloat() - 0.5F) * 0.2F;
 | |
| 						float h = (level.random.nextFloat() - 0.5F) * 0.2F;
 | |
| 						double e = Mth.lerp(d, (double)blockPos.getX(), (double)pos.getX()) + (level.random.nextDouble() - 0.5) + 0.5;
 | |
| 						double k = Mth.lerp(d, (double)blockPos.getY(), (double)pos.getY()) + level.random.nextDouble() - 0.5;
 | |
| 						double l = Mth.lerp(d, (double)blockPos.getZ(), (double)pos.getZ()) + (level.random.nextDouble() - 0.5) + 0.5;
 | |
| 						level.addParticle(ParticleTypes.PORTAL, e, k, l, f, g, h);
 | |
| 					}
 | |
| 				} else {
 | |
| 					level.setBlock(blockPos, state, 2);
 | |
| 					level.removeBlock(pos, false);
 | |
| 				}
 | |
| 
 | |
| 				return;
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected int getDelayAfterPlace() {
 | |
| 		return 5;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
 | |
| 		return false;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getDustColor(BlockState state, BlockGetter level, BlockPos pos) {
 | |
| 		return -16777216;
 | |
| 	}
 | |
| }
 |