EndGatewayBlock .java

net.minecraft.world.level.block.EndGatewayBlock (class): members: getPortalDestination, getRenderShape, canBeReplaced, getCloneItemStack, effectApplier.

net.minecraft.world.level.blockclass122 linescommonextends BaseEntityBlock4.7 KB

Implements

API Surface (6)

BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState)
void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)
ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData)
boolean canBeReplaced(final BlockState state, final Fluid fluid)
void entityInside(final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise)
RenderShape getRenderShape(final BlockState state)

Fields & Constants (1)

effectApplier

Full Source

EndGatewayBlock.java122 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Set;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.particles.ParticleTypes;
6
import net.minecraft.server.level.ServerLevel;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.entity.Entity;
9
import net.minecraft.world.entity.InsideBlockEffectApplier;
10
import net.minecraft.world.entity.Relative;
11
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEnderpearl;
12
import net.minecraft.world.item.ItemStack;
13
import net.minecraft.world.level.Level;
14
import net.minecraft.world.level.LevelReader;
15
import net.minecraft.world.level.block.entity.BlockEntity;
16
import net.minecraft.world.level.block.entity.BlockEntityTicker;
17
import net.minecraft.world.level.block.entity.BlockEntityType;
18
import net.minecraft.world.level.block.entity.BlockEntityTypes;
19
import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
20
import net.minecraft.world.level.block.state.BlockBehaviour;
21
import net.minecraft.world.level.block.state.BlockState;
22
import net.minecraft.world.level.material.Fluid;
23
import net.minecraft.world.level.portal.TeleportTransition;
24
import net.minecraft.world.phys.Vec3;
25
import org.jspecify.annotations.Nullable;
26
27
/**
28
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
29
 */
30
public class EndGatewayBlock extends BaseEntityBlock implements Portal {
31
	/**
32
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
33
	 */
34
	public EndGatewayBlock(final BlockBehaviour.Properties properties) {
35
		super(properties);
36
	}
37
38
	@Override
39
	public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
40
		return new TheEndGatewayBlockEntity(worldPosition, blockState);
41
	}
42
43
	@Override
44
	public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
45
		return createTickerHelper(
46
			type, BlockEntityTypes.END_GATEWAY, level.isClientSide() ? TheEndGatewayBlockEntity::beamAnimationTick : TheEndGatewayBlockEntity::portalTick
47
		);
48
	}
49
50
	@Override
51
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
52
		if (level.getBlockEntity(pos) instanceof TheEndGatewayBlockEntity theEndGatewayBlockEntity) {
53
			int particleCount = theEndGatewayBlockEntity.getParticleAmount();
54
55
			for (int i = 0; i < particleCount; i++) {
56
				double x = pos.getX() + random.nextDouble();
57
				double y = pos.getY() + random.nextDouble();
58
				double z = pos.getZ() + random.nextDouble();
59
				double xa = (random.nextDouble() - 0.5) * 0.5;
60
				double ya = (random.nextDouble() - 0.5) * 0.5;
61
				double za = (random.nextDouble() - 0.5) * 0.5;
62
				int flip = random.nextInt(2) * 2 - 1;
63
				if (random.nextBoolean()) {
64
					z = pos.getZ() + 0.5 + 0.25 * flip;
65
					za = random.nextFloat() * 2.0F * flip;
66
				} else {
67
					x = pos.getX() + 0.5 + 0.25 * flip;
68
					xa = random.nextFloat() * 2.0F * flip;
69
				}
70
71
				level.addParticle(ParticleTypes.PORTAL, x, y, z, xa, ya, za);
72
			}
73
		}
74
	}
75
76
	@Override
77
	protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
78
		return ItemStack.EMPTY;
79
	}
80
81
	@Override
82
	protected boolean canBeReplaced(final BlockState state, final Fluid fluid) {
83
		return false;
84
	}
85
86
	@Override
87
	protected void entityInside(
88
		final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise
89
	) {
90
		if (entity.canUsePortal(false)
91
			&& !level.isClientSide()
92
			&& level.getBlockEntity(pos) instanceof TheEndGatewayBlockEntity endGatewayBlockEntity
93
			&& !endGatewayBlockEntity.isCoolingDown()) {
94
			entity.setAsInsidePortal(this, pos);
95
			TheEndGatewayBlockEntity.triggerCooldown(level, pos, state, endGatewayBlockEntity);
96
		}
97
	}
98
99
	@Override
100
	public @Nullable TeleportTransition getPortalDestination(final ServerLevel currentLevel, final Entity entity, final BlockPos portalEntryPos) {
101
		if (currentLevel.getBlockEntity(portalEntryPos) instanceof TheEndGatewayBlockEntity endGatewayBlockEntity) {
102
			Vec3 teleportPosition = endGatewayBlockEntity.getPortalPosition(currentLevel, portalEntryPos);
103
			if (teleportPosition == null) {
104
				return null;
105
			} else {
106
				return entity instanceof ThrownEnderpearl
107
					? new TeleportTransition(currentLevel, teleportPosition, Vec3.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET)
108
					: new TeleportTransition(
109
						currentLevel, teleportPosition, Vec3.ZERO, 0.0F, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), TeleportTransition.PLACE_PORTAL_TICKET
110
					);
111
			}
112
		} else {
113
			return null;
114
		}
115
	}
116
117
	@Override
118
	protected RenderShape getRenderShape(final BlockState state) {
119
		return RenderShape.INVISIBLE;
120
	}
121
}
122

Decompiled Minecraft 26.3 source of EndGatewayBlock (net/minecraft/world/level/block/EndGatewayBlock.java) with Mojang official mappings, stored verbatim on the site.