Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@
+ final org.bukkit.event.player.PlayerTeleportEvent tpEvent;
+ // Paper start - gateway-specific teleport event
+ if (this.portalProcess != null && this.portalProcess.isSamePortal(((net.minecraft.world.level.block.EndGatewayBlock) net.minecraft.world.level.block.Blocks.END_GATEWAY)) && this.level().getBlockEntity(this.portalProcess.getEntryPosition()) instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity theEndGatewayBlockEntity) {
+ tpEvent = new com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent(this.getBukkitEntity(), enter, exit.clone(), new org.bukkit.craftbukkit.block.CraftEndGateway(this.level().getWorld(), theEndGatewayBlockEntity));
+ tpEvent = new com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent(this.getBukkitEntity(), enter, exit.clone(), new org.bukkit.craftbukkit.block.CraftEndGateway(this.level().getWorld(), theEndGatewayBlockEntity, true));
+ } else {
+ tpEvent = new org.bukkit.event.player.PlayerTeleportEvent(this.getBukkitEntity(), enter, exit.clone(), transition.cause());
+ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@
+ // Paper start - gateway-specific teleport event
+ final org.bukkit.event.entity.EntityTeleportEvent teleEvent;
+ if (this.portalProcess != null && this.portalProcess.isSamePortal(((net.minecraft.world.level.block.EndGatewayBlock) Blocks.END_GATEWAY)) && this.level.getBlockEntity(this.portalProcess.getEntryPosition()) instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity theEndGatewayBlockEntity) {
+ teleEvent = new com.destroystokyo.paper.event.entity.EntityTeleportEndGatewayEvent(this.getBukkitEntity(), this.getBukkitEntity().getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(to.getWorld(), theEndGatewayBlockEntity));
+ teleEvent = new com.destroystokyo.paper.event.entity.EntityTeleportEndGatewayEvent(this.getBukkitEntity(), this.getBukkitEntity().getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(to.getWorld(), theEndGatewayBlockEntity, true));
+ teleEvent.callEvent();
+ } else {
+ teleEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTeleportEvent(this, to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
private DyeColor base;
private List<Pattern> patterns;

public CraftBanner(World world, BannerBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBanner(World world, BannerBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBanner(CraftBanner state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class CraftBarrel extends CraftLootable<BarrelBlockEntity> implements Barrel {

public CraftBarrel(World world, BarrelBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBarrel(World world, BarrelBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBarrel(CraftBarrel state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implements Beacon {

public CraftBeacon(World world, BeaconBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBeacon(World world, BeaconBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBeacon(CraftBeacon state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> implements Beehive {

public CraftBeehive(World world, BeehiveBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBeehive(World world, BeehiveBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBeehive(CraftBeehive state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class CraftBell extends CraftBlockEntityState<BellBlockEntity> implements Bell {

public CraftBell(World world, BellBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBell(World world, BellBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBell(CraftBell state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

public class CraftBlastFurnace extends CraftFurnace<BlastFurnaceBlockEntity> implements BlastFurnace {

public CraftBlastFurnace(World world, BlastFurnaceBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBlastFurnace(World world, BlastFurnaceBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBlastFurnace(CraftBlastFurnace state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
private final T blockEntity;
private final T snapshot;
public boolean snapshotDisabled; // Paper
public static boolean DISABLE_SNAPSHOT = false; // Paper

public CraftBlockEntityState(World world, T blockEntity) {
public CraftBlockEntityState(World world, T blockEntity, boolean useSnapshot) {
super(world, blockEntity.getBlockPos(), blockEntity.getBlockState());

this.blockEntity = blockEntity;

try { // Paper - Show blockstate location if we failed to read it
// Paper start
this.snapshotDisabled = DISABLE_SNAPSHOT;
if (DISABLE_SNAPSHOT) {
this.snapshotDisabled = !useSnapshot;
if (!useSnapshot) {
this.snapshot = this.blockEntity;
} else {
this.snapshot = this.createSnapshot(blockEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.BiFunction;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
Expand Down Expand Up @@ -37,43 +36,49 @@ public BlockStateFactory(Class<B> blockStateType) {
// If the given block entity is not null, its position and block data are expected to match the given block position and block data.
// In some situations, such as during chunk generation, the block entity's world may be null, even if the given world is not null.
// If the block entity's world is not null, it is expected to match the given world.
public abstract B createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity);
public abstract B createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity, boolean useSnapshot);
}

@FunctionalInterface
private interface BlockEntityStateConstructor<T, B> {

B create(World world, T blockEntity, boolean useSnapshot);
}

private static class BlockEntityStateFactory<T extends BlockEntity, B extends CraftBlockEntityState<T>> extends BlockStateFactory<B> {

private final BiFunction<World, T, B> blockStateConstructor;
private final BlockEntityStateConstructor<T, B> blockStateConstructor;
private final BlockEntityType<? extends T> blockEntityType;

protected BlockEntityStateFactory(Class<B> blockStateType, BiFunction<World, T, B> blockStateConstructor, BlockEntityType<? extends T> blockEntityType) {
protected BlockEntityStateFactory(Class<B> blockStateType, BlockEntityStateConstructor<T, B> blockStateConstructor, BlockEntityType<? extends T> blockEntityType) {
super(blockStateType);
this.blockStateConstructor = blockStateConstructor;
this.blockEntityType = blockEntityType;
}

@Override
public final B createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) {
public final B createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity, boolean useSnapshot) {
if (world != null) {
Preconditions.checkState(blockEntity != null, "Block entity is null, asynchronous access? %s", CraftBlock.at(((CraftWorld) world).getHandle(), pos));
} else if (blockEntity == null) {
blockEntity = this.createBlockEntity(pos, state);
}
return this.createBlockState(world, (T) blockEntity);
return this.createBlockState(world, (T) blockEntity, useSnapshot);
}

private T createBlockEntity(BlockPos pos, net.minecraft.world.level.block.state.BlockState state) {
return this.blockEntityType.create(pos, state);
}

private B createBlockState(World world, T blockEntity) {
return this.blockStateConstructor.apply(world, blockEntity);
private B createBlockState(World world, T blockEntity, boolean useSnapshot) {
return this.blockStateConstructor.create(world, blockEntity, useSnapshot);
}
}

private static final Map<Material, BlockStateFactory<?>> FACTORIES = new IdentityHashMap<>();
private static final BlockStateFactory<?> DEFAULT_FACTORY = new BlockStateFactory<>(CraftBlockState.class) {
@Override
public CraftBlockState createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) {
public CraftBlockState createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity, boolean useSnapshot) {
// Paper - revert upstream's revert of the block state changes. Block entities that have already had the block type set to AIR are still valid, upstream decided to ignore them
Preconditions.checkState(blockEntity == null, "Unexpected BlockState for %s", CraftBlockType.minecraftToBukkit(state.getBlock()));
return new CraftBlockState(world, pos, state);
Expand Down Expand Up @@ -146,7 +151,7 @@ private static void register(Material blockType, BlockStateFactory<?> factory) {
private static <T extends BlockEntity, B extends CraftBlockEntityState<T>> void register(
net.minecraft.world.level.block.entity.BlockEntityType<? extends T> blockEntityType,
Class<B> blockStateType,
BiFunction<World, T, B> blockStateConstructor
BlockEntityStateConstructor<T, B> blockStateConstructor
) {
BlockStateFactory<B> factory = new BlockEntityStateFactory<>(blockStateType, blockStateConstructor, blockEntityType);
for (net.minecraft.world.level.block.Block block : blockEntityType.validBlocks) {
Expand Down Expand Up @@ -198,15 +203,9 @@ public static BlockState getBlockState(Block block, boolean useSnapshot) {
BlockPos pos = craftBlock.getPosition();
net.minecraft.world.level.block.state.BlockState state = craftBlock.getBlockState();
BlockEntity blockEntity = craftBlock.getLevel().getBlockEntity(pos);
boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
try {
CraftBlockState blockState = CraftBlockStates.getBlockState(world, pos, state, blockEntity);
blockState.setWorldHandle(craftBlock.getLevel()); // Inject the block's level accessor
return blockState;
} finally {
CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
}
CraftBlockState blockState = CraftBlockStates.getBlockState(world, pos, state, blockEntity, useSnapshot);
blockState.setWorldHandle(craftBlock.getLevel()); // Inject the block's level accessor
return blockState;
}

@Deprecated
Expand Down Expand Up @@ -240,8 +239,12 @@ public static BlockState getBlockState(RegistryAccess registry, BlockPos pos, ne
return CraftBlockStates.getBlockState(null, pos, state, blockEntity);
}

// See BlockStateFactory#createBlockState(World, BlockPos, BlockState, BlockEntity)
// See BlockStateFactory#createBlockState(World, BlockPos, BlockState, BlockEntity, boolean)
public static CraftBlockState getBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) {
return CraftBlockStates.getBlockState(world, pos, state, blockEntity, true);
}

public static CraftBlockState getBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity, boolean useSnapshot) {
Material material = CraftBlockType.minecraftToBukkit(state.getBlock());
BlockStateFactory<?> factory;
// For some types of BlockEntity blocks (e.g. moving pistons), Minecraft may in some situations (e.g. when using Block#setType or the
Expand All @@ -251,7 +254,7 @@ public static CraftBlockState getBlockState(World world, BlockPos pos, net.minec
} else {
factory = CraftBlockStates.getFactory(material, blockEntity != null ? blockEntity.getType() : null); // Paper
}
return factory.createBlockState(world, pos, state, blockEntity);
return factory.createBlockState(world, pos, state, blockEntity, useSnapshot);
}

public static boolean isBlockEntityOptional(Material material) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

public class CraftBrewingStand extends CraftContainer<BrewingStandBlockEntity> implements BrewingStand {

public CraftBrewingStand(World world, BrewingStandBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBrewingStand(World world, BrewingStandBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBrewingStand(CraftBrewingStand state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

public class CraftBrushableBlock extends CraftBlockEntityState<BrushableBlockEntity> implements BrushableBlock {

public CraftBrushableBlock(World world, BrushableBlockEntity blockEntity) {
super(world, blockEntity);
public CraftBrushableBlock(World world, BrushableBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftBrushableBlock(CraftBrushableBlock state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

public class CraftCalibratedSculkSensor extends CraftSculkSensor<CalibratedSculkSensorBlockEntity> implements CalibratedSculkSensor {

public CraftCalibratedSculkSensor(World world, CalibratedSculkSensorBlockEntity blockEntity) {
super(world, blockEntity);
public CraftCalibratedSculkSensor(World world, CalibratedSculkSensorBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftCalibratedSculkSensor(CraftCalibratedSculkSensor state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> implements Campfire {

public CraftCampfire(World world, CampfireBlockEntity blockEntity) {
super(world, blockEntity);
public CraftCampfire(World world, CampfireBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftCampfire(CraftCampfire state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

public class CraftChest extends CraftLootable<ChestBlockEntity> implements Chest {

public CraftChest(World world, ChestBlockEntity blockEntity) {
super(world, blockEntity);
public CraftChest(World world, ChestBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftChest(CraftChest state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookShelfBlockEntity> implements ChiseledBookshelf {

public CraftChiseledBookshelf(World world, ChiseledBookShelfBlockEntity blockEntity) {
super(world, blockEntity);
public CraftChiseledBookshelf(World world, ChiseledBookShelfBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftChiseledBookshelf(CraftChiseledBookshelf state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity> implements CommandBlock, io.papermc.paper.commands.PaperCommandBlockHolder {

public CraftCommandBlock(World world, CommandBlockEntity blockEntity) {
super(world, blockEntity);
public CraftCommandBlock(World world, CommandBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftCommandBlock(CraftCommandBlock state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

public class CraftComparator extends CraftBlockEntityState<ComparatorBlockEntity> implements Comparator {

public CraftComparator(World world, ComparatorBlockEntity blockEntity) {
super(world, blockEntity);
public CraftComparator(World world, ComparatorBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftComparator(CraftComparator state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> implements Conduit {

public CraftConduit(World world, ConduitBlockEntity blockEntity) {
super(world, blockEntity);
public CraftConduit(World world, ConduitBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftConduit(CraftConduit state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends CraftBlockEntityState<T> implements Container {

public CraftContainer(World world, T blockEntity) {
super(world, blockEntity);
public CraftContainer(World world, T blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftContainer(CraftContainer<T> state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.bukkit.block.CopperGolemStatue;

public class CraftCopperGolemStatue extends CraftBlockEntityState<CopperGolemStatueBlockEntity> implements CopperGolemStatue {
public CraftCopperGolemStatue(World world, CopperGolemStatueBlockEntity blockEntity) {
super(world, blockEntity);
public CraftCopperGolemStatue(World world, CopperGolemStatueBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftCopperGolemStatue(CraftCopperGolemStatue state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class CraftCrafter extends CraftLootable<CrafterBlockEntity> implements Crafter {

public CraftCrafter(World world, CrafterBlockEntity blockEntity) {
super(world, blockEntity);
public CraftCrafter(World world, CrafterBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftCrafter(CraftCrafter state, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@NullMarked
public class CraftCreakingHeart extends CraftBlockEntityState<CreakingHeartBlockEntity> implements CreakingHeart {

public CraftCreakingHeart(World world, CreakingHeartBlockEntity blockEntity) {
super(world, blockEntity);
public CraftCreakingHeart(World world, CreakingHeartBlockEntity blockEntity, boolean useSnapshot) {
super(world, blockEntity, useSnapshot);
}

protected CraftCreakingHeart(CraftCreakingHeart state, @Nullable Location location) {
Expand Down
Loading
Loading