| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import java.util.Set;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.core.particles.ParticleTypes;
|
| 7 | import net.minecraft.resources.ResourceKey;
|
| 8 | import net.minecraft.server.level.ServerLevel;
|
| 9 | import net.minecraft.server.level.ServerPlayer;
|
| 10 | import net.minecraft.util.RandomSource;
|
| 11 | import net.minecraft.world.entity.Entity;
|
| 12 | import net.minecraft.world.entity.InsideBlockEffectApplier;
|
| 13 | import net.minecraft.world.entity.Relative;
|
| 14 | import net.minecraft.world.item.ItemStack;
|
| 15 | import net.minecraft.world.level.BlockGetter;
|
| 16 | import net.minecraft.world.level.Level;
|
| 17 | import net.minecraft.world.level.LevelReader;
|
| 18 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 19 | import net.minecraft.world.level.block.entity.TheEndPortalBlockEntity;
|
| 20 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 21 | import net.minecraft.world.level.block.state.BlockState;
|
| 22 | import net.minecraft.world.level.levelgen.feature.EndPlatformFeature;
|
| 23 | import net.minecraft.world.level.material.Fluid;
|
| 24 | import net.minecraft.world.level.portal.TeleportTransition;
|
| 25 | import net.minecraft.world.level.storage.LevelData;
|
| 26 | import net.minecraft.world.phys.Vec3;
|
| 27 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 28 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 29 | import org.jspecify.annotations.Nullable;
|
| 30 |
|
| 31 | /**
|
| 32 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 33 | */
|
| 34 | public class EndPortalBlock extends BaseEntityBlock implements Portal {
|
| 35 | private static final VoxelShape SHAPE = Block.column(16.0, 6.0, 12.0);
|
| 36 |
|
| 37 | /**
|
| 38 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 39 | */
|
| 40 | public EndPortalBlock(final BlockBehaviour.Properties properties) {
|
| 41 | super(properties);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
|
| 46 | return new TheEndPortalBlockEntity(worldPosition, blockState);
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 51 | return SHAPE;
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | protected VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity) {
|
| 56 | return state.getShape(level, pos);
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected void entityInside(
|
| 61 | final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise
|
| 62 | ) {
|
| 63 | if (entity.canUsePortal(false)) {
|
| 64 | if (!level.isClientSide() && level.dimension() == Level.END && entity instanceof ServerPlayer player && !player.seenCredits) {
|
| 65 | player.showEndCredits();
|
| 66 | } else {
|
| 67 | entity.setAsInsidePortal(this, pos);
|
| 68 | }
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | public @Nullable TeleportTransition getPortalDestination(final ServerLevel currentLevel, final Entity entity, final BlockPos portalEntryPos) {
|
| 74 | LevelData.RespawnData respawnData = currentLevel.getRespawnData();
|
| 75 | ResourceKey<Level> currentDimension = currentLevel.dimension();
|
| 76 | boolean fromEnd = currentDimension == Level.END;
|
| 77 | ResourceKey<Level> newDimension = fromEnd ? respawnData.dimension() : Level.END;
|
| 78 | BlockPos spawnBlockPos = fromEnd ? respawnData.pos() : ServerLevel.END_SPAWN_POINT;
|
| 79 | ServerLevel newLevel = currentLevel.getServer().getLevel(newDimension);
|
| 80 | if (newLevel == null) {
|
| 81 | return null;
|
| 82 | }
|
| 83 |
|
| 84 | Vec3 spawnPos = Vec3.atBottomCenterOf(spawnBlockPos);
|
| 85 | float yRot;
|
| 86 | float xRot;
|
| 87 | Set<Relative> relatives;
|
| 88 | if (!fromEnd) {
|
| 89 | EndPlatformFeature.createEndPlatform(newLevel, BlockPos.containing(spawnPos).below(), true);
|
| 90 | yRot = Direction.WEST.toYRot();
|
| 91 | xRot = 0.0F;
|
| 92 | relatives = Relative.union(Relative.DELTA, Set.of(Relative.X_ROT));
|
| 93 | if (entity instanceof ServerPlayer) {
|
| 94 | spawnPos = spawnPos.subtract(0.0, 1.0, 0.0);
|
| 95 | }
|
| 96 | } else {
|
| 97 | yRot = respawnData.yaw();
|
| 98 | xRot = respawnData.pitch();
|
| 99 | relatives = Relative.union(Relative.DELTA, Relative.ROTATION);
|
| 100 | if (entity instanceof ServerPlayer serverPlayer) {
|
| 101 | return serverPlayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING);
|
| 102 | }
|
| 103 |
|
| 104 | spawnPos = Vec3.atBottomCenterOf(entity.adjustSpawnLocation(newLevel, spawnBlockPos));
|
| 105 | }
|
| 106 |
|
| 107 | return new TeleportTransition(
|
| 108 | newLevel, spawnPos, Vec3.ZERO, yRot, xRot, relatives, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET)
|
| 109 | );
|
| 110 | }
|
| 111 |
|
| 112 | @Override
|
| 113 | public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
|
| 114 | double x = pos.getX() + random.nextDouble();
|
| 115 | double y = pos.getY() + 0.8;
|
| 116 | double z = pos.getZ() + random.nextDouble();
|
| 117 | level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0);
|
| 118 | }
|
| 119 |
|
| 120 | @Override
|
| 121 | protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
|
| 122 | return ItemStack.EMPTY;
|
| 123 | }
|
| 124 |
|
| 125 | @Override
|
| 126 | protected boolean canBeReplaced(final BlockState state, final Fluid fluid) {
|
| 127 | return false;
|
| 128 | }
|
| 129 |
|
| 130 | @Override
|
| 131 | protected RenderShape getRenderShape(final BlockState state) {
|
| 132 | return RenderShape.INVISIBLE;
|
| 133 | }
|
| 134 | }
|
| 135 |
|