Co-authored-by: Bjarne Koll <git@lynxplay.dev>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Co-authored-by: MiniDigger | Martin <admin@minidigger.dev>
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com>
Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
This commit is contained in:
Nassim Jahnke
2025-04-12 17:26:44 +02:00
parent 0767902699
commit f00727c57e
2092 changed files with 50551 additions and 48729 deletions

View File

@@ -42,7 +42,6 @@ public class CraftArt extends OldEnumHolderable<Art, PaintingVariant> implements
return this.getHandle().height();
}
// Paper start - Expand Art API
@Override
public Component title() {
return this.getHandle().title().map(PaperAdventure::asAdventure).orElse(null);
@@ -53,10 +52,10 @@ public class CraftArt extends OldEnumHolderable<Art, PaintingVariant> implements
return this.getHandle().author().map(PaperAdventure::asAdventure).orElse(null);
}
@Override
public net.kyori.adventure.key.Key assetId() {
return PaperAdventure.asAdventure(this.getHandle().assetId());
}
// Paper end - Expand Art API
@Override
public int getId() {

View File

@@ -4,25 +4,21 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.mojang.serialization.Codec;
import io.papermc.paper.FeatureHooks;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;
import java.util.List;
import java.util.function.Predicate;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.thread.ConsecutiveExecutor;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.DataLayer;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
@@ -30,9 +26,7 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.chunk.storage.EntityStorage;
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.lighting.LevelLightEngine;
@@ -54,7 +48,7 @@ import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.plugin.Plugin;
public class CraftChunk implements Chunk {
private final ServerLevel worldServer;
private final ServerLevel level;
private final int x;
private final int z;
private static final PalettedContainer<net.minecraft.world.level.block.state.BlockState> emptyBlockIDs = FeatureHooks.emptyPalettedBlockContainer();
@@ -62,20 +56,20 @@ public class CraftChunk implements Chunk {
private static final byte[] EMPTY_LIGHT = new byte[2048];
public CraftChunk(net.minecraft.world.level.chunk.LevelChunk chunk) {
this.worldServer = chunk.level;
this.level = chunk.level;
this.x = chunk.getPos().x;
this.z = chunk.getPos().z;
}
public CraftChunk(ServerLevel worldServer, int x, int z) {
this.worldServer = worldServer;
public CraftChunk(ServerLevel level, int x, int z) {
this.level = level;
this.x = x;
this.z = z;
}
@Override
public World getWorld() {
return this.worldServer.getWorld();
return this.level.getWorld();
}
public CraftWorld getCraftWorld() {
@@ -84,12 +78,12 @@ public class CraftChunk implements Chunk {
public ChunkAccess getHandle(ChunkStatus chunkStatus) {
// Paper start - chunk system
net.minecraft.world.level.chunk.LevelChunk full = this.worldServer.getChunkIfLoaded(this.x, this.z);
net.minecraft.world.level.chunk.LevelChunk full = this.level.getChunkIfLoaded(this.x, this.z);
if (full != null) {
return full;
}
// Paper end - chunk system
ChunkAccess chunkAccess = this.worldServer.getChunk(this.x, this.z, chunkStatus);
ChunkAccess chunkAccess = this.level.getChunk(this.x, this.z, chunkStatus);
// SPIGOT-7332: Get unwrapped extension
if (chunkAccess instanceof ImposterProtoChunk extension) {
@@ -116,9 +110,9 @@ public class CraftChunk implements Chunk {
@Override
public Block getBlock(int x, int y, int z) {
CraftChunk.validateChunkCoordinates(this.worldServer.getMinY(), this.worldServer.getMaxY(), x, y, z);
CraftChunk.validateChunkCoordinates(this.level.getMinY(), this.level.getMaxY(), x, y, z);
return new CraftBlock(this.worldServer, new BlockPos((this.x << 4) | x, y, (this.z << 4) | z));
return new CraftBlock(this.level, new BlockPos((this.x << 4) | x, y, (this.z << 4) | z));
}
@Override
@@ -128,53 +122,49 @@ public class CraftChunk implements Chunk {
@Override
public Entity[] getEntities() {
return FeatureHooks.getChunkEntities(this.worldServer, this.x, this.z); // Paper - chunk system
return FeatureHooks.getChunkEntities(this.level, this.x, this.z); // Paper - chunk system
}
@Override
public BlockState[] getTileEntities() {
// Paper start
return getTileEntities(true);
return this.getTileEntities(true);
}
@Override
public BlockState[] getTileEntities(boolean useSnapshot) {
// Paper end
if (!this.isLoaded()) {
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
}
int index = 0;
ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
BlockState[] entities = new BlockState[chunk.blockEntities.size()];
for (BlockPos position : chunk.blockEntities.keySet()) {
// Paper start
entities[index++] = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState(useSnapshot);
BlockState[] states = new BlockState[chunk.blockEntities.size()];
for (BlockPos pos : chunk.blockEntities.keySet()) {
states[index++] = CraftBlock.at(this.level, pos).getState(useSnapshot);
}
return entities;
return states;
}
@Override
public Collection<BlockState> getTileEntities(Predicate<? super Block> blockPredicate, boolean useSnapshot) {
Preconditions.checkNotNull(blockPredicate, "blockPredicate");
Preconditions.checkArgument(blockPredicate != null, "blockPredicate cannot be null");
if (!this.isLoaded()) {
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
}
ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
java.util.List<BlockState> entities = new java.util.ArrayList<>();
for (BlockPos position : chunk.blockEntities.keySet()) {
Block block = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
List<BlockState> states = new ArrayList<>();
for (BlockPos pos : chunk.blockEntities.keySet()) {
Block block = CraftBlock.at(this.level, pos);
if (blockPredicate.test(block)) {
entities.add(block.getState(useSnapshot));
states.add(block.getState(useSnapshot));
}
// Paper end
}
return entities;
return states;
}
@Override
@@ -205,8 +195,8 @@ public class CraftChunk implements Chunk {
@Override
public boolean isSlimeChunk() {
// 987234911L is deterimined in EntitySlime when seeing if a slime can spawn in a chunk
return this.worldServer.paperConfig().entities.spawning.allChunksAreSlimeChunks || WorldgenRandom.seedSlimeChunk(this.getX(), this.getZ(), this.getWorld().getSeed(), worldServer.spigotConfig.slimeSeed).nextInt(10) == 0; // Paper
// 987234911L is taken from Slime when seeing if a slime can spawn in a chunk
return this.level.paperConfig().entities.spawning.allChunksAreSlimeChunks || WorldgenRandom.seedSlimeChunk(this.getX(), this.getZ(), this.getWorld().getSeed(), level.spigotConfig.slimeSeed).nextInt(10) == 0; // Paper
}
@Override
@@ -255,9 +245,9 @@ public class CraftChunk implements Chunk {
public boolean contains(BlockData block) {
Preconditions.checkArgument(block != null, "Block cannot be null");
Predicate<net.minecraft.world.level.block.state.BlockState> nms = Predicates.equalTo(((CraftBlockData) block).getState());
Predicate<net.minecraft.world.level.block.state.BlockState> filter = Predicates.equalTo(((CraftBlockData) block).getState());
for (LevelChunkSection section : this.getHandle(ChunkStatus.FULL).getSections()) {
if (section != null && section.getStates().maybeHas(nms)) {
if (section != null && section.getStates().maybeHas(filter)) {
return true;
}
}
@@ -270,9 +260,9 @@ public class CraftChunk implements Chunk {
Preconditions.checkArgument(biome != null, "Biome cannot be null");
ChunkAccess chunk = this.getHandle(ChunkStatus.BIOMES);
Predicate<Holder<net.minecraft.world.level.biome.Biome>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
Predicate<Holder<net.minecraft.world.level.biome.Biome>> filter = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
for (LevelChunkSection section : chunk.getSections()) {
if (section != null && section.getBiomes().maybeHas(nms)) {
if (section != null && section.getBiomes().maybeHas(filter)) {
return true;
}
}
@@ -287,26 +277,20 @@ public class CraftChunk implements Chunk {
@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain) {
// Paper start - Add getChunkSnapshot includeLightData parameter
return getChunkSnapshot(includeMaxBlockY, includeBiome, includeBiomeTempRain, true);
}
@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain, boolean includeLightData) {
// Paper end - Add getChunkSnapshot includeLightData parameter
ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
LevelChunkSection[] cs = chunk.getSections();
PalettedContainer[] sectionBlockIDs = new PalettedContainer[cs.length];
// Paper start - Add getChunkSnapshot includeLightData parameter
byte[][] sectionSkyLights = includeLightData ? new byte[cs.length][] : null;
byte[][] sectionEmitLights = includeLightData ? new byte[cs.length][] : null;
// Paper end - Add getChunkSnapshot includeLightData parameter
boolean[] sectionEmpty = new boolean[cs.length];
PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>[] biome = (includeBiome || includeBiomeTempRain) ? new PalettedContainer[cs.length] : null;
Registry<net.minecraft.world.level.biome.Biome> iregistry = this.worldServer.registryAccess().lookupOrThrow(Registries.BIOME);
for (int i = 0; i < cs.length; i++) {
// Paper start - Fix ChunkSnapshot#isSectionEmpty(int); and remove codec usage
@@ -318,38 +302,39 @@ public class CraftChunk implements Chunk {
}
// Paper end - Fix ChunkSnapshot#isSectionEmpty(int)
if (includeLightData) { // Paper - Add getChunkSnapshot includeLightData parameter
LevelLightEngine lightengine = this.worldServer.getLightEngine();
DataLayer skyLightArray = lightengine.getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(this.x, chunk.getSectionYFromSectionIndex(i), this.z)); // SPIGOT-7498: Convert section index
if (skyLightArray == null) {
sectionSkyLights[i] = this.worldServer.dimensionType().hasSkyLight() ? CraftChunk.FULL_LIGHT : CraftChunk.EMPTY_LIGHT;
} else {
sectionSkyLights[i] = new byte[2048];
System.arraycopy(skyLightArray.getData(), 0, sectionSkyLights[i], 0, 2048);
if (includeLightData) {
LevelLightEngine lightEngine = this.level.getLightEngine();
DataLayer skyLightArray = lightEngine.getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(this.x, chunk.getSectionYFromSectionIndex(i), this.z)); // SPIGOT-7498: Convert section index
if (skyLightArray == null) {
sectionSkyLights[i] = this.level.dimensionType().hasSkyLight() ? CraftChunk.FULL_LIGHT : CraftChunk.EMPTY_LIGHT;
} else {
sectionSkyLights[i] = new byte[2048];
System.arraycopy(skyLightArray.getData(), 0, sectionSkyLights[i], 0, 2048);
}
DataLayer emitLightArray = lightEngine.getLayerListener(LightLayer.BLOCK).getDataLayerData(SectionPos.of(this.x, chunk.getSectionYFromSectionIndex(i), this.z)); // SPIGOT-7498: Convert section index
if (emitLightArray == null) {
sectionEmitLights[i] = CraftChunk.EMPTY_LIGHT;
} else {
sectionEmitLights[i] = new byte[2048];
System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
}
}
DataLayer emitLightArray = lightengine.getLayerListener(LightLayer.BLOCK).getDataLayerData(SectionPos.of(this.x, chunk.getSectionYFromSectionIndex(i), this.z)); // SPIGOT-7498: Convert section index
if (emitLightArray == null) {
sectionEmitLights[i] = CraftChunk.EMPTY_LIGHT;
} else {
sectionEmitLights[i] = new byte[2048];
System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
}
} // Paper - Add getChunkSnapshot includeLightData parameter
if (biome != null) {
biome[i] = ((PalettedContainer<Holder<net.minecraft.world.level.biome.Biome>>) cs[i].getBiomes()).copy(); // Paper - Perf: use copy instead of round tripping with codecs
biome[i] = cs[i].getBiomes().copy(); // Paper - Perf: use copy instead of round tripping with codecs
}
}
Heightmap hmap = null;
Heightmap heightmap = null;
if (includeMaxBlockY) {
hmap = new Heightmap(chunk, Heightmap.Types.MOTION_BLOCKING);
hmap.setRawData(chunk, Heightmap.Types.MOTION_BLOCKING, chunk.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).getRawData());
heightmap = new Heightmap(chunk, Heightmap.Types.MOTION_BLOCKING);
heightmap.setRawData(chunk, Heightmap.Types.MOTION_BLOCKING, chunk.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).getRawData());
}
World world = this.getWorld();
return new CraftChunkSnapshot(this.getX(), this.getZ(), chunk.getMinY(), chunk.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, iregistry, biome);
return new CraftChunkSnapshot(this.getX(), this.getZ(), chunk.getMinY(), chunk.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, heightmap, biome);
}
@Override
@@ -359,7 +344,7 @@ public class CraftChunk implements Chunk {
@Override
public LoadLevel getLoadLevel() {
net.minecraft.world.level.chunk.LevelChunk chunk = this.worldServer.getChunkIfLoaded(this.getX(), this.getZ());
net.minecraft.world.level.chunk.LevelChunk chunk = this.level.getChunkIfLoaded(this.getX(), this.getZ());
if (chunk == null) {
return LoadLevel.UNLOADED;
}
@@ -390,12 +375,12 @@ public class CraftChunk implements Chunk {
if (this.x != that.x) return false;
if (this.z != that.z) return false;
return this.worldServer.equals(that.worldServer);
return this.level.equals(that.level);
}
@Override
public int hashCode() {
int result = this.worldServer.hashCode();
int result = this.level.hashCode();
result = 31 * result + this.x;
result = 31 * result + this.z;
return result;
@@ -410,9 +395,9 @@ public class CraftChunk implements Chunk {
byte[][] skyLight = new byte[hSection][];
byte[][] emitLight = new byte[hSection][];
boolean[] empty = new boolean[hSection];
Registry<net.minecraft.world.level.biome.Biome> iregistry = world.getHandle().registryAccess().lookupOrThrow(Registries.BIOME);
Registry<net.minecraft.world.level.biome.Biome> registry = world.getHandle().registryAccess().lookupOrThrow(Registries.BIOME);
PalettedContainer<Holder<net.minecraft.world.level.biome.Biome>>[] biome = (includeBiome || includeBiomeTempRain) ? new PalettedContainer[hSection] : null;
Codec<PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>> biomeCodec = PalettedContainer.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
Codec<PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>> biomeCodec = PalettedContainer.codecRO(registry.asHolderIdMap(), registry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, registry.getOrThrow(Biomes.PLAINS));
for (int i = 0; i < hSection; i++) {
blockIDs[i] = CraftChunk.emptyBlockIDs;
@@ -425,7 +410,7 @@ public class CraftChunk implements Chunk {
}
}
return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new Heightmap(actual, Heightmap.Types.MOTION_BLOCKING), iregistry, biome);
return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new Heightmap(actual, Heightmap.Types.MOTION_BLOCKING), biome);
}
static void validateChunkCoordinates(int minY, int maxY, int x, int y, int z) {

View File

@@ -5,7 +5,6 @@ import com.google.common.base.Predicates;
import java.util.function.Predicate;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO;
@@ -15,7 +14,6 @@ import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.CraftBiome;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@@ -26,30 +24,28 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers;
public class CraftChunkSnapshot implements ChunkSnapshot {
private final int x, z;
private final int minHeight, maxHeight, seaLevel;
private final String worldname;
private final PalettedContainer<BlockState>[] blockids;
private final String worldName;
private final PalettedContainer<BlockState>[] blockIds;
private final byte[][] skylight;
private final byte[][] emitlight;
private final byte[][] emitLight;
private final boolean[] empty;
private final Heightmap hmap; // Height map
private final long captureFulltime;
private final Registry<net.minecraft.world.level.biome.Biome> biomeRegistry;
private final Heightmap heightmap; // Height map
private final long captureFullTime;
private final PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>[] biome;
CraftChunkSnapshot(int x, int z, int minHeight, int maxHeight, int seaLevel, String wname, long wtime, PalettedContainer<BlockState>[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, Heightmap hmap, Registry<net.minecraft.world.level.biome.Biome> biomeRegistry, PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>[] biome) {
CraftChunkSnapshot(int x, int z, int minHeight, int maxHeight, int seaLevel, String worldName, long fullTime, PalettedContainer<BlockState>[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, Heightmap heightmap, PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>[] biome) {
this.x = x;
this.z = z;
this.minHeight = minHeight;
this.maxHeight = maxHeight;
this.seaLevel = seaLevel;
this.worldname = wname;
this.captureFulltime = wtime;
this.blockids = sectionBlockIDs;
this.worldName = worldName;
this.captureFullTime = fullTime;
this.blockIds = sectionBlockIDs;
this.skylight = sectionSkyLights;
this.emitlight = sectionEmitLights;
this.emitLight = sectionEmitLights;
this.empty = sectionEmpty;
this.hmap = hmap;
this.biomeRegistry = biomeRegistry;
this.heightmap = heightmap;
this.biome = biome;
}
@@ -65,16 +61,16 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override
public String getWorldName() {
return this.worldname;
return this.worldName;
}
@Override
public boolean contains(BlockData block) {
Preconditions.checkArgument(block != null, "Block cannot be null");
Predicate<BlockState> nms = Predicates.equalTo(((CraftBlockData) block).getState());
for (PalettedContainer<BlockState> palette : this.blockids) {
if (palette.maybeHas(nms)) {
Predicate<BlockState> filter = Predicates.equalTo(((CraftBlockData) block).getState());
for (PalettedContainer<BlockState> palette : this.blockIds) {
if (palette.maybeHas(filter)) {
return true;
}
}
@@ -86,9 +82,9 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
public boolean contains(Biome biome) {
Preconditions.checkArgument(biome != null, "Biome cannot be null");
Predicate<Holder<net.minecraft.world.level.biome.Biome>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
Predicate<Holder<net.minecraft.world.level.biome.Biome>> filter = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
for (PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>> palette : this.biome) {
if (palette.maybeHas(nms)) {
if (palette.maybeHas(filter)) {
return true;
}
}
@@ -100,21 +96,21 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
public Material getBlockType(int x, int y, int z) {
this.validateChunkCoordinates(x, y, z);
return this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBukkitMaterial(); // Paper - optimise getType calls
return this.blockIds[this.getSectionIndex(y)].get(x, y & 0xF, z).getBukkitMaterial(); // Paper - optimise get calls
}
@Override
public final BlockData getBlockData(int x, int y, int z) {
this.validateChunkCoordinates(x, y, z);
return CraftBlockData.fromData(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z));
return CraftBlockData.fromData(this.blockIds[this.getSectionIndex(y)].get(x, y & 0xF, z));
}
@Override
public final int getData(int x, int y, int z) {
this.validateChunkCoordinates(x, y, z);
return CraftMagicNumbers.toLegacyData(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z));
return CraftMagicNumbers.toLegacyData(this.blockIds[this.getSectionIndex(y)].get(x, y & 0xF, z));
}
@Override
@@ -128,19 +124,19 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override
public final int getBlockEmittedLight(int x, int y, int z) {
Preconditions.checkState(this.emitlight != null, "ChunkSnapshot created without light data. Please call getSnapshot with includeLightData=true"); // Paper - Add getChunkSnapshot includeLightData parameter
Preconditions.checkState(this.emitLight != null, "ChunkSnapshot created without light data. Please call getSnapshot with includeLightData=true"); // Paper - Add getChunkSnapshot includeLightData parameter
this.validateChunkCoordinates(x, y, z);
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (this.emitlight[this.getSectionIndex(y)][off] >> ((x & 1) << 2)) & 0xF;
return (this.emitLight[this.getSectionIndex(y)][off] >> ((x & 1) << 2)) & 0xF;
}
@Override
public final int getHighestBlockYAt(int x, int z) {
Preconditions.checkState(this.hmap != null, "ChunkSnapshot created without height map. Please call getSnapshot with includeMaxblocky=true");
Preconditions.checkState(this.heightmap != null, "ChunkSnapshot created without height map. Please call getSnapshot with includeMaxblocky=true");
this.validateChunkCoordinates(x, 0, z);
return this.hmap.getHighestTaken(x, z);
return this.heightmap.getHighestTaken(x, z);
}
@Override
@@ -173,7 +169,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override
public final long getCaptureFullTime() {
return this.captureFulltime;
return this.captureFullTime;
}
@Override

View File

@@ -18,10 +18,10 @@ public class CraftCrashReport implements Supplier<String> {
@Override
public String get() {
final io.papermc.paper.ServerBuildInfo build = io.papermc.paper.ServerBuildInfo.buildInfo(); // Paper
final io.papermc.paper.ServerBuildInfo build = io.papermc.paper.ServerBuildInfo.buildInfo();
StringWriter value = new StringWriter();
try {
value.append("\n BrandInfo: ").append(String.format("%s (%s) version %s", build.brandName(), build.brandId(), build.asString(io.papermc.paper.ServerBuildInfo.StringRepresentation.VERSION_FULL))); // Paper
value.append("\n BrandInfo: ").append(String.format("%s (%s) version %s", build.brandName(), build.brandId(), build.asString(io.papermc.paper.ServerBuildInfo.StringRepresentation.VERSION_FULL)));
value.append("\n Running: ").append(Bukkit.getName()).append(" version ").append(Bukkit.getVersion()).append(" (Implementing API version ").append(Bukkit.getBukkitVersion()).append(") ").append(String.valueOf(MinecraftServer.getServer().usesAuthentication()));
value.append("\n Plugins: {");
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {

View File

@@ -1,54 +1,55 @@
package org.bukkit.craftbukkit;
import java.util.Locale;
import com.google.common.collect.BiMap;
import com.google.common.collect.EnumBiMap;
import net.minecraft.Util;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlotGroup;
import org.bukkit.inventory.EquipmentSlot;
public class CraftEquipmentSlot {
public final class CraftEquipmentSlot {
private static final net.minecraft.world.entity.EquipmentSlot[] slots = new net.minecraft.world.entity.EquipmentSlot[EquipmentSlot.values().length];
private static final EquipmentSlot[] enums = new EquipmentSlot[net.minecraft.world.entity.EquipmentSlot.values().length];
static {
set(EquipmentSlot.HAND, net.minecraft.world.entity.EquipmentSlot.MAINHAND);
set(EquipmentSlot.OFF_HAND, net.minecraft.world.entity.EquipmentSlot.OFFHAND);
set(EquipmentSlot.FEET, net.minecraft.world.entity.EquipmentSlot.FEET);
set(EquipmentSlot.LEGS, net.minecraft.world.entity.EquipmentSlot.LEGS);
set(EquipmentSlot.CHEST, net.minecraft.world.entity.EquipmentSlot.CHEST);
set(EquipmentSlot.HEAD, net.minecraft.world.entity.EquipmentSlot.HEAD);
set(EquipmentSlot.BODY, net.minecraft.world.entity.EquipmentSlot.BODY);
private CraftEquipmentSlot() {
}
private static void set(EquipmentSlot type, net.minecraft.world.entity.EquipmentSlot value) {
CraftEquipmentSlot.slots[type.ordinal()] = value;
CraftEquipmentSlot.enums[value.ordinal()] = type;
private static final BiMap<net.minecraft.world.entity.EquipmentSlot, EquipmentSlot> BRIDGE =
Util.make(EnumBiMap.create(net.minecraft.world.entity.EquipmentSlot.class, EquipmentSlot.class), data -> {
data.put(net.minecraft.world.entity.EquipmentSlot.MAINHAND, EquipmentSlot.HAND);
data.put(net.minecraft.world.entity.EquipmentSlot.OFFHAND, EquipmentSlot.OFF_HAND);
data.put(net.minecraft.world.entity.EquipmentSlot.FEET, EquipmentSlot.FEET);
data.put(net.minecraft.world.entity.EquipmentSlot.LEGS, EquipmentSlot.LEGS);
data.put(net.minecraft.world.entity.EquipmentSlot.CHEST, EquipmentSlot.CHEST);
data.put(net.minecraft.world.entity.EquipmentSlot.HEAD, EquipmentSlot.HEAD);
data.put(net.minecraft.world.entity.EquipmentSlot.BODY, EquipmentSlot.BODY);
data.put(net.minecraft.world.entity.EquipmentSlot.SADDLE, EquipmentSlot.SADDLE);
});
public static EquipmentSlot getSlot(net.minecraft.world.entity.EquipmentSlot slot) {
return BRIDGE.get(slot);
}
public static EquipmentSlot getSlot(net.minecraft.world.entity.EquipmentSlot nms) {
return CraftEquipmentSlot.enums[nms.ordinal()];
}
public static org.bukkit.inventory.EquipmentSlotGroup getSlot(EquipmentSlotGroup nms) {
return org.bukkit.inventory.EquipmentSlotGroup.getByName(nms.getSerializedName());
public static org.bukkit.inventory.EquipmentSlotGroup getSlotGroup(EquipmentSlotGroup slotGroup) {
return org.bukkit.inventory.EquipmentSlotGroup.getByName(slotGroup.getSerializedName());
}
public static net.minecraft.world.entity.EquipmentSlot getNMS(EquipmentSlot slot) {
return CraftEquipmentSlot.slots[slot.ordinal()];
return BRIDGE.inverse().get(slot);
}
public static EquipmentSlotGroup getNMSGroup(org.bukkit.inventory.EquipmentSlotGroup slot) {
return EquipmentSlotGroup.valueOf(slot.toString().toUpperCase(Locale.ROOT));
}
public static EquipmentSlot getHand(InteractionHand enumhand) {
return (enumhand == InteractionHand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
public static EquipmentSlot getHand(InteractionHand hand) {
return hand == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
}
public static InteractionHand getHand(EquipmentSlot hand) {
if (hand == EquipmentSlot.HAND) {
return InteractionHand.MAIN_HAND;
} else if (hand == EquipmentSlot.OFF_HAND) {
}
if (hand == EquipmentSlot.OFF_HAND) {
return InteractionHand.OFF_HAND;
}

View File

@@ -8,20 +8,14 @@ public final class CraftExplosionResult {
private CraftExplosionResult() {}
public static ExplosionResult toBukkit(Explosion.BlockInteraction effect) {
public static ExplosionResult toExplosionResult(Explosion.BlockInteraction effect) {
Preconditions.checkArgument(effect != null, "explosion effect cannot be null");
switch (effect) {
case KEEP:
return ExplosionResult.KEEP;
case DESTROY:
return ExplosionResult.DESTROY;
case DESTROY_WITH_DECAY:
return ExplosionResult.DESTROY_WITH_DECAY;
case TRIGGER_BLOCK:
return ExplosionResult.TRIGGER_BLOCK;
default:
throw new IllegalArgumentException("There is no ExplosionResult which matches " + effect);
}
return switch (effect) {
case KEEP -> ExplosionResult.KEEP;
case DESTROY -> ExplosionResult.DESTROY;
case DESTROY_WITH_DECAY -> ExplosionResult.DESTROY_WITH_DECAY;
case TRIGGER_BLOCK -> ExplosionResult.TRIGGER_BLOCK;
};
}
}

View File

@@ -1,13 +1,13 @@
package org.bukkit.craftbukkit;
import java.util.Locale;
import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import org.bukkit.Fluid;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
public class CraftFluid implements Fluid, Handleable<net.minecraft.world.level.material.Fluid> {
@NullMarked
public class CraftFluid extends OldEnumHolderable<Fluid, net.minecraft.world.level.material.Fluid> implements Fluid {
private static int count = 0;
@@ -19,74 +19,7 @@ public class CraftFluid implements Fluid, Handleable<net.minecraft.world.level.m
return CraftRegistry.bukkitToMinecraft(bukkit);
}
private final NamespacedKey key;
private final net.minecraft.world.level.material.Fluid fluidType;
private final String name;
private final int ordinal;
public CraftFluid(NamespacedKey key, net.minecraft.world.level.material.Fluid fluidType) {
this.key = key;
this.fluidType = fluidType;
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive fluid specific values.
// Custom fluids will return the key with namespace. For a plugin this should look than like a new fluid
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftFluid.count++;
}
@Override
public net.minecraft.world.level.material.Fluid getHandle() {
return this.fluidType;
}
@NotNull
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(@NotNull Fluid fluid) {
return this.ordinal - fluid.ordinal();
}
@NotNull
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftFluid otherFluid)) {
return false;
}
return this.getKey().equals(otherFluid.getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftFluid(final Holder<net.minecraft.world.level.material.Fluid> holder) {
super(holder, count++);
}
}

View File

@@ -7,18 +7,13 @@ public final class CraftFluidCollisionMode {
private CraftFluidCollisionMode() {}
public static Fluid toNMS(FluidCollisionMode fluidCollisionMode) {
public static Fluid toFluid(FluidCollisionMode fluidCollisionMode) {
if (fluidCollisionMode == null) return null;
switch (fluidCollisionMode) {
case ALWAYS:
return Fluid.ANY;
case SOURCE_ONLY:
return Fluid.SOURCE_ONLY;
case NEVER:
return Fluid.NONE;
default:
return null;
}
return switch (fluidCollisionMode) {
case ALWAYS -> Fluid.ANY;
case SOURCE_ONLY -> Fluid.SOURCE_ONLY;
case NEVER -> Fluid.NONE;
};
}
}

View File

@@ -31,7 +31,6 @@ public class CraftGameEvent extends GameEvent implements Handleable<net.minecraf
return this.handle;
}
// Paper start
@Override
public int getRange() {
return this.handle.notificationRadius();
@@ -41,7 +40,6 @@ public class CraftGameEvent extends GameEvent implements Handleable<net.minecraf
public int getVibrationLevel() {
return net.minecraft.world.level.gameevent.vibrations.VibrationSystem.getGameEventFrequency(this.handleKey);
}
// Paper end
@NotNull
@Override

View File

@@ -8,40 +8,25 @@ public final class CraftHeightMap {
}
public static net.minecraft.world.level.levelgen.Heightmap.Types toNMS(HeightMap bukkitHeightMap) {
switch (bukkitHeightMap) {
case MOTION_BLOCKING_NO_LEAVES:
return net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
case OCEAN_FLOOR:
return net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR;
case OCEAN_FLOOR_WG:
return net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR_WG;
case WORLD_SURFACE:
return net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE;
case WORLD_SURFACE_WG:
return net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE_WG;
case MOTION_BLOCKING:
return net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING;
default:
throw new EnumConstantNotPresentException(net.minecraft.world.level.levelgen.Heightmap.Types.class, bukkitHeightMap.name());
}
return switch (bukkitHeightMap) {
case MOTION_BLOCKING_NO_LEAVES ->
net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
case OCEAN_FLOOR -> net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR;
case OCEAN_FLOOR_WG -> net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR_WG;
case WORLD_SURFACE -> net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE;
case WORLD_SURFACE_WG -> net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE_WG;
case MOTION_BLOCKING -> net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING;
};
}
public static HeightMap fromNMS(net.minecraft.world.level.levelgen.Heightmap.Types nmsHeightMapType) {
switch (nmsHeightMapType) {
case WORLD_SURFACE_WG:
return HeightMap.WORLD_SURFACE_WG;
case WORLD_SURFACE:
return HeightMap.WORLD_SURFACE;
case OCEAN_FLOOR_WG:
return HeightMap.OCEAN_FLOOR_WG;
case OCEAN_FLOOR:
return HeightMap.OCEAN_FLOOR;
case MOTION_BLOCKING_NO_LEAVES:
return HeightMap.MOTION_BLOCKING_NO_LEAVES;
case MOTION_BLOCKING:
return HeightMap.MOTION_BLOCKING;
default:
throw new EnumConstantNotPresentException(HeightMap.class, nmsHeightMapType.name());
}
return switch (nmsHeightMapType) {
case WORLD_SURFACE_WG -> HeightMap.WORLD_SURFACE_WG;
case WORLD_SURFACE -> HeightMap.WORLD_SURFACE;
case OCEAN_FLOOR_WG -> HeightMap.OCEAN_FLOOR_WG;
case OCEAN_FLOOR -> HeightMap.OCEAN_FLOOR;
case MOTION_BLOCKING_NO_LEAVES -> HeightMap.MOTION_BLOCKING_NO_LEAVES;
case MOTION_BLOCKING -> HeightMap.MOTION_BLOCKING;
};
}
}

View File

@@ -1,55 +1,54 @@
package org.bukkit.craftbukkit;
import java.util.Objects;
import org.bukkit.Input;
public class CraftInput implements Input {
private final net.minecraft.world.entity.player.Input handle;
private final net.minecraft.world.entity.player.Input input;
public CraftInput(net.minecraft.world.entity.player.Input handle) {
this.handle = handle;
public CraftInput(net.minecraft.world.entity.player.Input input) {
this.input = input;
}
@Override
public boolean isForward() {
return this.handle.forward();
return this.input.forward();
}
@Override
public boolean isBackward() {
return this.handle.backward();
return this.input.backward();
}
@Override
public boolean isLeft() {
return this.handle.left();
return this.input.left();
}
@Override
public boolean isRight() {
return this.handle.right();
return this.input.right();
}
@Override
public boolean isJump() {
return this.handle.jump();
return this.input.jump();
}
@Override
public boolean isSneak() {
return this.handle.shift();
return this.input.shift();
}
@Override
public boolean isSprint() {
return this.handle.sprint();
return this.input.sprint();
}
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + Objects.hashCode(this.handle);
hash = 89 * hash + this.input.hashCode();
return hash;
}
@@ -58,18 +57,16 @@ public class CraftInput implements Input {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
final CraftInput other = (CraftInput) obj;
return Objects.equals(this.handle, other.handle);
return this.input.equals(other.input);
}
@Override
public String toString() {
return "CraftInput{" + this.handle + '}';
return "CraftInput{" + this.input + '}';
}
}

View File

@@ -107,7 +107,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
ServerLevel handle = ((CraftWorld) loc.getWorld()).getHandle();
LootParams.Builder builder = new LootParams.Builder(handle);
this.setMaybe(builder, LootContextParams.ORIGIN, CraftLocation.toVec3D(loc));
this.setMaybe(builder, LootContextParams.ORIGIN, CraftLocation.toVec3(loc));
if (this.getHandle() != LootTable.EMPTY) {
builder.withLuck(context.getLuck());
@@ -128,7 +128,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
}
// SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
// SPIGOT-5603 - Avoid IllegalArgumentException in ContextKeySet.Builder#create
ContextKeySet.Builder nmsBuilder = new ContextKeySet.Builder();
for (ContextKey<?> param : this.getHandle().getParamSet().required()) {
nmsBuilder.required(param);
@@ -151,7 +151,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
public static LootContext convertContext(net.minecraft.world.level.storage.loot.LootContext info) {
Vec3 position = info.getOptionalParameter(LootContextParams.ORIGIN);
if (position == null) {
position = info.getOptionalParameter(LootContextParams.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParameterSets
position = info.getOptionalParameter(LootContextParams.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParamSets
}
Location location = CraftLocation.toBukkit(position, info.getLevel().getWorld());
LootContext.Builder contextBuilder = new LootContext.Builder(location);
@@ -173,7 +173,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
@Override
public String toString() {
return this.getKey().toString();
return this.key.toString();
}
@Override
@@ -183,13 +183,11 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
org.bukkit.loot.LootTable table = (org.bukkit.loot.LootTable) obj;
return table.getKey().equals(this.getKey());
return table.getKey().equals(this.key);
}
// Paper start - satisfy equals/hashCode contract
@Override
public int hashCode() {
return java.util.Objects.hash(key);
return this.key.hashCode();
}
// Paper end
}

View File

@@ -41,7 +41,6 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, RegistryKey.INSTRUMENT); // Paper - switch to Holder
}
// Paper start - switch to Holder
@Override
public boolean equals(final Object o) {
return this.implEquals(o);
@@ -58,9 +57,9 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
}
private final Holder<Instrument> holder;
public CraftMusicInstrument(Holder<Instrument> holder) {
this.holder = holder;
// Paper end - switch to Holder
}
@Override
@@ -74,7 +73,6 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
return Holderable.super.getKey();
}
// Paper start - add translationKey methods
@Override
public @NotNull String translationKey() {
if (!(this.getHandle().description().getContents() instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents)) {
@@ -82,7 +80,4 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
}
return translatableContents.getKey();
}
// Paper end - add translationKey methods
// Paper - switch to Holder
}

View File

@@ -11,11 +11,13 @@ import java.util.Map;
import java.util.UUID;
import net.minecraft.core.GlobalPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.UserWhiteListEntry;
import net.minecraft.stats.ServerStatsCounter;
import net.minecraft.world.level.storage.PlayerDataStorage;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
@@ -24,20 +26,18 @@ import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.ban.ProfileBanList;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper;
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.profile.PlayerProfile;
@SerializableAs("Player")
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
private static final org.slf4j.Logger LOGGER = com.mojang.logging.LogUtils.getLogger(); // Paper
private final GameProfile profile;
private final CraftServer server;
private final PlayerDataStorage storage;
@@ -46,7 +46,6 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
this.server = server;
this.profile = profile;
this.storage = server.console.playerDataStorage;
}
@Override
@@ -54,12 +53,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return this.getPlayer() != null;
}
// Paper start
@Override
public boolean isConnected() {
return false;
}
// Paper end
@Override
public String getName() {
@@ -76,9 +73,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
CompoundTag data = this.getBukkitData();
if (data != null) {
if (data.contains("lastKnownName")) {
return data.getString("lastKnownName");
}
return data.getString("lastKnownName").orElse(null);
}
return null;
@@ -192,17 +187,14 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return false;
}
if ((this.getUniqueId() == null) || (other.getUniqueId() == null)) {
return false;
}
return this.getUniqueId().equals(other.getUniqueId());
}
@Override
public int hashCode() {
int hash = 5;
hash = 97 * hash + (this.getUniqueId() != null ? this.getUniqueId().hashCode() : 0);
hash = 97 * hash + this.getUniqueId().hashCode();
return hash;
}
@@ -214,10 +206,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
CompoundTag result = this.getData();
if (result != null) {
if (!result.contains("bukkit")) {
result.put("bukkit", new CompoundTag());
}
result = result.getCompound("bukkit");
result = result.getCompound("bukkit").orElse(null);
}
return result;
@@ -235,12 +224,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
CompoundTag data = this.getBukkitData();
if (data != null) {
if (data.contains("firstPlayed")) {
return data.getLong("firstPlayed");
} else {
return data.getLong("firstPlayed").orElseGet(() -> {
File file = this.getDataFile();
return file.lastModified();
}
});
} else {
return 0;
}
@@ -254,12 +241,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
CompoundTag data = this.getBukkitData();
if (data != null) {
if (data.contains("lastPlayed")) {
return data.getLong("lastPlayed");
} else {
return data.getLong("lastPlayed").orElseGet(() -> {
File file = this.getDataFile();
return file.lastModified();
}
});
} else {
return 0;
}
@@ -270,22 +255,19 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return this.getData() != null;
}
// Paper start
@Override
public long getLastLogin() {
Player player = getPlayer();
Player player = this.getPlayer();
if (player != null) return player.getLastLogin();
CompoundTag data = getPaperData();
CompoundTag data = this.getPaperData();
if (data != null) {
if (data.contains("LastLogin")) {
return data.getLong("LastLogin");
} else {
return data.getLong("LastLogin").orElseGet(() -> {
// if the player file cannot provide accurate data, this is probably the closest we can approximate
File file = getDataFile();
return file.lastModified();
}
});
} else {
return 0;
}
@@ -293,39 +275,32 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public long getLastSeen() {
Player player = getPlayer();
Player player = this.getPlayer();
if (player != null) return player.getLastSeen();
CompoundTag data = getPaperData();
CompoundTag data = this.getPaperData();
if (data != null) {
if (data.contains("LastSeen")) {
return data.getLong("LastSeen");
} else {
return data.getLong("LastSeen").orElseGet(() -> {
// if the player file cannot provide accurate data, this is probably the closest we can approximate
File file = getDataFile();
return file.lastModified();
}
});
} else {
return 0;
}
}
private CompoundTag getPaperData() {
CompoundTag result = getData();
CompoundTag result = this.getData();
if (result != null) {
if (!result.contains("Paper")) {
result.put("Paper", new CompoundTag());
}
result = result.getCompound("Paper");
result = result.getCompound("Paper").orElse(null);
}
return result;
}
// Paper end
// Paper start - Add Offline PDC API
private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
private io.papermc.paper.persistence.@org.checkerframework.checker.nullness.qual.MonotonicNonNull PersistentDataContainerView persistentDataContainerView;
@@ -335,7 +310,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
this.persistentDataContainerView = new io.papermc.paper.persistence.PaperPersistentDataContainerView(DATA_TYPE_REGISTRY) {
private CompoundTag getPersistentTag() {
return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues"));
return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues").orElse(null));
}
@Override
@@ -351,14 +326,15 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
}
return this.persistentDataContainerView;
}
// Paper end - Add Offline PDC API
@Override
public Location getLastDeathLocation() {
if (this.getData().contains("LastDeathLocation", 10)) {
return GlobalPos.CODEC.parse(NbtOps.INSTANCE, this.getData().get("LastDeathLocation")).result().map(CraftMemoryMapper::fromNms).orElse(null);
CompoundTag data = this.getData();
if (data == null) {
return null;
}
return null;
return data.read("LastDeathLocation", GlobalPos.CODEC).map(CraftLocation::fromGlobalPos).orElse(null);
}
@Override
@@ -368,69 +344,38 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return null;
}
if (data.contains("Pos") && data.contains("Rotation")) {
ListTag position = (ListTag) data.get("Pos");
ListTag rotation = (ListTag) data.get("Rotation");
Vec3 pos = data.read("Pos", Vec3.CODEC).orElse(null);
Vec2 rot = data.read("Rotation", Vec2.CODEC).orElse(null);
if (pos != null && rot != null) {
Long msb = data.getLong("WorldUUIDMost").orElse(null);
Long lsb = data.getLong("WorldUUIDLeast").orElse(null);
World world = msb != null && lsb != null ? this.server.getWorld(new UUID(msb, lsb)) : null;
UUID uuid = new UUID(data.getLong("WorldUUIDMost"), data.getLong("WorldUUIDLeast"));
return new Location(this.server.getWorld(uuid),
position.getDouble(0),
position.getDouble(1),
position.getDouble(2),
rotation.getFloat(0),
rotation.getFloat(1)
return new Location(
world,
pos.x(), pos.y(), pos.z(),
rot.x, rot.y
);
}
return null;
}
@Override
public Location getBedSpawnLocation() {
return this.getRespawnLocation();
}
@Override
public Location getRespawnLocation() {
CompoundTag data = this.getData();
if (data == null) return null;
if (data.contains("SpawnX") && data.contains("SpawnY") && data.contains("SpawnZ")) {
// Paper start - fix wrong world
final float respawnAngle = data.getFloat("SpawnAngle");
org.bukkit.World spawnWorld = this.server.getWorld(data.getString("SpawnWorld")); // legacy
if (data.contains("SpawnDimension")) {
com.mojang.serialization.DataResult<net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level>> result = net.minecraft.world.level.Level.RESOURCE_KEY_CODEC.parse(net.minecraft.nbt.NbtOps.INSTANCE, data.get("SpawnDimension"));
net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> levelKey = result.resultOrPartial(LOGGER::error).orElse(net.minecraft.world.level.Level.OVERWORLD);
net.minecraft.server.level.ServerLevel level = this.server.console.getLevel(levelKey);
spawnWorld = level != null ? level.getWorld() : spawnWorld;
final ServerPlayer.RespawnConfig respawnConfig = data.read("respawn", ServerPlayer.RespawnConfig.CODEC).orElse(null);
if (respawnConfig != null) {
final ServerLevel level = this.server.console.getLevel(respawnConfig.dimension());
if (level != null) {
return CraftLocation.toBukkit(respawnConfig.pos(), level.getWorld(), respawnConfig.angle(), 0);
}
if (spawnWorld == null) {
return null;
}
return new Location(spawnWorld, data.getInt("SpawnX"), data.getInt("SpawnY"), data.getInt("SpawnZ"), respawnAngle, 0);
// Paper end
}
return null;
}
public void setMetadata(String metadataKey, MetadataValue metadataValue) {
this.server.getPlayerMetadata().setMetadata(this, metadataKey, metadataValue);
}
public List<MetadataValue> getMetadata(String metadataKey) {
return this.server.getPlayerMetadata().getMetadata(this, metadataKey);
}
public boolean hasMetadata(String metadataKey) {
return this.server.getPlayerMetadata().hasMetadata(this, metadataKey);
}
public void removeMetadata(String metadataKey, Plugin plugin) {
this.server.getPlayerMetadata().removeMetadata(this, metadataKey, plugin);
}
private ServerStatsCounter getStatisticManager() {
return this.server.getHandle().getPlayerStats(this.getUniqueId(), this.getName());
}

View File

@@ -192,7 +192,7 @@ public abstract class CraftParticle<D> implements Keyed {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> trailFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.Trail.class) {
@Override
public ParticleOptions createParticleParam(Particle.Trail data) {
return new TrailParticleOption(CraftLocation.toVec3D(data.getTarget()), data.getColor().asRGB(), data.getDuration());
return new TrailParticleOption(CraftLocation.toVec3(data.getTarget()), data.getColor().asRGB(), data.getDuration());
}
};
@@ -206,6 +206,7 @@ public abstract class CraftParticle<D> implements Keyed {
add("shriek", integerFunction);
add("block_marker", blockDataFunction);
add("entity_effect", colorFunction);
add("tinted_leaves", colorFunction);
add("dust_pillar", blockDataFunction);
add("block_crumble", blockDataFunction);
add("trail", trailFunction);

View File

@@ -11,16 +11,17 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.Raid;
import org.bukkit.Raid.RaidStatus;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Raider;
public final class CraftRaid implements Raid {
private final net.minecraft.world.entity.raid.Raid handle;
private final Level level;
public CraftRaid(net.minecraft.world.entity.raid.Raid handle) {
public CraftRaid(net.minecraft.world.entity.raid.Raid handle, Level level) {
this.handle = handle;
this.level = level;
}
@Override
@@ -48,8 +49,7 @@ public final class CraftRaid implements Raid {
@Override
public Location getLocation() {
BlockPos pos = this.handle.getCenter();
Level world = this.handle.getLevel();
return CraftLocation.toBukkit(pos, world.getWorld());
return CraftLocation.toBukkit(pos, this.level.getWorld());
}
@Override
@@ -104,10 +104,9 @@ public final class CraftRaid implements Raid {
return this.handle;
}
// Paper start - more Raid API
@Override
public int getId() {
return this.handle.getId();
return this.handle.idOrNegativeOne;
}
@Override
@@ -132,5 +131,4 @@ public final class CraftRaid implements Raid {
public int hashCode() {
return this.handle.hashCode();
}
// Paper end - more Raid API
}

View File

@@ -12,12 +12,13 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.features.TreeFeatures;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChorusFlowerBlock;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
@@ -35,19 +36,19 @@ import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftEntityTypes;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.BlockStateListPopulator;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.AbstractCow;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LargeFireball;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.SizedFireball;
@@ -56,7 +57,6 @@ import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.TippedArrow;
import org.bukkit.entity.minecart.RideableMinecart;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionType;
public abstract class CraftRegionAccessor implements RegionAccessor {
@@ -77,12 +77,10 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
return CraftBiome.minecraftHolderToBukkit(this.getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
}
// Paper start
@Override
public Biome getComputedBiome(int x, int y, int z) {
return CraftBiome.minecraftHolderToBukkit(this.getHandle().getBiome(new BlockPos(x, y, z)));
}
// Paper end
@Override
public void setBiome(Location location, Biome biome) {
@@ -108,12 +106,10 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
return CraftBlock.at(this.getHandle(), new BlockPos(x, y, z)).getState();
}
// Paper start - FluidState API
@Override
public io.papermc.paper.block.fluid.FluidData getFluidData(final int x, final int y, final int z) {
return io.papermc.paper.block.fluid.PaperFluidData.createData(getHandle().getFluidState(new BlockPos(x, y, z)));
}
// Paper end
@Override
public BlockData getBlockData(Location location) {
@@ -150,7 +146,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
BlockPos pos = new BlockPos(x, y, z);
net.minecraft.world.level.block.state.BlockState old = this.getHandle().getBlockState(pos);
CraftBlock.setTypeAndData(world, pos, old, ((CraftBlockData) blockData).getState(), true);
CraftBlock.setBlockState(world, pos, old, ((CraftBlockData) blockData).getState(), true);
}
@Override
@@ -203,13 +199,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
BlockStateListPopulator populator = new BlockStateListPopulator(this.getHandle());
boolean result = this.generateTree(populator, this.getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, new RandomSourceWrapper(random), treeType);
populator.refreshTiles();
for (BlockState blockState : populator.getList()) {
if (predicate == null || predicate.test(blockState)) {
blockState.update(true, true);
}
}
populator.placeSomeBlocks(predicate == null ? ($ -> true) : predicate);
return result;
}
@@ -265,7 +255,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
gen = TreeFeatures.SUPER_BIRCH_BEES_0002;
break;
case CHORUS_PLANT:
((ChorusFlowerBlock) Blocks.CHORUS_FLOWER).generatePlant(access, pos, random, 8);
ChorusFlowerBlock.generatePlant(access, pos, random, 8);
return true;
case CRIMSON_FUNGUS:
gen = this.isNormalWorld() ? TreeFeatures.CRIMSON_FUNGUS_PLANTED : TreeFeatures.CRIMSON_FUNGUS; // Paper - Fix async entity add due to fungus trees; if world gen, don't use planted version
@@ -298,7 +288,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
}
Holder<ConfiguredFeature<?, ?>> holder = access.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(gen).orElse(null);
return (holder != null) ? holder.value().place(access, chunkGenerator, random, pos) : false;
return holder != null && holder.value().place(access, chunkGenerator, random, pos);
}
@Override
@@ -313,7 +303,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
public List<Entity> getEntities() {
List<Entity> list = new ArrayList<Entity>();
List<Entity> list = new ArrayList<>();
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
@@ -329,13 +319,13 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
public List<LivingEntity> getLivingEntities() {
List<LivingEntity> list = new ArrayList<LivingEntity>();
List<LivingEntity> list = new ArrayList<>();
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
// Assuming that bukkitEntity isn't null
if (bukkitEntity != null && bukkitEntity instanceof LivingEntity && (!this.isNormalWorld() || bukkitEntity.isValid())) {
if (bukkitEntity instanceof LivingEntity && (!this.isNormalWorld() || bukkitEntity.isValid())) {
list.add((LivingEntity) bukkitEntity);
}
});
@@ -367,7 +357,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
public Collection<Entity> getEntitiesByClasses(Class<?>... classes) {
Collection<Entity> list = new ArrayList<Entity>();
Collection<Entity> list = new ArrayList<>();
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
@@ -472,11 +462,6 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
public abstract void addEntityWithPassengers(net.minecraft.world.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason);
@SuppressWarnings("unchecked")
public net.minecraft.world.entity.Entity makeEntity(Location location, Class<? extends Entity> clazz) throws IllegalArgumentException {
return this.createEntity(location, clazz, true);
}
@SuppressWarnings("unchecked")
public net.minecraft.world.entity.Entity createEntity(Location location, Class<? extends Entity> clazz, boolean randomizeData) throws IllegalArgumentException {
Preconditions.checkArgument(location != null, "Location cannot be null");
@@ -488,17 +473,16 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
clazz = Arrow.class;
} else if (clazz == AbstractHorse.class) {
clazz = Horse.class;
} else if (clazz == AbstractCow.class) {
clazz = Cow.class;
} else if (clazz == Fireball.class) {
clazz = LargeFireball.class;
} else if (clazz == LingeringPotion.class) {
clazz = ThrownPotion.class;
runOld = other -> ((net.minecraft.world.entity.projectile.ThrownPotion) other).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else if (clazz == ThrownPotion.class) {
clazz = SplashPotion.class;
} else if (clazz == Minecart.class) {
clazz = RideableMinecart.class;
} else if (clazz == SizedFireball.class) {
clazz = LargeFireball.class;
} else if (clazz == SplashPotion.class) {
clazz = ThrownPotion.class;
} else if (clazz == TippedArrow.class) {
clazz = Arrow.class;
runOld = other -> ((Arrow) other.getBukkitEntity()).setBasePotionType(PotionType.WATER);
@@ -530,10 +514,9 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
}
// Paper start
@Override
public io.papermc.paper.world.MoonPhase getMoonPhase() {
return io.papermc.paper.world.MoonPhase.getPhase(this.getHandle().dayTime() / 24000L);
return io.papermc.paper.world.MoonPhase.getPhase(this.getHandle().dayTime() / Level.TICKS_PER_DAY);
}
@Override
@@ -550,7 +533,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
net.minecraft.world.phys.Vec3 start = new net.minecraft.world.phys.Vec3(from.getX(), from.getY(), from.getZ());
net.minecraft.world.phys.Vec3 end = new net.minecraft.world.phys.Vec3(to.getX(), to.getY(), to.getZ());
if (end.distanceToSqr(start) > 128D * 128D) {
if (end.distanceToSqr(start) > Mth.square(128D)) {
return false; // Return early if the distance is greater than 128 blocks
}
@@ -563,12 +546,9 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
return !this.getHandle().noCollision(aabb);
}
// Paper end
// Paper start - feature flag API
@Override
public java.util.Set<org.bukkit.FeatureFlag> getFeatureFlags() {
return io.papermc.paper.world.flag.PaperFeatureFlagProviderImpl.fromNms(this.getHandle().enabledFeatures());
}
// Paper end - feature flag API
}

View File

@@ -124,7 +124,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
}
// Paper start - fixup upstream being dum
public static <T extends Keyed, M> Optional<T> unwrapAndConvertHolder(final RegistryKey<T> registryKey, final Holder<M> value) {
public static <T extends Keyed, M> Optional<T> unwrapAndConvertHolder(final RegistryKey<T> registryKey, final Holder<M> value) { // todo recheck usage with holderable support
final Registry<T> registry = RegistryAccess.registryAccess().getRegistry(registryKey);
if (registry instanceof final CraftRegistry<?,?> craftRegistry && craftRegistry.supportsDirectHolders() && value.kind() == Holder.Kind.DIRECT) {
return Optional.of(((CraftRegistry<T, M>) registry).createBukkit(value));
@@ -255,7 +255,6 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
return this.minecraftToBukkit.supportsDirectHolders();
}
// Paper start - improve Registry
@Override
public NamespacedKey getKey(final B value) {
if (value instanceof Holderable<?> holderable) {
@@ -263,7 +262,6 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
}
return value.getKey();
}
// Paper end - improve Registry
// Paper start - RegistrySet API
@Override

View File

@@ -61,7 +61,6 @@ public class CraftServerLinks implements ServerLinks {
return link;
}
// Paper start - Adventure
@Override
public ServerLink addLink(net.kyori.adventure.text.Component displayName, URI url) {
Preconditions.checkArgument(displayName != null, "displayName cannot be null");
@@ -72,7 +71,6 @@ public class CraftServerLinks implements ServerLinks {
return link;
}
// Paper end - Adventure
@Override
public ServerLink addLink(String displayName, URI url) {
@@ -147,12 +145,10 @@ public class CraftServerLinks implements ServerLinks {
return CraftChatMessage.fromComponent(this.handle.displayName());
}
// Paper start - Adventure
@Override
public net.kyori.adventure.text.Component displayName() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.displayName());
}
// Paper end - Adventure
@Override
public URI getUrl() {

View File

@@ -25,10 +25,4 @@ public class CraftSound extends OldEnumHolderable<Sound, SoundEvent> implements
public CraftSound(Holder<SoundEvent> soundEffect) {
super(soundEffect, count++);
}
// Paper start
public static String getSound(Sound sound) {
return sound.getKey().getKey();
}
// Paper end
}

View File

@@ -34,7 +34,7 @@ public class CraftSoundGroup implements SoundGroup {
@Override
public Sound getBreakSound() {
return CraftSound.minecraftToBukkit(this.getHandle().breakSound);
return CraftSound.minecraftToBukkit(this.getHandle().getBreakSound());
}
@Override
@@ -49,7 +49,7 @@ public class CraftSoundGroup implements SoundGroup {
@Override
public Sound getHitSound() {
return CraftSound.minecraftToBukkit(this.getHandle().hitSound);
return CraftSound.minecraftToBukkit(this.getHandle().getHitSound());
}
@Override

View File

@@ -20,89 +20,95 @@ import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.entity.EntityType;
public enum CraftStatistic {
DAMAGE_DEALT(Stats.DAMAGE_DEALT),
DAMAGE_TAKEN(Stats.DAMAGE_TAKEN),
DEATHS(Stats.DEATHS),
MOB_KILLS(Stats.MOB_KILLS),
PLAYER_KILLS(Stats.PLAYER_KILLS),
FISH_CAUGHT(Stats.FISH_CAUGHT),
// Start generate - CraftStatisticCustom
// @GeneratedFrom 1.21.5
ANIMALS_BRED(Stats.ANIMALS_BRED),
LEAVE_GAME(Stats.LEAVE_GAME),
JUMP(Stats.JUMP),
DROP_COUNT(Stats.DROP),
DROP(ResourceLocation.withDefaultNamespace("dropped")),
PICKUP(ResourceLocation.withDefaultNamespace("picked_up")),
PLAY_ONE_MINUTE(Stats.PLAY_TIME),
TOTAL_WORLD_TIME(Stats.TOTAL_WORLD_TIME),
WALK_ONE_CM(Stats.WALK_ONE_CM),
WALK_ON_WATER_ONE_CM(Stats.WALK_ON_WATER_ONE_CM),
FALL_ONE_CM(Stats.FALL_ONE_CM),
SNEAK_TIME(Stats.CROUCH_TIME),
CLIMB_ONE_CM(Stats.CLIMB_ONE_CM),
FLY_ONE_CM(Stats.FLY_ONE_CM),
WALK_UNDER_WATER_ONE_CM(Stats.WALK_UNDER_WATER_ONE_CM),
MINECART_ONE_CM(Stats.MINECART_ONE_CM),
BOAT_ONE_CM(Stats.BOAT_ONE_CM),
PIG_ONE_CM(Stats.PIG_ONE_CM),
HORSE_ONE_CM(Stats.HORSE_ONE_CM),
SPRINT_ONE_CM(Stats.SPRINT_ONE_CM),
CROUCH_ONE_CM(Stats.CROUCH_ONE_CM),
AVIATE_ONE_CM(Stats.AVIATE_ONE_CM),
MINE_BLOCK(ResourceLocation.withDefaultNamespace("mined")),
USE_ITEM(ResourceLocation.withDefaultNamespace("used")),
BREAK_ITEM(ResourceLocation.withDefaultNamespace("broken")),
CRAFT_ITEM(ResourceLocation.withDefaultNamespace("crafted")),
KILL_ENTITY(ResourceLocation.withDefaultNamespace("killed")),
ENTITY_KILLED_BY(ResourceLocation.withDefaultNamespace("killed_by")),
TIME_SINCE_DEATH(Stats.TIME_SINCE_DEATH),
TALKED_TO_VILLAGER(Stats.TALKED_TO_VILLAGER),
TRADED_WITH_VILLAGER(Stats.TRADED_WITH_VILLAGER),
CAKE_SLICES_EATEN(Stats.EAT_CAKE_SLICE),
CAULDRON_FILLED(Stats.FILL_CAULDRON),
CAULDRON_USED(Stats.USE_CAULDRON),
BELL_RING(Stats.BELL_RING),
BOAT_ONE_CM(Stats.BOAT_ONE_CM),
ARMOR_CLEANED(Stats.CLEAN_ARMOR),
BANNER_CLEANED(Stats.CLEAN_BANNER),
BREWINGSTAND_INTERACTION(Stats.INTERACT_WITH_BREWINGSTAND),
BEACON_INTERACTION(Stats.INTERACT_WITH_BEACON),
DROPPER_INSPECTED(Stats.INSPECT_DROPPER),
HOPPER_INSPECTED(Stats.INSPECT_HOPPER),
DISPENSER_INSPECTED(Stats.INSPECT_DISPENSER),
NOTEBLOCK_PLAYED(Stats.PLAY_NOTEBLOCK),
NOTEBLOCK_TUNED(Stats.TUNE_NOTEBLOCK),
FLOWER_POTTED(Stats.POT_FLOWER),
TRAPPED_CHEST_TRIGGERED(Stats.TRIGGER_TRAPPED_CHEST),
ENDERCHEST_OPENED(Stats.OPEN_ENDERCHEST),
ITEM_ENCHANTED(Stats.ENCHANT_ITEM),
RECORD_PLAYED(Stats.PLAY_RECORD),
FURNACE_INTERACTION(Stats.INTERACT_WITH_FURNACE),
CRAFTING_TABLE_INTERACTION(Stats.INTERACT_WITH_CRAFTING_TABLE),
CHEST_OPENED(Stats.OPEN_CHEST),
SLEEP_IN_BED(Stats.SLEEP_IN_BED),
SHULKER_BOX_OPENED(Stats.OPEN_SHULKER_BOX),
TIME_SINCE_REST(Stats.TIME_SINCE_REST),
SWIM_ONE_CM(Stats.SWIM_ONE_CM),
CLEAN_SHULKER_BOX(Stats.CLEAN_SHULKER_BOX),
CLIMB_ONE_CM(Stats.CLIMB_ONE_CM),
CROUCH_ONE_CM(Stats.CROUCH_ONE_CM),
DAMAGE_ABSORBED(Stats.DAMAGE_ABSORBED),
DAMAGE_BLOCKED_BY_SHIELD(Stats.DAMAGE_BLOCKED_BY_SHIELD),
DAMAGE_DEALT(Stats.DAMAGE_DEALT),
DAMAGE_DEALT_ABSORBED(Stats.DAMAGE_DEALT_ABSORBED),
DAMAGE_DEALT_RESISTED(Stats.DAMAGE_DEALT_RESISTED),
DAMAGE_BLOCKED_BY_SHIELD(Stats.DAMAGE_BLOCKED_BY_SHIELD),
DAMAGE_ABSORBED(Stats.DAMAGE_ABSORBED),
DAMAGE_RESISTED(Stats.DAMAGE_RESISTED),
CLEAN_SHULKER_BOX(Stats.CLEAN_SHULKER_BOX),
OPEN_BARREL(Stats.OPEN_BARREL),
DAMAGE_TAKEN(Stats.DAMAGE_TAKEN),
DEATHS(Stats.DEATHS),
DROP_COUNT(Stats.DROP),
CAKE_SLICES_EATEN(Stats.EAT_CAKE_SLICE),
ITEM_ENCHANTED(Stats.ENCHANT_ITEM),
FALL_ONE_CM(Stats.FALL_ONE_CM),
CAULDRON_FILLED(Stats.FILL_CAULDRON),
FISH_CAUGHT(Stats.FISH_CAUGHT),
FLY_ONE_CM(Stats.FLY_ONE_CM),
HORSE_ONE_CM(Stats.HORSE_ONE_CM),
DISPENSER_INSPECTED(Stats.INSPECT_DISPENSER),
DROPPER_INSPECTED(Stats.INSPECT_DROPPER),
HOPPER_INSPECTED(Stats.INSPECT_HOPPER),
INTERACT_WITH_ANVIL(Stats.INTERACT_WITH_ANVIL),
BEACON_INTERACTION(Stats.INTERACT_WITH_BEACON),
INTERACT_WITH_BLAST_FURNACE(Stats.INTERACT_WITH_BLAST_FURNACE),
INTERACT_WITH_SMOKER(Stats.INTERACT_WITH_SMOKER),
INTERACT_WITH_LECTERN(Stats.INTERACT_WITH_LECTERN),
BREWINGSTAND_INTERACTION(Stats.INTERACT_WITH_BREWINGSTAND),
INTERACT_WITH_CAMPFIRE(Stats.INTERACT_WITH_CAMPFIRE),
INTERACT_WITH_CARTOGRAPHY_TABLE(Stats.INTERACT_WITH_CARTOGRAPHY_TABLE),
CRAFTING_TABLE_INTERACTION(Stats.INTERACT_WITH_CRAFTING_TABLE),
FURNACE_INTERACTION(Stats.INTERACT_WITH_FURNACE),
INTERACT_WITH_GRINDSTONE(Stats.INTERACT_WITH_GRINDSTONE),
INTERACT_WITH_LECTERN(Stats.INTERACT_WITH_LECTERN),
INTERACT_WITH_LOOM(Stats.INTERACT_WITH_LOOM),
INTERACT_WITH_SMITHING_TABLE(Stats.INTERACT_WITH_SMITHING_TABLE),
INTERACT_WITH_SMOKER(Stats.INTERACT_WITH_SMOKER),
INTERACT_WITH_STONECUTTER(Stats.INTERACT_WITH_STONECUTTER),
BELL_RING(Stats.BELL_RING),
JUMP(Stats.JUMP),
LEAVE_GAME(Stats.LEAVE_GAME),
MINECART_ONE_CM(Stats.MINECART_ONE_CM),
MOB_KILLS(Stats.MOB_KILLS),
OPEN_BARREL(Stats.OPEN_BARREL),
CHEST_OPENED(Stats.OPEN_CHEST),
ENDERCHEST_OPENED(Stats.OPEN_ENDERCHEST),
SHULKER_BOX_OPENED(Stats.OPEN_SHULKER_BOX),
PIG_ONE_CM(Stats.PIG_ONE_CM),
NOTEBLOCK_PLAYED(Stats.PLAY_NOTEBLOCK),
RECORD_PLAYED(Stats.PLAY_RECORD),
PLAY_ONE_MINUTE(Stats.PLAY_TIME),
PLAYER_KILLS(Stats.PLAYER_KILLS),
FLOWER_POTTED(Stats.POT_FLOWER),
RAID_TRIGGER(Stats.RAID_TRIGGER),
RAID_WIN(Stats.RAID_WIN),
INTERACT_WITH_ANVIL(Stats.INTERACT_WITH_ANVIL),
INTERACT_WITH_GRINDSTONE(Stats.INTERACT_WITH_GRINDSTONE),
SLEEP_IN_BED(Stats.SLEEP_IN_BED),
SNEAK_TIME(Stats.CROUCH_TIME),
SPRINT_ONE_CM(Stats.SPRINT_ONE_CM),
STRIDER_ONE_CM(Stats.STRIDER_ONE_CM),
SWIM_ONE_CM(Stats.SWIM_ONE_CM),
TALKED_TO_VILLAGER(Stats.TALKED_TO_VILLAGER),
TARGET_HIT(Stats.TARGET_HIT),
INTERACT_WITH_SMITHING_TABLE(Stats.INTERACT_WITH_SMITHING_TABLE),
STRIDER_ONE_CM(Stats.STRIDER_ONE_CM);
TIME_SINCE_DEATH(Stats.TIME_SINCE_DEATH),
TIME_SINCE_REST(Stats.TIME_SINCE_REST),
TOTAL_WORLD_TIME(Stats.TOTAL_WORLD_TIME),
TRADED_WITH_VILLAGER(Stats.TRADED_WITH_VILLAGER),
TRAPPED_CHEST_TRIGGERED(Stats.TRIGGER_TRAPPED_CHEST),
NOTEBLOCK_TUNED(Stats.TUNE_NOTEBLOCK),
CAULDRON_USED(Stats.USE_CAULDRON),
WALK_ON_WATER_ONE_CM(Stats.WALK_ON_WATER_ONE_CM),
WALK_ONE_CM(Stats.WALK_ONE_CM),
WALK_UNDER_WATER_ONE_CM(Stats.WALK_UNDER_WATER_ONE_CM),
// End generate - CraftStatisticCustom
// Start generate - CraftStatisticType
// @GeneratedFrom 1.21.5
BREAK_ITEM(ResourceLocation.withDefaultNamespace("broken")),
CRAFT_ITEM(ResourceLocation.withDefaultNamespace("crafted")),
DROP(ResourceLocation.withDefaultNamespace("dropped")),
KILL_ENTITY(ResourceLocation.withDefaultNamespace("killed")),
ENTITY_KILLED_BY(ResourceLocation.withDefaultNamespace("killed_by")),
MINE_BLOCK(ResourceLocation.withDefaultNamespace("mined")),
PICKUP(ResourceLocation.withDefaultNamespace("picked_up")),
USE_ITEM(ResourceLocation.withDefaultNamespace("used"));
// End generate - CraftStatisticType
private final ResourceLocation minecraftKey;
private final org.bukkit.Statistic bukkit;
private static final BiMap<ResourceLocation, org.bukkit.Statistic> statistics;

View File

@@ -47,7 +47,6 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.util.Unit;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LightningBolt;
@@ -58,9 +57,11 @@ import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Climate;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.storage.LevelResource;
@@ -213,7 +214,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public int getTileEntityCount() {
// We don't use the full world tile entity list, so we must iterate chunks
// We don't use the full world block entity list, so we must iterate chunks
int size = 0;
for (ChunkHolder playerchunk : ca.spottedleaf.moonrise.common.PlatformHooks.get().getVisibleChunkHolders(this.world)) {
net.minecraft.world.level.chunk.LevelChunk chunk = playerchunk.getTickingChunk();
@@ -448,7 +449,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
public boolean unloadChunkRequest(int x, int z) {
org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
if (this.isChunkLoaded(x, z)) {
this.world.getChunkSource().removeRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 1, Unit.INSTANCE);
this.world.getChunkSource().removeTicketWithRadius(TicketType.PLUGIN, new ChunkPos(x, z), 1);
}
return true;
@@ -532,8 +533,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
chunk = this.world.getChunkSource().getChunk(x, z, ChunkStatus.FULL, true);
}
if (chunk instanceof net.minecraft.world.level.chunk.LevelChunk) {
this.world.getChunkSource().addRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 1, Unit.INSTANCE);
if (chunk instanceof LevelChunk) {
this.world.getChunkSource().addTicketWithRadius(TicketType.PLUGIN, new ChunkPos(x, z), 1);
return true;
}
@@ -561,7 +562,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkArgument(plugin.isEnabled(), "plugin is not enabled");
final DistanceManager distanceManager = this.world.getChunkSource().chunkMap.distanceManager;
if (distanceManager.addPluginRegionTicket(new ChunkPos(x, z), plugin)) {
if (distanceManager.ticketStorage.addPluginRegionTicket(new ChunkPos(x, z), plugin)) {
this.getChunkAt(x, z); // ensure it's loaded
return true;
}
@@ -574,7 +575,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkNotNull(plugin, "null plugin");
final DistanceManager distanceManager = this.world.getChunkSource().chunkMap.distanceManager;
return distanceManager.removePluginRegionTicket(new ChunkPos(x, z), plugin);
return distanceManager.ticketStorage.removePluginRegionTicket(new ChunkPos(x, z), plugin);
}
@Override
@@ -582,7 +583,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkNotNull(plugin, "null plugin");
DistanceManager chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager;
chunkDistanceManager.removeAllTicketsFor(TicketType.PLUGIN_TICKET, 31, plugin); // keep in-line with force loading, remove at level 31
chunkDistanceManager.ticketStorage.removeAllPluginRegionTickets(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL, plugin);
}
@Override
@@ -616,7 +617,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public boolean isChunkForceLoaded(int x, int z) {
return this.getHandle().getForcedChunks().contains(ChunkPos.asLong(x, z));
return this.getHandle().getForceLoadedChunks().contains(ChunkPos.asLong(x, z));
}
@Override
@@ -629,7 +630,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
public Collection<Chunk> getForceLoadedChunks() {
Set<Chunk> chunks = new HashSet<>();
for (long coord : this.getHandle().getForcedChunks()) {
for (long coord : this.getHandle().getForceLoadedChunks()) {
chunks.add(this.getChunkAt(ChunkPos.getX(coord), ChunkPos.getZ(coord)));
}
@@ -700,7 +701,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
arrow = EntityType.ARROW.create(this.world, EntitySpawnReason.COMMAND);
}
arrow.moveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
arrow.snapTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
arrow.shoot(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread);
this.world.addFreshEntity(arrow);
return (T) arrow.getBukkitEntity();
@@ -720,7 +721,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkArgument(loc != null, "Location cannot be null");
LightningBolt lightning = EntityType.LIGHTNING_BOLT.create(this.world, EntitySpawnReason.COMMAND);
lightning.moveTo(loc.getX(), loc.getY(), loc.getZ());
lightning.snapTo(loc.getX(), loc.getY(), loc.getZ());
lightning.isEffect = isVisual; // Paper - Properly handle lightning effects api
this.world.strikeLightning(lightning, LightningStrikeEvent.Cause.CUSTOM);
return (LightningStrike) lightning.getBukkitEntity();
@@ -729,8 +730,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
// Paper start - Add methods to find targets for lightning strikes
@Override
public Location findLightningRod(Location location) {
return this.world.findLightningRod(io.papermc.paper.util.MCUtil.toBlockPosition(location))
.map(blockPos -> io.papermc.paper.util.MCUtil.toLocation(this.world, blockPos)
return this.world.findLightningRod(CraftLocation.toBlockPosition(location))
.map(blockPos -> CraftLocation.toBukkit(blockPos, this.world)
// get the actual rod pos
.subtract(0, 1, 0))
.orElse(null);
@@ -738,8 +739,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public Location findLightningTarget(Location location) {
final BlockPos pos = this.world.findLightningTargetAround(io.papermc.paper.util.MCUtil.toBlockPosition(location), true);
return pos == null ? null : io.papermc.paper.util.MCUtil.toLocation(this.world, pos);
final BlockPos pos = this.world.findLightningTargetAround(CraftLocation.toBlockPosition(location), true);
return pos == null ? null : CraftLocation.toBukkit(pos, this.world);
}
// Paper end - Add methods to find targets for lightning strikes
@@ -759,10 +760,10 @@ public class CraftWorld extends CraftRegionAccessor implements World {
for (BlockState blockstate : this.world.capturedBlockStates.values()) {
BlockPos position = ((CraftBlockState) blockstate).getPosition();
net.minecraft.world.level.block.state.BlockState oldBlock = this.world.getBlockState(position);
int flag = ((CraftBlockState) blockstate).getFlag();
int flags = ((CraftBlockState) blockstate).getFlags();
delegate.setBlockData(blockstate.getX(), blockstate.getY(), blockstate.getZ(), blockstate.getBlockData());
net.minecraft.world.level.block.state.BlockState newBlock = this.world.getBlockState(position);
this.world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag, 512);
this.world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flags, net.minecraft.world.level.block.Block.UPDATE_LIMIT);
}
this.world.capturedBlockStates.clear();
return true;
@@ -794,15 +795,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public long getTime() {
long time = this.getFullTime() % 24000;
if (time < 0) time += 24000;
long time = this.getFullTime() % Level.TICKS_PER_DAY;
if (time < 0) time += Level.TICKS_PER_DAY;
return time;
}
@Override
public void setTime(long time) {
long margin = (time - this.getFullTime()) % 24000;
if (margin < 0) margin += 24000;
long margin = (time - this.getFullTime()) % Level.TICKS_PER_DAY;
if (margin < 0) margin += Level.TICKS_PER_DAY;
this.setFullTime(this.getFullTime() + margin);
}
@@ -834,7 +835,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
// Paper start
@Override
public boolean isDayTime() {
return getHandle().isDay();
return getHandle().isBrightOutside();
}
// Paper end
@@ -1177,9 +1178,9 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Vector dir = direction.clone().normalize().multiply(maxDistance);
Vec3 startPos = io.papermc.paper.util.MCUtil.toVec3(start); // Paper - Add predicate for blocks when raytracing
Vec3 endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
HitResult nmsHitResult = this.getHandle().clip(new ClipContext(startPos, endPos, ignorePassableBlocks ? ClipContext.Block.COLLIDER : ClipContext.Block.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), CollisionContext.empty()), canCollide); // Paper - Add predicate for blocks when raytracing
HitResult hitResult = this.getHandle().clip(new ClipContext(startPos, endPos, ignorePassableBlocks ? ClipContext.Block.COLLIDER : ClipContext.Block.OUTLINE, CraftFluidCollisionMode.toFluid(fluidCollisionMode), CollisionContext.empty()), canCollide); // Paper - Add predicate for blocks when raytracing
return CraftRayTraceResult.fromNMS(this, nmsHitResult);
return CraftRayTraceResult.convertFromInternal(this.getHandle(), hitResult);
}
@Override
@@ -2314,7 +2315,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return null;
}
return new CraftBiomeSearchResult(CraftBiome.minecraftHolderToBukkit(found.getSecond()), new Location(this, found.getFirst().getX(), found.getFirst().getY(), found.getFirst().getZ()));
return new CraftBiomeSearchResult(CraftBiome.minecraftHolderToBukkit(found.getSecond()), CraftLocation.toBukkit(found.getFirst(), this));
}
@Override
@@ -2324,21 +2325,21 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Raids persistentRaid = this.world.getRaids();
net.minecraft.world.entity.raid.Raid raid = persistentRaid.getNearbyRaid(CraftLocation.toBlockPosition(location), radius * radius);
return (raid == null) ? null : new CraftRaid(raid);
return (raid == null) ? null : new CraftRaid(raid, this.world);
}
// Paper start - more Raid API
@Override
public @Nullable Raid getRaid(final int id) {
final net.minecraft.world.entity.raid.@Nullable Raid nmsRaid = this.world.getRaids().raidMap.get(id);
return nmsRaid != null ? new CraftRaid(nmsRaid) : null;
return nmsRaid != null ? new CraftRaid(nmsRaid, this.world) : null;
}
// Paper end - more Raid API
@Override
public List<Raid> getRaids() {
Raids persistentRaid = this.world.getRaids();
return persistentRaid.raidMap.values().stream().map(CraftRaid::new).collect(Collectors.toList());
return persistentRaid.raidMap.values().stream().map(raid -> new CraftRaid(raid, this.world)).collect(Collectors.toList());
}
@Override
@@ -2390,24 +2391,20 @@ public class CraftWorld extends CraftRegionAccessor implements World {
}
// Spigot start
private final org.bukkit.World.Spigot spigot = new org.bukkit.World.Spigot()
{
private final org.bukkit.World.Spigot spigot = new org.bukkit.World.Spigot() {
@Override
public LightningStrike strikeLightning(Location loc, boolean isSilent)
{
public LightningStrike strikeLightning(Location loc, boolean isSilent) {
return CraftWorld.this.strikeLightning(loc);
}
@Override
public LightningStrike strikeLightningEffect(Location loc, boolean isSilent)
{
public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
return CraftWorld.this.strikeLightningEffect(loc);
}
};
public org.bukkit.World.Spigot spigot()
{
public org.bukkit.World.Spigot spigot() {
return this.spigot;
}
// Spigot end

View File

@@ -7,7 +7,6 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import joptsimple.OptionParser;
@@ -26,12 +25,6 @@ public class Main {
// Paper end - Reset loggers after shutdown
public static void main(String[] args) {
// Paper start
final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected");
if (false && System.getProperty(warnWhenLegacyFormattingDetected) == null) {
System.setProperty(warnWhenLegacyFormattingDetected, String.valueOf(true));
}
// Paper end
// Todo: Installation script
if (System.getProperty("jdk.nio.maxCachedBufferSize") == null) System.setProperty("jdk.nio.maxCachedBufferSize", "262144"); // Paper - cap per-thread NIO cache size; https://www.evanjones.ca/java-bytebuffer-leak.html
OptionParser parser = new OptionParser() {
@@ -149,15 +142,12 @@ public class Main {
this.acceptsAll(Main.asList("initSettings"), "Only create configuration files and then exit"); // SPIGOT-5761: Add initSettings option
// Spigot start
this.acceptsAll(Main.asList("S", "spigot-settings"), "File for spigot settings")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("spigot.yml"))
.describedAs("Yml file");
// Spigot end
// Paper start
acceptsAll(asList("paper-dir", "paper-settings-directory"), "Directory for Paper settings")
.withRequiredArg()
.ofType(File.class)
@@ -174,15 +164,12 @@ public class Main {
.ofType(File.class)
.defaultsTo(new File[] {})
.describedAs("Jar file");
// Paper end
// Paper start
acceptsAll(asList("server-name"), "Name of the server")
.withRequiredArg()
.ofType(String.class)
.defaultsTo("Unknown Server")
.describedAs("Name");
// Paper end
}
};
@@ -226,32 +213,10 @@ public class Main {
// Paper end - Improve java version check
try {
// Paper start - Handled by TerminalConsoleAppender
/*
// This trick bypasses Maven Shade's clever rewriting of our getProperty call when using String literals
String jline_UnsupportedTerminal = new String(new char[]{'j', 'l', 'i', 'n', 'e', '.', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd', 'T', 'e', 'r', 'm', 'i', 'n', 'a', 'l'});
String jline_terminal = new String(new char[]{'j', 'l', 'i', 'n', 'e', '.', 't', 'e', 'r', 'm', 'i', 'n', 'a', 'l'});
Main.useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal));
if (options.has("nojline")) {
System.setProperty("user.language", "en");
Main.useJline = false;
}
if (Main.useJline) {
AnsiConsole.systemInstall();
} else {
// This ensures the terminal literal will always match the jline implementation
System.setProperty(jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName());
}
*/
if (options.has("nojline")) {
System.setProperty(net.minecrell.terminalconsole.TerminalConsoleAppender.JLINE_OVERRIDE_PROPERTY, "false");
useJline = false;
}
// Paper end
if (options.has("noconsole")) {
Main.useConsole = false;
@@ -267,17 +232,14 @@ public class Main {
if (buildDate.before(deadline.getTime())) {
// Paper start - This is some stupid bullshit
System.err.println("*** Warning, you've not updated in a while! ***");
System.err.println("*** Please download a new build from https://papermc.io/downloads/paper ***"); // Paper
//System.err.println("*** Server will start in 20 seconds ***");
//Thread.sleep(TimeUnit.SECONDS.toMillis(20));
System.err.println("*** Please download a new build from https://papermc.io/downloads/paper ***");
// Paper end
}
}
System.setProperty("library.jansi.version", "Paper"); // Paper - set meaningless jansi version to prevent git builds from crashing on Windows
System.setProperty("jdk.console", "java.base"); // Paper - revert default console provider back to java.base so we can have our own jline
//System.out.println("Loading libraries, please wait...");
//net.minecraft.server.Main.main(options);
io.papermc.paper.PaperBootstrap.boot(options);
} catch (Throwable t) {
t.printStackTrace();

View File

@@ -35,14 +35,12 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
return new CraftAdvancementRequirements(this.handle.value().requirements());
}
// Paper start - Add more advancement API
@Override
public io.papermc.paper.advancement.AdvancementDisplay getDisplay() {
return this.handle.value().display().map(d -> d.paper).orElse(null);
}
@Deprecated
@io.papermc.paper.annotation.DoNotUse
public AdvancementDisplay getDisplay0() { // May be called by plugins via Commodore
return this.handle.value().display().map(CraftAdvancementDisplay::new).orElse(null);
}
@@ -62,7 +60,7 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
@Override
public Collection<org.bukkit.advancement.Advancement> getChildren() {
final com.google.common.collect.ImmutableList.Builder<org.bukkit.advancement.Advancement> children = com.google.common.collect.ImmutableList.<org.bukkit.advancement.Advancement>builder();
final com.google.common.collect.ImmutableList.Builder<org.bukkit.advancement.Advancement> children = com.google.common.collect.ImmutableList.builder();
final net.minecraft.advancements.AdvancementNode advancementNode = net.minecraft.server.MinecraftServer.getServer().getAdvancements().tree().get(this.handle);
if (advancementNode != null) {
for (final net.minecraft.advancements.AdvancementNode child : advancementNode.children()) {
@@ -77,5 +75,4 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
final net.minecraft.advancements.AdvancementNode advancementNode = net.minecraft.server.MinecraftServer.getServer().getAdvancements().tree().get(this.handle);
return java.util.Objects.requireNonNull(advancementNode, "could not find internal advancement node for advancement " + this.handle.id()).root().holder().toBukkit();
}
// Paper end - Add more advancement API
}

View File

@@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.inventory.ItemStack;
@Deprecated // Paper
@Deprecated
public class CraftAdvancementDisplay implements org.bukkit.advancement.AdvancementDisplay {
private final DisplayInfo handle;

View File

@@ -6,7 +6,6 @@ import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.attribute.Attribute;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.legacy.FieldRename;

View File

@@ -8,7 +8,6 @@ import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.EquipmentSlot;
public class CraftAttributeInstance implements AttributeInstance {
@@ -45,7 +44,6 @@ public class CraftAttributeInstance implements AttributeInstance {
return result;
}
// Paper start
@Override
public AttributeModifier getModifier(final net.kyori.adventure.key.Key key) {
Preconditions.checkArgument(key != null, "Key cannot be null");
@@ -70,7 +68,6 @@ public class CraftAttributeInstance implements AttributeInstance {
Preconditions.checkArgument(uuid != null, "UUID cannot be null");
this.removeModifier(AttributeMappings.uuidToKey(uuid));
}
// Paper end
@Override
public void addModifier(AttributeModifier modifier) {
@@ -78,13 +75,11 @@ public class CraftAttributeInstance implements AttributeInstance {
this.handle.addPermanentModifier(CraftAttributeInstance.convert(modifier));
}
// Paper start - Transient modifier API
@Override
public void addTransientModifier(AttributeModifier modifier) {
Preconditions.checkArgument(modifier != null, "modifier");
this.handle.addTransientModifier(CraftAttributeInstance.convert(modifier));
}
// Paper end
@Override
public void removeModifier(AttributeModifier modifier) {
@@ -111,6 +106,6 @@ public class CraftAttributeInstance implements AttributeInstance {
}
public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms, net.minecraft.world.entity.EquipmentSlotGroup slot) { // Paper
return new AttributeModifier(CraftNamespacedKey.fromMinecraft(nms.id()), nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()], org.bukkit.craftbukkit.CraftEquipmentSlot.getSlot(slot)); // Paper
return new AttributeModifier(CraftNamespacedKey.fromMinecraft(nms.id()), nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()], org.bukkit.craftbukkit.CraftEquipmentSlot.getSlotGroup(slot)); // Paper
}
}

View File

@@ -9,20 +9,36 @@ import org.bukkit.attribute.AttributeInstance;
public class CraftAttributeMap implements Attributable {
private final AttributeMap handle;
// Paper start - convert legacy attributes
private static final com.google.common.collect.ImmutableMap<String, String> legacyNMS = com.google.common.collect.ImmutableMap.<String, String>builder().put("generic.maxHealth", "generic.max_health").put("Max Health", "generic.max_health").put("zombie.spawnReinforcements", "zombie.spawn_reinforcements").put("Spawn Reinforcements Chance", "zombie.spawn_reinforcements").put("horse.jumpStrength", "horse.jump_strength").put("Jump Strength", "horse.jump_strength").put("generic.followRange", "generic.follow_range").put("Follow Range", "generic.follow_range").put("generic.knockbackResistance", "generic.knockback_resistance").put("Knockback Resistance", "generic.knockback_resistance").put("generic.movementSpeed", "generic.movement_speed").put("Movement Speed", "generic.movement_speed").put("generic.flyingSpeed", "generic.flying_speed").put("Flying Speed", "generic.flying_speed").put("generic.attackDamage", "generic.attack_damage").put("generic.attackKnockback", "generic.attack_knockback").put("generic.attackSpeed", "generic.attack_speed").put("generic.armorToughness", "generic.armor_toughness").build();
// convert legacy attributes
private static final com.google.common.collect.ImmutableMap<String, String> LEGACY_ATTRIBUTE_MAP = com.google.common.collect.ImmutableMap.<String, String>builder()
.put("generic.maxHealth", "generic.max_health")
.put("Max Health", "generic.max_health")
.put("zombie.spawnReinforcements", "zombie.spawn_reinforcements")
.put("Spawn Reinforcements Chance", "zombie.spawn_reinforcements")
.put("horse.jumpStrength", "horse.jump_strength")
.put("Jump Strength", "horse.jump_strength")
.put("generic.followRange", "generic.follow_range")
.put("Follow Range", "generic.follow_range")
.put("generic.knockbackResistance", "generic.knockback_resistance")
.put("Knockback Resistance", "generic.knockback_resistance")
.put("generic.movementSpeed", "generic.movement_speed")
.put("Movement Speed", "generic.movement_speed")
.put("generic.flyingSpeed", "generic.flying_speed")
.put("Flying Speed", "generic.flying_speed")
.put("generic.attackDamage", "generic.attack_damage")
.put("generic.attackKnockback", "generic.attack_knockback")
.put("generic.attackSpeed", "generic.attack_speed")
.put("generic.armorToughness", "generic.armor_toughness")
.buildOrThrow();
public static String convertIfNeeded(String nms) {
if (nms == null) {
return null;
}
nms = legacyNMS.getOrDefault(nms, nms);
nms = LEGACY_ATTRIBUTE_MAP.getOrDefault(nms, nms);
if (!nms.toLowerCase(java.util.Locale.ROOT).equals(nms) || nms.indexOf(' ') != -1) {
return null;
}
return nms;
}
// Paper end
public CraftAttributeMap(AttributeMap handle) {
this.handle = handle;
@@ -35,11 +51,10 @@ public class CraftAttributeMap implements Attributable {
return (nms == null) ? null : new CraftAttributeInstance(nms, attribute);
}
// Paper start - living entity allow attribute registration
@Override
public void registerAttribute(Attribute attribute) {
Preconditions.checkArgument(attribute != null, "attribute");
handle.registerAttribute(CraftAttribute.bukkitToMinecraftHolder(attribute));
this.handle.registerAttribute(CraftAttribute.bukkitToMinecraftHolder(attribute));
}
// Paper end - living entity allow attribute registration
}

View File

@@ -6,8 +6,6 @@ import java.util.Date;
import net.minecraft.server.players.UserBanList;
import net.minecraft.server.players.UserBanListEntry;
import org.bukkit.BanEntry;
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
import org.bukkit.profile.PlayerProfile;
public final class CraftProfileBanEntry implements BanEntry<com.destroystokyo.paper.profile.PlayerProfile> { // Paper
private static final Date minorDate = Date.from(Instant.parse("1899-12-31T04:00:00Z"));

View File

@@ -13,7 +13,6 @@ import net.minecraft.server.players.UserBanList;
import net.minecraft.server.players.UserBanListEntry;
import org.bukkit.BanEntry;
import org.bukkit.ban.ProfileBanList;
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
import org.bukkit.profile.PlayerProfile;
public class CraftProfileBanList implements ProfileBanList {
@@ -36,7 +35,7 @@ public class CraftProfileBanList implements ProfileBanList {
return this.getBanEntry(((com.destroystokyo.paper.profile.SharedPlayerProfile) target).buildGameProfile()); // Paper
}
// Paper start - fix ban list API
@Override
public BanEntry<com.destroystokyo.paper.profile.PlayerProfile> getBanEntry(final com.destroystokyo.paper.profile.PlayerProfile target) {
Preconditions.checkArgument(target != null, "target cannot be null");
@@ -73,7 +72,6 @@ public class CraftProfileBanList implements ProfileBanList {
Instant instant = duration != null ? Instant.now().plus(duration) : null;
return this.addBan(target, reason, instant, source);
}
// Paper end - fix ban list API
@Override
public BanEntry<com.destroystokyo.paper.profile.PlayerProfile> addBan(String target, String reason, Date expires, String source) { // Paper - fix ban list API
@@ -126,11 +124,10 @@ public class CraftProfileBanList implements ProfileBanList {
@Override
public boolean isBanned(PlayerProfile target) {
// Paper start
return this.isBanned((com.destroystokyo.paper.profile.SharedPlayerProfile) target);
}
private boolean isBanned(com.destroystokyo.paper.profile.SharedPlayerProfile target) {
// Paper end
Preconditions.checkArgument(target != null, "Target cannot be null");
return this.isBanned(target.buildGameProfile()); // Paper
@@ -145,11 +142,10 @@ public class CraftProfileBanList implements ProfileBanList {
@Override
public void pardon(PlayerProfile target) {
// Paper start
this.pardon((com.destroystokyo.paper.profile.SharedPlayerProfile) target);
}
private void pardon(com.destroystokyo.paper.profile.SharedPlayerProfile target) {
// Paper end
Preconditions.checkArgument(target != null, "Target cannot be null");
this.pardon(target.buildGameProfile()); // Paper

View File

@@ -5,24 +5,23 @@ import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.util.CraftLocation;
@Deprecated(forRemoval = true)
public final class CapturedBlockState extends CraftBlockState {
private final boolean treeBlock;
public CapturedBlockState(Block block, int flag, boolean treeBlock) {
super(block, flag);
public CapturedBlockState(Block block, int capturedFlags, boolean treeBlock) {
super(block, capturedFlags);
this.treeBlock = treeBlock;
}
protected CapturedBlockState(CapturedBlockState state, Location location) {
private CapturedBlockState(CapturedBlockState state, Location location) {
super(state, location);
this.treeBlock = state.treeBlock;
}
@@ -31,39 +30,39 @@ public final class CapturedBlockState extends CraftBlockState {
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
// Probably no longer needed with the extra #updatedTree method,
// but leave if here for now in case a plugin for whatever reason relies on this.
this.addBees();
if (result) {
this.addBees();
}
return result;
}
private void updatedTree() {
// SPIGOT-7248 - Manual update to avoid physics where appropriate
// SPIGOT-7572 - Move SPIGOT-7248 fix from nms ItemStack to here, to allow bee generation in nests
this.world.getHandle().setBlock(CraftLocation.toBlockPosition(this.getLocation()), this.getHandle(), this.getFlag());
@Override
public boolean place(int flags) {
boolean result = super.place(flags);
this.addBees();
if (result) {
this.addBees();
}
return result;
}
private void addBees() {
// SPIGOT-5537: Horrible hack to manually add bees given World.captureTreeGeneration does not support tiles
// SPIGOT-5537: Horrible hack to manually add bees given Level#captureTreeGeneration does not support block entities
if (this.treeBlock && this.getType() == Material.BEE_NEST) {
WorldGenLevel generatoraccessseed = this.world.getHandle();
BlockPos blockposition1 = this.getPosition();
RandomSource random = generatoraccessseed.getRandom();
WorldGenLevel worldGenLevel = this.world.getHandle();
BlockPos pos = this.getPosition();
RandomSource randomSource = worldGenLevel.getRandom();
// Begin copied block from WorldGenFeatureTreeBeehive
BlockEntity tileentity = generatoraccessseed.getBlockEntity(blockposition1);
// Begin copied block from BeehiveDecorator
worldGenLevel.getBlockEntity(pos, BlockEntityType.BEEHIVE).ifPresent(beehiveBlockEntity -> {
int i1 = 2 + randomSource.nextInt(2);
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity tileentitybeehive = (BeehiveBlockEntity) tileentity;
int j = 2 + random.nextInt(2);
for (int k = 0; k < j; ++k) {
tileentitybeehive.storeBee(BeehiveBlockEntity.Occupant.create(random.nextInt(599)));
for (int i2 = 0; i2 < i1; i2++) {
beehiveBlockEntity.storeBee(BeehiveBlockEntity.Occupant.create(randomSource.nextInt(599)));
}
}
});
// End copied block
}
}
@@ -78,19 +77,7 @@ public final class CapturedBlockState extends CraftBlockState {
return new CapturedBlockState(this, location);
}
public static CapturedBlockState getBlockState(Level world, BlockPos pos, int flag) {
return new CapturedBlockState(world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), flag, false);
}
public static CapturedBlockState getTreeBlockState(Level world, BlockPos pos, int flag) {
return new CapturedBlockState(world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), flag, true);
}
public static void setBlockState(BlockState blockState) {
if (blockState instanceof CapturedBlockState capturedBlockState) {
capturedBlockState.updatedTree();
} else {
blockState.update(true);
}
return new CapturedBlockState(CraftBlock.at(world, pos), flag, true);
}
}

View File

@@ -19,8 +19,8 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
private DyeColor base;
private List<Pattern> patterns;
public CraftBanner(World world, BannerBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBanner(World world, BannerBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBanner(CraftBanner state, Location location) {
@@ -30,21 +30,19 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
}
@Override
public void load(BannerBlockEntity banner) {
super.load(banner);
public void load(BannerBlockEntity blockEntity) {
super.load(blockEntity);
this.base = DyeColor.getByWoolData((byte) ((AbstractBannerBlock) this.data.getBlock()).getColor().getId());
this.patterns = new ArrayList<Pattern>();
this.patterns = new ArrayList<>();
if (banner.getPatterns() != null) {
for (int i = 0; i < banner.getPatterns().layers().size(); i++) {
BannerPatternLayers.Layer p = banner.getPatterns().layers().get(i);
// Paper start - fix upstream not handling inlined banner pattern
java.util.Optional<org.bukkit.block.banner.PatternType> type = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(RegistryKey.BANNER_PATTERN, p.pattern());
if (type.isEmpty()) continue;
this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), type.get()));
// Paper end - fix upstream not handling inlined banner pattern
}
for (int i = 0; i < blockEntity.getPatterns().layers().size(); i++) {
BannerPatternLayers.Layer p = blockEntity.getPatterns().layers().get(i);
// Paper start - fix upstream not handling inlined banner pattern
java.util.Optional<org.bukkit.block.banner.PatternType> type = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(RegistryKey.BANNER_PATTERN, p.pattern());
if (type.isEmpty()) continue;
this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), type.get()));
// Paper end - fix upstream not handling inlined banner pattern
}
}
@@ -95,17 +93,17 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
}
@Override
public void applyTo(BannerBlockEntity banner) {
super.applyTo(banner);
public void applyTo(BannerBlockEntity blockEntity) {
super.applyTo(blockEntity);
banner.baseColor = net.minecraft.world.item.DyeColor.byId(this.base.getWoolData());
blockEntity.baseColor = net.minecraft.world.item.DyeColor.byId(this.base.getWoolData());
List<BannerPatternLayers.Layer> newPatterns = new ArrayList<>();
for (Pattern p : this.patterns) {
newPatterns.add(new net.minecraft.world.level.block.entity.BannerPatternLayers.Layer(CraftPatternType.bukkitToMinecraftHolder(p.getPattern()), net.minecraft.world.item.DyeColor.byId(p.getColor().getWoolData())));
}
banner.setPatterns(new BannerPatternLayers(newPatterns));
blockEntity.setPatterns(new BannerPatternLayers(newPatterns));
}
@Override
@@ -118,15 +116,14 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
return new CraftBanner(this, location);
}
// Paper start
@Override
public net.kyori.adventure.text.Component customName() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getSnapshot().getCustomName());
return this.getSnapshot().name == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getSnapshot().name);
}
@Override
public void customName(net.kyori.adventure.text.Component customName) {
this.getSnapshot().name = io.papermc.paper.adventure.PaperAdventure.asVanilla(customName);
this.getSnapshot().name = customName == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(customName);
}
@Override
@@ -138,5 +135,4 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
public void setCustomName(String name) {
this.customName(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOrNull(name));
}
// Paper end
}

View File

@@ -12,8 +12,8 @@ import org.bukkit.inventory.Inventory;
public class CraftBarrel extends CraftLootable<BarrelBlockEntity> implements Barrel {
public CraftBarrel(World world, BarrelBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBarrel(World world, BarrelBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBarrel(CraftBarrel state, Location location) {
@@ -31,37 +31,37 @@ public class CraftBarrel extends CraftLootable<BarrelBlockEntity> implements Bar
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override
public void open() {
this.requirePlaced();
if (!this.getTileEntity().openersCounter.opened) {
BlockState blockData = this.getTileEntity().getBlockState();
boolean open = blockData.getValue(BarrelBlock.OPEN);
if (!this.getBlockEntity().openersCounter.opened) {
BlockState state = this.getBlockEntity().getBlockState();
boolean open = state.getValue(BarrelBlock.OPEN);
if (!open) {
this.getTileEntity().updateBlockState(blockData, true);
this.getBlockEntity().updateBlockState(state, true);
if (this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
this.getTileEntity().playSound(blockData, SoundEvents.BARREL_OPEN);
this.getBlockEntity().playSound(state, SoundEvents.BARREL_OPEN);
}
}
}
this.getTileEntity().openersCounter.opened = true;
this.getBlockEntity().openersCounter.opened = true;
}
@Override
public void close() {
this.requirePlaced();
if (this.getTileEntity().openersCounter.opened) {
BlockState blockData = this.getTileEntity().getBlockState();
this.getTileEntity().updateBlockState(blockData, false);
if (this.getBlockEntity().openersCounter.opened) {
BlockState state = this.getBlockEntity().getBlockState();
this.getBlockEntity().updateBlockState(state, false);
if (this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
this.getTileEntity().playSound(blockData, SoundEvents.BARREL_CLOSE);
this.getBlockEntity().playSound(state, SoundEvents.BARREL_CLOSE);
}
}
this.getTileEntity().openersCounter.opened = false;
this.getBlockEntity().openersCounter.opened = false;
}
@Override
@@ -77,7 +77,7 @@ public class CraftBarrel extends CraftLootable<BarrelBlockEntity> implements Bar
// Paper start - More Lidded Block API
@Override
public boolean isOpen() {
return getTileEntity().openersCounter.opened;
return getBlockEntity().openersCounter.opened;
}
// Paper end - More Lidded Block API
}

View File

@@ -4,9 +4,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import net.minecraft.advancements.critereon.DataComponentMatchers;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.component.DataComponentPredicate;
import net.minecraft.core.component.DataComponentExactPredicate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.LockCode;
@@ -26,8 +27,8 @@ import org.bukkit.potion.PotionEffectType;
public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implements Beacon {
public CraftBeacon(World world, BeaconBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBeacon(World world, BeaconBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBeacon(CraftBeacon state, Location location) {
@@ -38,12 +39,12 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
public Collection<LivingEntity> getEntitiesInRange() {
this.ensureNoWorldGeneration();
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof BeaconBlockEntity) {
BeaconBlockEntity beacon = (BeaconBlockEntity) tileEntity;
BlockEntity blockEntity = this.getBlockEntityFromWorld();
if (blockEntity instanceof BeaconBlockEntity) {
BeaconBlockEntity beacon = (BeaconBlockEntity) blockEntity;
Collection<Player> nms = BeaconBlockEntity.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels, beacon); // Paper - Custom beacon ranges
Collection<LivingEntity> bukkit = new ArrayList<LivingEntity>(nms.size());
Collection<LivingEntity> bukkit = new ArrayList<>(nms.size());
for (Player human : nms) {
bukkit.add(human.getBukkitEntity());
@@ -53,7 +54,7 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
}
// block is no longer a beacon
return new ArrayList<LivingEntity>();
return new ArrayList<>();
}
@Override
@@ -81,18 +82,16 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraftHolder(effect) : null;
}
// Paper start
@Override
public net.kyori.adventure.text.Component customName() {
final BeaconBlockEntity be = this.getSnapshot();
return be.name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.name) : null;
final BeaconBlockEntity beacon = this.getSnapshot();
return beacon.name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(beacon.name) : null;
}
@Override
public void customName(final net.kyori.adventure.text.Component customName) {
this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
}
// Paper end
@Override
public String getCustomName() {
@@ -112,7 +111,7 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
@Override
public String getLock() {
Optional<? extends Component> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
Optional<? extends Component> customName = this.getSnapshot().lockKey.predicate().components().exact().asPatch().get(DataComponents.CUSTOM_NAME);
return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : "";
}
@@ -122,8 +121,8 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
if (key == null) {
this.getSnapshot().lockKey = LockCode.NO_LOCK;
} else {
DataComponentPredicate predicate = DataComponentPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build();
this.getSnapshot().lockKey = new LockCode(new ItemPredicate(Optional.empty(), MinMaxBounds.Ints.ANY, predicate, Collections.emptyMap()));
DataComponentExactPredicate predicate = DataComponentExactPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build();
this.getSnapshot().lockKey = new LockCode(new ItemPredicate(Optional.empty(), MinMaxBounds.Ints.ANY, new DataComponentMatchers(predicate, Collections.emptyMap())));
}
}

View File

@@ -8,8 +8,8 @@ import org.bukkit.block.Bed;
public class CraftBed extends CraftBlockEntityState<BedBlockEntity> implements Bed {
public CraftBed(World world, BedBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBed(World world, BedBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBed(CraftBed state, Location location) {
@@ -18,42 +18,25 @@ public class CraftBed extends CraftBlockEntityState<BedBlockEntity> implements B
@Override
public DyeColor getColor() {
switch (this.getType()) {
case BLACK_BED:
return DyeColor.BLACK;
case BLUE_BED:
return DyeColor.BLUE;
case BROWN_BED:
return DyeColor.BROWN;
case CYAN_BED:
return DyeColor.CYAN;
case GRAY_BED:
return DyeColor.GRAY;
case GREEN_BED:
return DyeColor.GREEN;
case LIGHT_BLUE_BED:
return DyeColor.LIGHT_BLUE;
case LIGHT_GRAY_BED:
return DyeColor.LIGHT_GRAY;
case LIME_BED:
return DyeColor.LIME;
case MAGENTA_BED:
return DyeColor.MAGENTA;
case ORANGE_BED:
return DyeColor.ORANGE;
case PINK_BED:
return DyeColor.PINK;
case PURPLE_BED:
return DyeColor.PURPLE;
case RED_BED:
return DyeColor.RED;
case WHITE_BED:
return DyeColor.WHITE;
case YELLOW_BED:
return DyeColor.YELLOW;
default:
throw new IllegalArgumentException("Unknown DyeColor for " + this.getType());
}
return switch (this.getType()) {
case BLACK_BED -> DyeColor.BLACK;
case BLUE_BED -> DyeColor.BLUE;
case BROWN_BED -> DyeColor.BROWN;
case CYAN_BED -> DyeColor.CYAN;
case GRAY_BED -> DyeColor.GRAY;
case GREEN_BED -> DyeColor.GREEN;
case LIGHT_BLUE_BED -> DyeColor.LIGHT_BLUE;
case LIGHT_GRAY_BED -> DyeColor.LIGHT_GRAY;
case LIME_BED -> DyeColor.LIME;
case MAGENTA_BED -> DyeColor.MAGENTA;
case ORANGE_BED -> DyeColor.ORANGE;
case PINK_BED -> DyeColor.PINK;
case PURPLE_BED -> DyeColor.PURPLE;
case RED_BED -> DyeColor.RED;
case WHITE_BED -> DyeColor.WHITE;
case YELLOW_BED -> DyeColor.YELLOW;
default -> throw new IllegalArgumentException("Unknown DyeColor for " + this.getType());
};
}
@Override

View File

@@ -16,8 +16,8 @@ import org.bukkit.entity.Bee;
public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> implements Beehive {
public CraftBeehive(World world, BeehiveBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBeehive(World world, BeehiveBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBeehive(CraftBeehive state, Location location) {
@@ -43,7 +43,7 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
@Override
public boolean isSedated() {
return this.isPlaced() && this.getTileEntity().isSedated();
return this.isPlaced() && this.getBlockEntity().isSedated();
}
@Override
@@ -70,7 +70,7 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
List<Bee> bees = new ArrayList<>();
if (this.isPlaced()) {
BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getTileEntityFromWorld());
BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getBlockEntityFromWorld());
for (Entity bee : beehive.releaseBees(this.getHandle(), BeeReleaseStatus.BEE_RELEASED, true)) {
bees.add((Bee) bee.getBukkitEntity());
}

View File

@@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.BellBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BellBlockEntity;
@@ -15,8 +14,8 @@ import org.bukkit.entity.Entity;
public class CraftBell extends CraftBlockEntityState<BellBlockEntity> implements Bell {
public CraftBell(World world, BellBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBell(World world, BellBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBell(CraftBell state, Location location) {
@@ -27,30 +26,13 @@ public class CraftBell extends CraftBlockEntityState<BellBlockEntity> implements
public boolean ring(Entity entity, BlockFace direction) {
Preconditions.checkArgument(direction == null || direction.isCartesian(), "direction must be cartesian, given %s", direction);
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity == null) {
BlockEntity blockEntity = this.getBlockEntityFromWorld();
if (blockEntity == null) {
return false;
}
net.minecraft.world.entity.Entity nmsEntity = (entity != null) ? ((CraftEntity) entity).getHandle() : null;
Direction enumDirection = CraftBlock.blockFaceToNotch(direction);
return ((BellBlock) Blocks.BELL).attemptToRing(nmsEntity, this.world.getHandle(), this.getPosition(), enumDirection);
}
@Override
public boolean ring(Entity entity) {
return this.ring(entity, null);
}
@Override
public boolean ring(BlockFace direction) {
return this.ring(null, direction);
}
@Override
public boolean ring() {
return this.ring(null, null);
return ((BellBlock) Blocks.BELL).attemptToRing(nmsEntity, this.world.getHandle(), this.getPosition(), CraftBlock.blockFaceToNotch(direction));
}
@Override

View File

@@ -1,15 +1,19 @@
package org.bukkit.craftbukkit.block;
import java.util.Locale;
import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.Objects;
public class CraftBiome implements Biome, Handleable<net.minecraft.world.level.biome.Biome> {
@NullMarked
public class CraftBiome extends OldEnumHolderable<Biome, net.minecraft.world.level.biome.Biome> implements Biome {
private static int count = 0;
@@ -18,10 +22,10 @@ public class CraftBiome implements Biome, Handleable<net.minecraft.world.level.b
}
public static Biome minecraftHolderToBukkit(Holder<net.minecraft.world.level.biome.Biome> minecraft) {
return CraftBiome.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.BIOME);
}
public static net.minecraft.world.level.biome.Biome bukkitToMinecraft(Biome bukkit) {
public static net.minecraft.world.level.biome.@Nullable Biome bukkitToMinecraft(Biome bukkit) {
if (bukkit == Biome.CUSTOM) {
return null;
}
@@ -29,89 +33,68 @@ public class CraftBiome implements Biome, Handleable<net.minecraft.world.level.b
return CraftRegistry.bukkitToMinecraft(bukkit);
}
public static Holder<net.minecraft.world.level.biome.Biome> bukkitToMinecraftHolder(Biome bukkit) {
public static @Nullable Holder<net.minecraft.world.level.biome.Biome> bukkitToMinecraftHolder(Biome bukkit) {
if (bukkit == Biome.CUSTOM) {
return null;
}
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.BIOME);
}
net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME);
public CraftBiome(final Holder<net.minecraft.world.level.biome.Biome> holder) {
super(holder, count++);
}
if (registry.wrapAsHolder(CraftBiome.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.level.biome.Biome> holder) {
return holder;
/**
* Implementation for the deprecated, API only, CUSTOM biome.
* As per {@link #bukkitToMinecraft(Biome)} and {@link #bukkitToMinecraftHolder(Biome)} it cannot be
* converted into an internal biome and only serves backwards compatibility reasons.
*/
@Deprecated(forRemoval = true, since = "1.21.5")
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
public static class LegacyCustomBiomeImpl implements Biome {
private static final NamespacedKey LEGACY_CUSTOM_KEY = new NamespacedKey("minecraft", "custom");
private final int ordinal;
public LegacyCustomBiomeImpl() {
this.ordinal = count++;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own biome base with out properly registering it.");
}
private final NamespacedKey key;
private final net.minecraft.world.level.biome.Biome biomeBase;
private final String name;
private final int ordinal;
public CraftBiome(NamespacedKey key, net.minecraft.world.level.biome.Biome biomeBase) {
this.key = key;
this.biomeBase = biomeBase;
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive biome specific values.
// Custom biomes will return the key with namespace. For a plugin this should look than like a new biome
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftBiome.count++;
}
@Override
public net.minecraft.world.level.biome.Biome getHandle() {
return this.biomeBase;
}
@NotNull
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(@NotNull Biome biome) {
return this.ordinal - biome.ordinal();
}
@NotNull
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
@Override
public @NotNull NamespacedKey getKey() {
return LEGACY_CUSTOM_KEY;
}
if (!(other instanceof CraftBiome otherBiome)) {
return false;
@Override
public int compareTo(@NotNull final Biome other) {
return this.ordinal - other.ordinal();
}
return this.getKey().equals(otherBiome.getKey());
}
@Override
public @NotNull String name() {
return "CUSTOM";
}
@Override
public int hashCode() {
return this.getKey().hashCode();
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public boolean equals(final Object object) {
if (object == null || getClass() != object.getClass()) return false;
final LegacyCustomBiomeImpl that = (LegacyCustomBiomeImpl) object;
return ordinal == that.ordinal;
}
@Override
public int hashCode() {
return Objects.hashCode(ordinal);
}
@Override
public String toString() {
return "CUSTOM";
}
}
}

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.BlastFurnace;
public class CraftBlastFurnace extends CraftFurnace<BlastFurnaceBlockEntity> implements BlastFurnace {
public CraftBlastFurnace(World world, BlastFurnaceBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBlastFurnace(World world, BlastFurnaceBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBlastFurnace(CraftBlastFurnace state, Location location) {

View File

@@ -78,11 +78,9 @@ public class CraftBlock implements Block {
return this.world.getBlockState(this.position);
}
// Paper start
public net.minecraft.world.level.material.FluidState getNMSFluid() {
return this.world.getFluidState(this.position);
}
// Paper end
public BlockPos getPosition() {
return this.position;
@@ -145,25 +143,25 @@ public class CraftBlock implements Block {
}
public void setData(final byte data) {
this.setData(data, 3);
this.setData(data, net.minecraft.world.level.block.Block.UPDATE_ALL);
}
public void setData(final byte data, boolean applyPhysics) {
if (applyPhysics) {
this.setData(data, 3);
this.setData(data, net.minecraft.world.level.block.Block.UPDATE_ALL);
} else {
this.setData(data, 2);
this.setData(data, net.minecraft.world.level.block.Block.UPDATE_CLIENTS);
}
}
private void setData(final byte data, int flag) {
this.world.setBlock(this.position, CraftMagicNumbers.getBlock(this.getType(), data), flag);
private void setData(final byte data, int flags) {
this.world.setBlock(this.position, CraftMagicNumbers.getBlock(this.getType(), data), flags);
}
@Override
public byte getData() {
net.minecraft.world.level.block.state.BlockState blockData = this.world.getBlockState(this.position);
return CraftMagicNumbers.toLegacyData(blockData);
net.minecraft.world.level.block.state.BlockState state = this.world.getBlockState(this.position);
return CraftMagicNumbers.toLegacyData(state);
}
@Override
@@ -190,34 +188,37 @@ public class CraftBlock implements Block {
@Override
public void setBlockData(BlockData data, boolean applyPhysics) {
Preconditions.checkArgument(data != null, "BlockData cannot be null");
this.setTypeAndData(((CraftBlockData) data).getState(), applyPhysics);
this.setBlockState(((CraftBlockData) data).getState(), applyPhysics);
}
boolean setTypeAndData(final net.minecraft.world.level.block.state.BlockState blockData, final boolean applyPhysics) {
return CraftBlock.setTypeAndData(this.world, this.position, this.getNMS(), blockData, applyPhysics);
boolean setBlockState(final net.minecraft.world.level.block.state.BlockState state, final boolean applyPhysics) {
return CraftBlock.setBlockState(this.world, this.position, this.getNMS(), state, applyPhysics);
}
public static boolean setTypeAndData(LevelAccessor world, BlockPos position, net.minecraft.world.level.block.state.BlockState old, net.minecraft.world.level.block.state.BlockState blockData, boolean applyPhysics) {
// SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup
if (old.hasBlockEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes
public static boolean setBlockState(LevelAccessor world, BlockPos pos, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState, boolean applyPhysics) {
// SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in block entity cleanup
if (oldState.hasBlockEntity() && newState.getBlock() != oldState.getBlock()) { // SPIGOT-3725 remove old block entity if block changes
// SPIGOT-4612: faster - just clear tile
if (world instanceof net.minecraft.world.level.Level) {
((net.minecraft.world.level.Level) world).removeBlockEntity(position);
((net.minecraft.world.level.Level) world).removeBlockEntity(pos);
} else {
world.setBlock(position, Blocks.AIR.defaultBlockState(), 0);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 0);
}
}
if (applyPhysics) {
return world.setBlock(position, blockData, 3);
return world.setBlock(pos, newState, net.minecraft.world.level.block.Block.UPDATE_ALL);
} else {
boolean success = world.setBlock(position, blockData, 2 | 16 | 1024); // NOTIFY | NO_OBSERVER | NO_PLACE (custom)
boolean success = world.setBlock(pos, newState,
net.minecraft.world.level.block.Block.UPDATE_CLIENTS |
net.minecraft.world.level.block.Block.UPDATE_KNOWN_SHAPE |
net.minecraft.world.level.block.Block.UPDATE_SKIP_ON_PLACE);
if (success && world instanceof net.minecraft.world.level.Level) {
world.getMinecraftWorld().sendBlockUpdated(
position,
old,
blockData,
3
pos,
oldState,
newState,
net.minecraft.world.level.block.Block.UPDATE_ALL
);
}
return success;
@@ -282,7 +283,7 @@ public class CraftBlock implements Block {
@Override
public String toString() {
return "CraftBlock{pos=" + this.position + ",type=" + this.getType() + ",data=" + this.getNMS() + ",fluid=" + this.world.getFluidState(this.position) + '}';
return "CraftBlock{pos=" + this.position + ",type=" + this.getType() + ",data=" + this.getNMS() + ",fluid=" + this.getNMSFluid() + '}';
}
public static BlockFace notchToBlockFace(Direction notch) {
@@ -406,7 +407,7 @@ public class CraftBlock implements Block {
Block relative = this.getRelative(face);
if (relative.getType() == Material.REDSTONE_WIRE) {
return Math.max(power, relative.getData()) > 0;
return Math.max(power, relative.getData()) > 0; // todo remove legacy usage
}
return power > 0;
@@ -428,13 +429,11 @@ public class CraftBlock implements Block {
return power > 0 ? power : (face == BlockFace.SELF ? this.isBlockIndirectlyPowered() : this.isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
}
private static int getPower(int i, net.minecraft.world.level.block.state.BlockState iblockdata) {
if (!iblockdata.is(Blocks.REDSTONE_WIRE)) {
return i;
private static int getPower(int power, net.minecraft.world.level.block.state.BlockState state) {
if (!state.is(Blocks.REDSTONE_WIRE)) {
return power;
} else {
int j = iblockdata.getValue(RedStoneWireBlock.POWER);
return j > i ? j : i;
return Math.max(state.getValue(RedStoneWireBlock.POWER), power);
}
}
@@ -502,39 +501,39 @@ public class CraftBlock implements Block {
public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience) {
// Paper end
// Order matters here, need to drop before setting to air so skulls can get their data
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
net.minecraft.world.level.block.Block block = iblockdata.getBlock();
net.minecraft.world.level.block.state.BlockState state = this.getNMS();
net.minecraft.world.level.block.Block block = state.getBlock();
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
boolean result = false;
// Modelled off EntityHuman#hasBlock
if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) {
net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem, false); // Paper - Properly handle xp dropping
// Paper start - improve Block#breanNaturally
// Modelled off Player#hasCorrectToolForDrops
if (block != Blocks.AIR && (item == null || !state.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(state))) {
net.minecraft.world.level.block.Block.dropResources(state, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem, false); // Paper - Properly handle xp dropping
// Paper start - improve Block#breakNaturally
if (triggerEffect) {
if (iblockdata.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {
if (state.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.SOUND_EXTINGUISH_FIRE, this.position, 0);
} else {
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.PARTICLES_DESTROY_BLOCK, this.position, net.minecraft.world.level.block.Block.getId(iblockdata));
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.PARTICLES_DESTROY_BLOCK, this.position, net.minecraft.world.level.block.Block.getId(state));
}
}
if (dropExperience) block.popExperience(this.world.getMinecraftWorld(), this.position, block.getExpDrop(iblockdata, this.world.getMinecraftWorld(), this.position, nmsItem, true));
if (dropExperience) block.popExperience(this.world.getMinecraftWorld(), this.position, block.getExpDrop(state, this.world.getMinecraftWorld(), this.position, nmsItem, true));
// Paper end
result = true;
}
// SPIGOT-6778: Directly call setBlock instead of setTypeAndData, so that the tile entiy is not removed and custom remove logic is run.
// SPIGOT-6778: Directly call setBlock instead of setBlockState, so that the block entity is not removed and custom remove logic is run.
// Paper start - improve breakNaturally
boolean destroyed = this.world.removeBlock(this.position, false);
if (destroyed) {
block.destroy(this.world, this.position, iblockdata);
block.destroy(this.world, this.position, state);
}
if (result) {
// special cases
if (block instanceof net.minecraft.world.level.block.IceBlock iceBlock) {
iceBlock.afterDestroy(this.world.getMinecraftWorld(), this.position, nmsItem);
} else if (block instanceof net.minecraft.world.level.block.TurtleEggBlock turtleEggBlock) {
turtleEggBlock.decreaseEggs(this.world.getMinecraftWorld(), this.position, iblockdata);
turtleEggBlock.decreaseEggs(this.world.getMinecraftWorld(), this.position, state);
}
}
return destroyed && result;
@@ -553,26 +552,27 @@ public class CraftBlock implements Block {
InteractionResult result = BoneMealItem.applyBonemeal(context);
world.captureTreeGeneration = false;
if (world.capturedBlockStates.size() > 0) {
if (!world.capturedBlockStates.isEmpty()) {
TreeType treeType = SaplingBlock.treeType;
SaplingBlock.treeType = null;
List<BlockState> blocks = new ArrayList<>(world.capturedBlockStates.values());
List<BlockState> states = new ArrayList<>(world.capturedBlockStates.values());
world.capturedBlockStates.clear();
StructureGrowEvent structureEvent = null;
if (treeType != null) {
structureEvent = new StructureGrowEvent(this.getLocation(), treeType, true, null, blocks);
structureEvent = new StructureGrowEvent(this.getLocation(), treeType, true, null, states);
Bukkit.getPluginManager().callEvent(structureEvent);
}
event = new BlockFertilizeEvent(CraftBlock.at(world, this.getPosition()), null, blocks);
event = new BlockFertilizeEvent(CraftBlock.at(world, this.getPosition()), null, states);
event.setCancelled(structureEvent != null && structureEvent.isCancelled());
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
for (BlockState blockstate : blocks) {
blockstate.update(true);
world.checkCapturedTreeStateForObserverNotify(this.position, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
for (BlockState state : states) {
CraftBlockState craftBlockState = (CraftBlockState) state;
craftBlockState.place(craftBlockState.getFlags());
world.checkCapturedTreeStateForObserverNotify(this.position, craftBlockState); // Paper - notify observers even if grow failed
}
}
}
@@ -592,12 +592,12 @@ public class CraftBlock implements Block {
@Override
public Collection<ItemStack> getDrops(ItemStack item, Entity entity) {
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
net.minecraft.world.level.block.state.BlockState state = this.getNMS();
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(item);
// Modelled off EntityHuman#hasBlock
if (item == null || CraftBlockData.isPreferredTool(iblockdata, nms)) {
return net.minecraft.world.level.block.Block.getDrops(iblockdata, (ServerLevel) this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), entity == null ? null : ((CraftEntity) entity).getHandle(), nms)
// Modelled off Player#hasCorrectToolForDrops
if (item == null || CraftBlockData.isPreferredTool(state, nms)) {
return net.minecraft.world.level.block.Block.getDrops(state, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), entity == null ? null : ((CraftEntity) entity).getHandle(), nms)
.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList());
} else {
return Collections.emptyList();
@@ -606,9 +606,9 @@ public class CraftBlock implements Block {
@Override
public boolean isPreferredTool(ItemStack item) {
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
net.minecraft.world.level.block.state.BlockState state = this.getNMS();
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(item);
return CraftBlockData.isPreferredTool(iblockdata, nms);
return CraftBlockData.isPreferredTool(state, nms);
}
@Override
@@ -658,11 +658,11 @@ public class CraftBlock implements Block {
}
Vector dir = direction.clone().normalize().multiply(maxDistance);
Vec3 startPos = CraftLocation.toVec3D(start);
Vec3 startPos = CraftLocation.toVec3(start);
Vec3 endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
HitResult nmsHitResult = this.world.clip(new ClipContext(startPos, endPos, ClipContext.Block.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), CollisionContext.empty()), this.position);
return CraftRayTraceResult.fromNMS(this.getWorld(), nmsHitResult);
HitResult hitResult = this.world.clip(new ClipContext(startPos, endPos, ClipContext.Block.OUTLINE, CraftFluidCollisionMode.toFluid(fluidCollisionMode), CollisionContext.empty()), this.position);
return CraftRayTraceResult.convertFromInternal(this.world, hitResult);
}
@Override

View File

@@ -9,12 +9,12 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.TileState;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.NotNull;
@@ -22,25 +22,25 @@ import org.jetbrains.annotations.Nullable;
public abstract class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockState implements TileState { // Paper - revert upstream's revert of the block state changes
private final T tileEntity;
private final T blockEntity;
private final T snapshot;
public boolean snapshotDisabled; // Paper
public static boolean DISABLE_SNAPSHOT = false; // Paper
public CraftBlockEntityState(World world, T tileEntity) {
super(world, tileEntity.getBlockPos(), tileEntity.getBlockState());
public CraftBlockEntityState(World world, T blockEntity) {
super(world, blockEntity.getBlockPos(), blockEntity.getBlockState());
this.tileEntity = tileEntity;
this.blockEntity = blockEntity;
try { // Paper - Show blockstate location if we failed to read it
// Paper start
this.snapshotDisabled = DISABLE_SNAPSHOT;
if (DISABLE_SNAPSHOT) {
this.snapshot = this.tileEntity;
this.snapshot = this.blockEntity;
} else {
this.snapshot = this.createSnapshot(tileEntity);
this.snapshot = this.createSnapshot(blockEntity);
}
// copy tile entity data:
// copy block entity data:
if (this.snapshot != null) {
this.load(this.snapshot);
}
@@ -62,29 +62,27 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
protected CraftBlockEntityState(CraftBlockEntityState<T> state, Location location) {
super(state, location);
this.tileEntity = this.createSnapshot(state.snapshot);
this.snapshot = this.tileEntity;
this.blockEntity = this.createSnapshot(state.snapshot);
this.snapshot = this.blockEntity;
this.loadData(state.getSnapshotNBT());
}
public void refreshSnapshot() {
this.load(this.tileEntity);
this.load(this.blockEntity);
}
private RegistryAccess getRegistryAccess() {
LevelAccessor worldHandle = this.getWorldHandle();
return (worldHandle != null) ? worldHandle.registryAccess() : MinecraftServer.getDefaultRegistryAccess();
return (worldHandle != null) ? worldHandle.registryAccess() : CraftRegistry.getMinecraftRegistry();
}
private T createSnapshot(T tileEntity) {
if (tileEntity == null) {
private T createSnapshot(T from) {
if (from == null) {
return null;
}
CompoundTag nbtTagCompound = tileEntity.saveWithFullMetadata(this.getRegistryAccess());
T snapshot = (T) BlockEntity.loadStatic(this.getPosition(), this.getHandle(), nbtTagCompound, this.getRegistryAccess());
return snapshot;
CompoundTag tag = from.saveWithFullMetadata(this.getRegistryAccess());
return (T) BlockEntity.loadStatic(this.getPosition(), this.getHandle(), tag, this.getRegistryAccess());
}
public Set<DataComponentType<?>> applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) {
@@ -97,36 +95,36 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
return this.snapshot.collectComponents();
}
// Loads the specified data into the snapshot TileEntity.
public void loadData(CompoundTag nbtTagCompound) {
this.snapshot.loadWithComponents(nbtTagCompound, this.getRegistryAccess());
// Loads the specified data into the snapshot BlockEntity.
public void loadData(CompoundTag tag) {
this.snapshot.loadWithComponents(tag, this.getRegistryAccess());
this.load(this.snapshot);
}
// copies the TileEntity-specific data, retains the position
// copies the BlockEntity-specific data, retains the position
private void copyData(T from, T to) {
CompoundTag nbtTagCompound = from.saveWithFullMetadata(this.getRegistryAccess());
to.loadWithComponents(nbtTagCompound, this.getRegistryAccess());
CompoundTag tag = from.saveWithFullMetadata(this.getRegistryAccess());
to.loadWithComponents(tag, this.getRegistryAccess());
}
// gets the wrapped TileEntity
public T getTileEntity() {
return this.tileEntity;
// gets the wrapped BlockEntity
public T getBlockEntity() {
return this.blockEntity;
}
// gets the cloned TileEntity which is used to store the captured data
// gets the cloned BlockEntity which is used to store the captured data
protected T getSnapshot() {
return this.snapshot;
}
// gets the current TileEntity from the world at this position
protected BlockEntity getTileEntityFromWorld() {
// gets the current BlockEntity from the world at this position
protected BlockEntity getBlockEntityFromWorld() {
this.requirePlaced();
return this.getWorldHandle().getBlockEntity(this.getPosition());
}
// gets the NBT data of the TileEntity represented by this block state
// gets the NBT data of the BlockEntity represented by this block state
public CompoundTag getSnapshotNBT() {
// update snapshot
this.applyTo(this.snapshot);
@@ -134,21 +132,7 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
return this.snapshot.saveWithFullMetadata(this.getRegistryAccess());
}
public CompoundTag getItemNBT() {
// update snapshot
this.applyTo(this.snapshot);
// See TileEntity#saveToItem
CompoundTag nbt = this.snapshot.saveCustomOnly(this.getRegistryAccess());
this.snapshot.removeComponentsFromTag(nbt);
return nbt;
}
public void addEntityType(CompoundTag nbt) {
BlockEntity.addEntityType(nbt, this.snapshot.getType());
}
// gets the packet data of the TileEntity represented by this block state
// gets the packet data of the BlockEntity represented by this block state
public CompoundTag getUpdateNBT() {
// update snapshot
this.applyTo(this.snapshot);
@@ -169,40 +153,47 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
}
// Paper end
// copies the data of the given tile entity to this block state
protected void load(T tileEntity) {
if (tileEntity != null && tileEntity != this.snapshot) {
this.copyData(tileEntity, this.snapshot);
// copies the data of the given block entity to this block state
protected void load(T blockEntity) {
if (blockEntity != null && blockEntity != this.snapshot) {
this.copyData(blockEntity, this.snapshot);
}
}
// applies the TileEntity data of this block state to the given TileEntity
protected void applyTo(T tileEntity) {
if (tileEntity != null && tileEntity != this.snapshot) {
this.copyData(this.snapshot, tileEntity);
// applies the BlockEntity data of this block state to the given BlockEntity
protected void applyTo(T blockEntity) {
if (blockEntity != null && blockEntity != this.snapshot) {
this.copyData(this.snapshot, blockEntity);
}
}
protected boolean isApplicable(BlockEntity tileEntity) {
return tileEntity != null && this.tileEntity.getClass() == tileEntity.getClass();
}
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced()) {
BlockEntity tile = this.getTileEntityFromWorld();
if (this.isApplicable(tile)) {
this.applyTo((T) tile);
tile.setChanged();
}
this.getWorldHandle().getBlockEntity(this.getPosition(), this.blockEntity.getType()).ifPresent(blockEntity -> {
this.applyTo((T) blockEntity);
blockEntity.setChanged();
});
}
return result;
}
@Override
public boolean place(int flags) {
if (super.place(flags)) {
this.getWorldHandle().getBlockEntity(this.getPosition(), this.blockEntity.getType()).ifPresent(blockEntity -> {
this.applyTo((T) blockEntity);
blockEntity.setChanged();
});
return true;
}
return false;
}
@Override
public PersistentDataContainer getPersistentDataContainer() {
return this.getSnapshot().persistentDataContainer;

View File

@@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
@@ -27,26 +28,27 @@ public class CraftBlockState implements BlockState {
protected final CraftWorld world;
private final BlockPos position;
protected net.minecraft.world.level.block.state.BlockState data;
protected int flag;
protected int capturedFlags; // todo move out of this class
private WeakReference<LevelAccessor> weakWorld;
protected CraftBlockState(final Block block) {
this(block.getWorld(), ((CraftBlock) block).getPosition(), ((CraftBlock) block).getNMS());
this.flag = 3;
this.capturedFlags = net.minecraft.world.level.block.Block.UPDATE_ALL;
this.setWorldHandle(((CraftBlock) block).getHandle());
}
protected CraftBlockState(final Block block, int flag) {
@Deprecated
protected CraftBlockState(final Block block, int capturedFlags) {
this(block);
this.flag = flag;
this.capturedFlags = capturedFlags;
}
// world can be null for non-placed BlockStates.
protected CraftBlockState(@Nullable World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData) {
protected CraftBlockState(@Nullable World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState data) {
this.world = (CraftWorld) world;
this.position = blockPosition;
this.data = blockData;
this.position = pos;
this.data = data;
}
// Creates an unplaced copy of the given CraftBlockState at the given location
@@ -59,7 +61,7 @@ public class CraftBlockState implements BlockState {
this.position = CraftLocation.toBlockPosition(location);
}
this.data = state.data;
this.flag = state.flag;
this.capturedFlags = state.capturedFlags;
this.setWorldHandle(state.getWorldHandle());
}
@@ -178,12 +180,12 @@ public class CraftBlockState implements BlockState {
return this.data.getBukkitMaterial(); // Paper - optimise getType calls
}
public void setFlag(int flag) {
this.flag = flag;
public void setFlags(int flags) {
this.capturedFlags = flags;
}
public int getFlag() {
return this.flag;
public int getFlags() {
return this.capturedFlags;
}
@Override
@@ -222,13 +224,13 @@ public class CraftBlockState implements BlockState {
}
net.minecraft.world.level.block.state.BlockState newBlock = this.data;
block.setTypeAndData(newBlock, applyPhysics);
block.setBlockState(newBlock, applyPhysics);
if (access instanceof net.minecraft.world.level.Level) {
this.world.getHandle().sendBlockUpdated(
this.position,
block.getNMS(),
newBlock,
3
this.position,
block.getNMS(),
newBlock,
net.minecraft.world.level.block.Block.UPDATE_ALL
);
}
@@ -240,6 +242,26 @@ public class CraftBlockState implements BlockState {
return true;
}
// used when the flags matter for non API usage
public boolean place(int flags) {
if (!this.isPlaced()) {
return false;
}
return this.getWorldHandle().setBlock(this.position, this.data, flags);
}
// used to revert a block placement due to an event being cancelled for example
public boolean revertPlace() {
return this.place(
net.minecraft.world.level.block.Block.UPDATE_CLIENTS |
net.minecraft.world.level.block.Block.UPDATE_KNOWN_SHAPE |
net.minecraft.world.level.block.Block.UPDATE_SUPPRESS_DROPS |
net.minecraft.world.level.block.Block.UPDATE_SKIP_ON_PLACE |
net.minecraft.world.level.block.Block.UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS
);
}
@Override
public byte getRawData() {
return CraftMagicNumbers.toLegacyData(this.data);
@@ -278,16 +300,9 @@ public class CraftBlockState implements BlockState {
return false;
}
final CraftBlockState other = (CraftBlockState) obj;
if (this.world != other.world && (this.world == null || !this.world.equals(other.world))) {
return false;
}
if (this.position != other.position && (this.position == null || !this.position.equals(other.position))) {
return false;
}
if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
return false;
}
return true;
return Objects.equals(this.world, other.world) &&
Objects.equals(this.position, other.position) &&
Objects.equals(this.data, other.data);
}
@Override
@@ -353,13 +368,13 @@ public class CraftBlockState implements BlockState {
this.requirePlaced();
net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item);
// Modelled off EntityHuman#hasBlock
if (item == null || !data.requiresCorrectToolForDrops() || nms.isCorrectToolForDrops(data)) {
// Modelled off Player#hasCorrectToolForDrops
if (item == null || !data.requiresCorrectToolForDrops() || nms.isCorrectToolForDrops(this.data)) {
return net.minecraft.world.level.block.Block.getDrops(
data,
world.getHandle(),
position,
world.getHandle().getBlockEntity(position), entity == null ? null :
this.data,
this.world.getHandle(),
this.position,
this.world.getHandle().getBlockEntity(this.position), entity == null ? null :
((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle(), nms
).stream().map(org.bukkit.craftbukkit.inventory.CraftItemStack::asBukkitCopy).toList();
} else {

View File

@@ -1,70 +1,22 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.entity.BannerBlockEntity;
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.world.level.block.entity.BedBlockEntity;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import net.minecraft.world.level.block.entity.BellBlockEntity;
import net.minecraft.world.level.block.entity.BlastFurnaceBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; // Paper
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
import net.minecraft.world.level.block.entity.BrushableBlockEntity;
import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity;
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
import net.minecraft.world.level.block.entity.CommandBlockEntity;
import net.minecraft.world.level.block.entity.ComparatorBlockEntity;
import net.minecraft.world.level.block.entity.ConduitBlockEntity;
import net.minecraft.world.level.block.entity.CrafterBlockEntity;
import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity;
import net.minecraft.world.level.block.entity.DaylightDetectorBlockEntity;
import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity;
import net.minecraft.world.level.block.entity.DispenserBlockEntity;
import net.minecraft.world.level.block.entity.DropperBlockEntity;
import net.minecraft.world.level.block.entity.EnchantingTableBlockEntity;
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
import net.minecraft.world.level.block.entity.HangingSignBlockEntity;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.entity.JigsawBlockEntity;
import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
import net.minecraft.world.level.block.entity.LecternBlockEntity;
import net.minecraft.world.level.block.entity.SculkCatalystBlockEntity;
import net.minecraft.world.level.block.entity.SculkSensorBlockEntity;
import net.minecraft.world.level.block.entity.SculkShriekerBlockEntity;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.level.block.entity.SmokerBlockEntity;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.entity.StructureBlockEntity;
import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
import net.minecraft.world.level.block.entity.TheEndPortalBlockEntity;
import net.minecraft.world.level.block.entity.TrappedChestBlockEntity;
import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
import net.minecraft.world.level.block.entity.vault.VaultBlockEntity;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftWorld;
public final class CraftBlockStates {
@@ -78,108 +30,110 @@ public final class CraftBlockStates {
}
// The given world can be null for unplaced BlockStates.
// If the world is not null and the given block data is a tile entity, the given tile entity is expected to not be null.
// Otherwise, the given tile entity may or may not be null.
// If the given tile 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 tile entity's world may be null, even if the given world is not null.
// If the tile entity's world is not null, it is expected to match the given world.
public abstract B createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity);
// If the world is not null and the given block data is a block entity, the given block entity is expected to not be null.
// Otherwise, the given block entity may or may not be null.
// 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);
}
private static class BlockEntityStateFactory<T extends BlockEntity, B extends CraftBlockEntityState<T>> extends BlockStateFactory<B> {
private final BiFunction<World, T, B> blockStateConstructor;
private final BlockEntityType<? extends T> tileEntityConstructor; // Paper
private final BlockEntityType<? extends T> blockEntityType;
protected BlockEntityStateFactory(Class<B> blockStateType, BiFunction<World, T, B> blockStateConstructor, BlockEntityType<? extends T> tileEntityConstructor) { // Paper
protected BlockEntityStateFactory(Class<B> blockStateType, BiFunction<World, T, B> blockStateConstructor, BlockEntityType<? extends T> blockEntityType) {
super(blockStateType);
this.blockStateConstructor = blockStateConstructor;
this.tileEntityConstructor = tileEntityConstructor;
this.blockEntityType = blockEntityType;
}
@Override
public final B createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
public final B createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) {
if (world != null) {
Preconditions.checkState(tileEntity != null, "Tile is null, asynchronous access? %s", CraftBlock.at(((CraftWorld) world).getHandle(), blockPosition));
} else if (tileEntity == null) {
tileEntity = this.createTileEntity(blockPosition, blockData);
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) tileEntity);
return this.createBlockState(world, (T) blockEntity);
}
private T createTileEntity(BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData) {
return this.tileEntityConstructor.create(blockPosition, blockData); // Paper
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 tileEntity) {
return this.blockStateConstructor.apply(world, tileEntity);
private B createBlockState(World world, T blockEntity) {
return this.blockStateConstructor.apply(world, blockEntity);
}
}
private static final Map<Material, BlockStateFactory<?>> FACTORIES = new HashMap<>();
private static final BlockStateFactory<?> DEFAULT_FACTORY = new BlockStateFactory<CraftBlockState>(CraftBlockState.class) {
private static final BlockStateFactory<?> DEFAULT_FACTORY = new BlockStateFactory<>(CraftBlockState.class) {
@Override
public CraftBlockState createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
public CraftBlockState createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) {
// 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(tileEntity == null, "Unexpected BlockState for %s", CraftBlockType.minecraftToBukkit(blockData.getBlock()));
return new CraftBlockState(world, blockPosition, blockData);
Preconditions.checkState(blockEntity == null, "Unexpected BlockState for %s", CraftBlockType.minecraftToBukkit(state.getBlock()));
return new CraftBlockState(world, pos, state);
}
};
// Paper start
private static final Map<BlockEntityType<?>, BlockStateFactory<?>> FACTORIES_BY_BLOCK_ENTITY_TYPE = new HashMap<>();
private static void register(BlockEntityType<?> type, BlockStateFactory<?> factory) {
FACTORIES_BY_BLOCK_ENTITY_TYPE.put(type, factory);
}
// Paper end
static {
// Paper start - simplify
register(BlockEntityType.SIGN, CraftSign.class, CraftSign::new);
register(BlockEntityType.HANGING_SIGN, CraftHangingSign.class, CraftHangingSign::new);
register(BlockEntityType.SKULL, CraftSkull.class, CraftSkull::new);
register(BlockEntityType.COMMAND_BLOCK, CraftCommandBlock.class, CraftCommandBlock::new);
// Start generate - CraftBlockEntityStates
// @GeneratedFrom 1.21.5
register(BlockEntityType.BANNER, CraftBanner.class, CraftBanner::new);
register(BlockEntityType.SHULKER_BOX, CraftShulkerBox.class, CraftShulkerBox::new);
register(BlockEntityType.BED, CraftBed.class, CraftBed::new);
register(BlockEntityType.BEEHIVE, CraftBeehive.class, CraftBeehive::new);
register(BlockEntityType.CAMPFIRE, CraftCampfire.class, CraftCampfire::new);
register(BlockEntityType.BARREL, CraftBarrel.class, CraftBarrel::new);
register(BlockEntityType.BEACON, CraftBeacon.class, CraftBeacon::new);
register(BlockEntityType.BED, CraftBed.class, CraftBed::new);
register(BlockEntityType.BEEHIVE, CraftBeehive.class, CraftBeehive::new);
register(BlockEntityType.BELL, CraftBell.class, CraftBell::new);
register(BlockEntityType.BLAST_FURNACE, CraftBlastFurnace.class, CraftBlastFurnace::new);
register(BlockEntityType.BREWING_STAND, CraftBrewingStand.class, CraftBrewingStand::new);
register(BlockEntityType.BRUSHABLE_BLOCK, CraftBrushableBlock.class, CraftBrushableBlock::new);
register(BlockEntityType.CALIBRATED_SCULK_SENSOR, CraftCalibratedSculkSensor.class, CraftCalibratedSculkSensor::new);
register(BlockEntityType.CAMPFIRE, CraftCampfire.class, CraftCampfire::new);
register(BlockEntityType.CHEST, CraftChest.class, CraftChest::new);
register(BlockEntityType.CHISELED_BOOKSHELF, CraftChiseledBookshelf.class, CraftChiseledBookshelf::new);
register(BlockEntityType.COMMAND_BLOCK, CraftCommandBlock.class, CraftCommandBlock::new);
register(BlockEntityType.COMPARATOR, CraftComparator.class, CraftComparator::new);
register(BlockEntityType.CONDUIT, CraftConduit.class, CraftConduit::new);
register(BlockEntityType.CRAFTER, CraftCrafter.class, CraftCrafter::new);
register(BlockEntityType.CREAKING_HEART, CraftCreakingHeart.class, CraftCreakingHeart::new);
register(BlockEntityType.DAYLIGHT_DETECTOR, CraftDaylightDetector.class, CraftDaylightDetector::new);
register(BlockEntityType.DECORATED_POT, CraftDecoratedPot.class, CraftDecoratedPot::new);
register(BlockEntityType.DISPENSER, CraftDispenser.class, CraftDispenser::new);
register(BlockEntityType.DROPPER, CraftDropper.class, CraftDropper::new);
register(BlockEntityType.ENCHANTING_TABLE, CraftEnchantingTable.class, CraftEnchantingTable::new);
register(BlockEntityType.ENDER_CHEST, CraftEnderChest.class, CraftEnderChest::new);
register(BlockEntityType.END_GATEWAY, CraftEndGateway.class, CraftEndGateway::new);
register(BlockEntityType.END_PORTAL, CraftEndPortal.class, CraftEndPortal::new);
register(BlockEntityType.ENDER_CHEST, CraftEnderChest.class, CraftEnderChest::new);
register(BlockEntityType.FURNACE, CraftFurnaceFurnace.class, CraftFurnaceFurnace::new);
register(BlockEntityType.HANGING_SIGN, CraftHangingSign.class, CraftHangingSign::new);
register(BlockEntityType.HOPPER, CraftHopper.class, CraftHopper::new);
register(BlockEntityType.JIGSAW, CraftJigsaw.class, CraftJigsaw::new);
register(BlockEntityType.JUKEBOX, CraftJukebox.class, CraftJukebox::new);
register(BlockEntityType.LECTERN, CraftLectern.class, CraftLectern::new);
register(BlockEntityType.MOB_SPAWNER, CraftCreatureSpawner.class, CraftCreatureSpawner::new);
register(BlockEntityType.PISTON, CraftMovingPiston.class, CraftMovingPiston::new);
register(BlockEntityType.SCULK_CATALYST, CraftSculkCatalyst.class, CraftSculkCatalyst::new);
register(BlockEntityType.SCULK_SENSOR, CraftSculkSensor.class, CraftSculkSensor::new);
register(BlockEntityType.SCULK_SHRIEKER, CraftSculkShrieker.class, CraftSculkShrieker::new);
register(BlockEntityType.CALIBRATED_SCULK_SENSOR, CraftCalibratedSculkSensor.class, CraftCalibratedSculkSensor::new);
register(BlockEntityType.SHULKER_BOX, CraftShulkerBox.class, CraftShulkerBox::new);
register(BlockEntityType.SIGN, CraftSign.class, CraftSign::new);
register(BlockEntityType.SKULL, CraftSkull.class, CraftSkull::new);
register(BlockEntityType.SMOKER, CraftSmoker.class, CraftSmoker::new);
register(BlockEntityType.MOB_SPAWNER, CraftCreatureSpawner.class, CraftCreatureSpawner::new);
register(BlockEntityType.STRUCTURE_BLOCK, CraftStructureBlock.class, CraftStructureBlock::new);
register(BlockEntityType.BRUSHABLE_BLOCK, CraftBrushableBlock.class, CraftBrushableBlock::new); // note: spigot still uses CraftSuspiciousSand impl for that block type
register(BlockEntityType.TEST_BLOCK, CraftTestBlock.class, CraftTestBlock::new);
register(BlockEntityType.TEST_INSTANCE_BLOCK, CraftTestInstanceBlock.class, CraftTestInstanceBlock::new);
register(BlockEntityType.TRAPPED_CHEST, CraftChest.class, CraftChest::new);
register(BlockEntityType.CRAFTER, CraftCrafter.class, CraftCrafter::new);
register(BlockEntityType.TRIAL_SPAWNER, CraftTrialSpawner.class, CraftTrialSpawner::new);
register(BlockEntityType.VAULT, CraftVault.class, CraftVault::new);
// Paper end
// End generate - CraftBlockEntityStates
}
private static void register(Material blockType, BlockStateFactory<?> factory) {
@@ -187,24 +141,21 @@ public final class CraftBlockStates {
}
private static <T extends BlockEntity, B extends CraftBlockEntityState<T>> void register(
net.minecraft.world.level.block.entity.BlockEntityType<? extends T> blockEntityType, // Paper
net.minecraft.world.level.block.entity.BlockEntityType<? extends T> blockEntityType,
Class<B> blockStateType,
BiFunction<World, T, B> blockStateConstructor // Paper
BiFunction<World, T, B> blockStateConstructor
) {
// Paper start
BlockStateFactory<B> factory = new BlockEntityStateFactory<>(blockStateType, blockStateConstructor, blockEntityType); // Paper
BlockStateFactory<B> factory = new BlockEntityStateFactory<>(blockStateType, blockStateConstructor, blockEntityType);
for (net.minecraft.world.level.block.Block block : blockEntityType.validBlocks) {
CraftBlockStates.register(CraftBlockType.minecraftToBukkit(block), factory);
}
CraftBlockStates.register(blockEntityType, factory);
// Paper end
}
private static BlockStateFactory<?> getFactory(Material material) {
return CraftBlockStates.FACTORIES.getOrDefault(material, CraftBlockStates.DEFAULT_FACTORY);
}
// Paper start
private static BlockStateFactory<?> getFactory(Material material, BlockEntityType<?> type) {
if (type != null) {
return CraftBlockStates.FACTORIES_BY_BLOCK_ENTITY_TYPE.getOrDefault(type, getFactory(material));
@@ -212,123 +163,108 @@ public final class CraftBlockStates {
return getFactory(material);
}
}
// Paper end
public static Class<? extends CraftBlockState> getBlockStateType(Material material) {
Preconditions.checkNotNull(material, "material is null");
return CraftBlockStates.getFactory(material).blockStateType;
}
public static BlockEntity createNewTileEntity(Material material) {
public static BlockEntity createNewBlockEntity(Material material) {
BlockStateFactory<?> factory = CraftBlockStates.getFactory(material);
if (factory instanceof BlockEntityStateFactory) {
return ((BlockEntityStateFactory<?, ?>) factory).createTileEntity(BlockPos.ZERO, CraftBlockType.bukkitToMinecraft(material).defaultBlockState());
return ((BlockEntityStateFactory<?, ?>) factory).createBlockEntity(BlockPos.ZERO, CraftBlockType.bukkitToMinecraft(material).defaultBlockState());
}
return null;
}
// Paper start
public static Class<? extends CraftBlockState> getBlockStateType(BlockEntityType<?> blockEntityType) {
Preconditions.checkNotNull(blockEntityType, "blockEntityType is null");
return CraftBlockStates.getFactory(null, blockEntityType).blockStateType;
}
// Paper end
public static BlockState getBlockState(Block block) {
// Paper start
return CraftBlockStates.getBlockState(block, true);
}
public static BlockState getBlockState(Block block, boolean useSnapshot) {
// Paper end
Preconditions.checkNotNull(block, "block is null");
CraftBlock craftBlock = (CraftBlock) block;
CraftWorld world = (CraftWorld) block.getWorld();
BlockPos blockPosition = craftBlock.getPosition();
net.minecraft.world.level.block.state.BlockState blockData = craftBlock.getNMS();
BlockEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition);
// Paper start - block state snapshots
BlockPos pos = craftBlock.getPosition();
net.minecraft.world.level.block.state.BlockState state = craftBlock.getNMS();
BlockEntity blockEntity = craftBlock.getHandle().getBlockEntity(pos);
boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
try {
// Paper end
CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
return blockState;
// Paper start
CraftBlockState blockState = CraftBlockStates.getBlockState(world, pos, state, blockEntity);
blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
return blockState;
} finally {
CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
}
// Paper end
}
@Deprecated
public static BlockState getBlockState(BlockPos blockPosition, Material material, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(MinecraftServer.getDefaultRegistryAccess(), blockPosition, material, blockEntityTag);
public static BlockState getBlockState(BlockPos pos, Material material, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), pos, material, blockEntityTag);
}
public static BlockState getBlockState(LevelReader world, BlockPos blockPosition, Material material, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(world.registryAccess(), blockPosition, material, blockEntityTag);
public static BlockState getBlockState(LevelReader world, BlockPos pos, Material material, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(world.registryAccess(), pos, material, blockEntityTag);
}
public static BlockState getBlockState(RegistryAccess registry, BlockPos blockPosition, Material material, @Nullable CompoundTag blockEntityTag) {
public static BlockState getBlockState(RegistryAccess registry, BlockPos pos, Material material, @Nullable CompoundTag blockEntityTag) {
Preconditions.checkNotNull(material, "material is null");
net.minecraft.world.level.block.state.BlockState blockData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState();
return CraftBlockStates.getBlockState(registry, blockPosition, blockData, blockEntityTag);
return CraftBlockStates.getBlockState(registry, pos, blockData, blockEntityTag);
}
@Deprecated
public static BlockState getBlockState(net.minecraft.world.level.block.state.BlockState blockData, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(MinecraftServer.getDefaultRegistryAccess(), BlockPos.ZERO, blockData, blockEntityTag);
public static BlockState getBlockState(net.minecraft.world.level.block.state.BlockState state, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, state, blockEntityTag);
}
public static BlockState getBlockState(LevelReader world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(world.registryAccess(), blockPosition, blockData, blockEntityTag);
public static BlockState getBlockState(LevelReader level, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState state, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(level.registryAccess(), blockPosition, state, blockEntityTag);
}
public static BlockState getBlockState(RegistryAccess registry, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, @Nullable CompoundTag blockEntityTag) {
Preconditions.checkNotNull(blockPosition, "blockPosition is null");
Preconditions.checkNotNull(blockData, "blockData is null");
BlockEntity tileEntity = (blockEntityTag == null) ? null : BlockEntity.loadStatic(blockPosition, blockData, blockEntityTag, registry);
return CraftBlockStates.getBlockState(null, blockPosition, blockData, tileEntity);
public static BlockState getBlockState(RegistryAccess registry, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable CompoundTag blockEntityTag) {
Preconditions.checkNotNull(pos, "pos is null");
Preconditions.checkNotNull(state, "state is null");
BlockEntity blockEntity = (blockEntityTag == null) ? null : BlockEntity.loadStatic(pos, state, blockEntityTag, registry); // todo create block entity from the state
return CraftBlockStates.getBlockState(null, pos, state, blockEntity);
}
// See BlockStateFactory#createBlockState(World, BlockPosition, IBlockData, TileEntity)
public static CraftBlockState getBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
Material material = CraftBlockType.minecraftToBukkit(blockData.getBlock());
// See BlockStateFactory#createBlockState(World, BlockPos, BlockState, BlockEntity)
public static CraftBlockState getBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) {
Material material = CraftBlockType.minecraftToBukkit(state.getBlock());
BlockStateFactory<?> factory;
// For some types of TileEntity blocks (eg. moving pistons), Minecraft may in some situations (eg. when using Block#setType or the
// setBlock command) not create a corresponding TileEntity in the world. We return a normal BlockState in this case.
if (world != null && tileEntity == null && CraftBlockStates.isTileEntityOptional(material)) {
// For some types of BlockEntity blocks (e.g. moving pistons), Minecraft may in some situations (e.g. when using Block#setType or the
// setBlock command) not create a corresponding BlockEntity in the world. We return a normal BlockState in this case.
if (world != null && blockEntity == null && CraftBlockStates.isBlockEntityOptional(material)) {
factory = CraftBlockStates.DEFAULT_FACTORY;
} else {
factory = CraftBlockStates.getFactory(material, tileEntity != null ? tileEntity.getType() : null); // Paper
factory = CraftBlockStates.getFactory(material, blockEntity != null ? blockEntity.getType() : null); // Paper
}
return factory.createBlockState(world, blockPosition, blockData, tileEntity);
return factory.createBlockState(world, pos, state, blockEntity);
}
public static boolean isTileEntityOptional(Material material) {
public static boolean isBlockEntityOptional(Material material) {
return material == Material.MOVING_PISTON;
}
// This ignores tile entity data.
// This ignores block entity data.
public static CraftBlockState getBlockState(LevelAccessor world, BlockPos pos) {
return new CraftBlockState(CraftBlock.at(world, pos));
}
// This ignores tile entity data.
public static CraftBlockState getBlockState(LevelAccessor world, BlockPos pos, int flag) {
return new CraftBlockState(CraftBlock.at(world, pos), flag);
}
// Paper start
@Nullable
public static BlockEntityType<?> getBlockEntityType(final Material material) {
final BlockStateFactory<?> factory = org.bukkit.craftbukkit.block.CraftBlockStates.FACTORIES.get(material);
return factory instanceof final BlockEntityStateFactory<?,?> blockEntityStateFactory ? blockEntityStateFactory.tileEntityConstructor : null;
return factory instanceof final BlockEntityStateFactory<?,?> blockEntityStateFactory ? blockEntityStateFactory.blockEntityType : null;
}
// Paper end
private CraftBlockStates() {
}

View File

@@ -1,12 +1,16 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import io.papermc.paper.registry.HolderableBase;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableList;
import java.util.function.Supplier;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
@@ -21,7 +25,6 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.World;
import org.bukkit.block.BlockType;
@@ -31,16 +34,14 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>, Handleable<Block>, io.papermc.paper.world.flag.PaperFeatureDependent { // Paper - feature flag API
@NullMarked
public class CraftBlockType<B extends @NonNull BlockData> extends HolderableBase<Block> implements BlockType.Typed<B>, io.papermc.paper.world.flag.PaperFeatureDependent<Block> { // Paper - feature flag API
private final NamespacedKey key;
private final Block block;
private final Class<B> blockDataClass;
private final boolean interactable;
public static Material minecraftToBukkit(Block block) {
return CraftMagicNumbers.getMaterial(block);
@@ -92,30 +93,26 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
return hasMethod;
}
public CraftBlockType(NamespacedKey key, Block block) {
this.key = key;
this.block = block;
this.blockDataClass = (Class<B>) CraftBlockData.fromData(block.defaultBlockState()).getClass().getInterfaces()[0];
this.interactable = CraftBlockType.isInteractable(block);
private final Supplier<Class<B>> blockDataClass;
private final Supplier<Boolean> interactable;
@SuppressWarnings("unchecked")
public CraftBlockType(final Holder<Block> holder) {
super(holder);
this.blockDataClass = Suppliers.memoize(() -> (Class<B>) CraftBlockData.fromData(this.getHandle().defaultBlockState()).getClass().getInterfaces()[0]);
this.interactable = Suppliers.memoize(() -> CraftBlockType.isInteractable(this.getHandle()));
}
@Override
public Block getHandle() {
return this.block;
}
@NotNull
@Override
public Typed<BlockData> typed() {
return this.typed(BlockData.class);
}
@NotNull
@Override
@SuppressWarnings("unchecked")
public <Other extends BlockData> Typed<Other> typed(@NotNull Class<Other> blockDataType) {
if (blockDataType.isAssignableFrom(this.blockDataClass)) return (Typed<Other>) this;
throw new IllegalArgumentException("Cannot type block type " + this.key.toString() + " to blockdata type " + blockDataType.getSimpleName());
public <Other extends BlockData> Typed<Other> typed(final Class<Other> blockDataType) {
if (blockDataType.isAssignableFrom(this.blockDataClass.get())) return (Typed<Other>) this;
throw new IllegalArgumentException("Cannot type block type " + this + " to blockdata type " + blockDataType.getSimpleName());
}
@Override
@@ -124,24 +121,23 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
return true;
}
return this.block.asItem() != Items.AIR;
return this.getHandle().asItem() != Items.AIR;
}
@NotNull
@Override
public ItemType getItemType() {
if (this == AIR) {
return ItemType.AIR;
}
Item item = this.block.asItem();
Item item = this.getHandle().asItem();
Preconditions.checkArgument(item != Items.AIR, "The block type %s has no corresponding item type", this.getKey());
return CraftItemType.minecraftToBukkitNew(item);
}
@Override
public Class<B> getBlockDataClass() {
return this.blockDataClass;
return this.blockDataClass.get();
}
@Override
@@ -150,17 +146,17 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
}
@Override
public @NotNull Collection<B> createBlockDataStates() {
final ImmutableList<BlockState> possibleStates = this.block.getStateDefinition().getPossibleStates();
public Collection<B> createBlockDataStates() {
final ImmutableList<BlockState> possibleStates = this.getHandle().getStateDefinition().getPossibleStates();
final ImmutableList.Builder<B> builder = ImmutableList.builderWithExpectedSize(possibleStates.size());
for (final BlockState possibleState : possibleStates) {
builder.add(this.blockDataClass.cast(possibleState.createCraftBlockData()));
builder.add(this.blockDataClass.get().cast(possibleState.createCraftBlockData()));
}
return builder.build();
}
@Override
public B createBlockData(Consumer<? super B> consumer) {
public B createBlockData(final @Nullable Consumer<? super B> consumer) {
B data = this.createBlockData();
if (consumer != null) {
@@ -170,94 +166,89 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
return data;
}
@SuppressWarnings("unchecked")
@Override
public B createBlockData(String data) {
public B createBlockData(final @Nullable String data) {
return (B) CraftBlockData.newData(this, data);
}
@Override
public boolean isSolid() {
return this.block.defaultBlockState().blocksMotion();
return this.getHandle().defaultBlockState().blocksMotion();
}
@Override
public boolean isAir() {
return this.block.defaultBlockState().isAir();
return this.getHandle().defaultBlockState().isAir();
}
@Override
public boolean isEnabledByFeature(@NotNull World world) {
public boolean isEnabledByFeature(final World world) {
Preconditions.checkNotNull(world, "World cannot be null");
return this.getHandle().isEnabled(((CraftWorld) world).getHandle().enabledFeatures());
}
@Override
public boolean isFlammable() {
return this.block.defaultBlockState().ignitedByLava();
return this.getHandle().defaultBlockState().ignitedByLava();
}
@Override
public boolean isBurnable() {
return ((FireBlock) Blocks.FIRE).igniteOdds.getOrDefault(this.block, 0) > 0;
return ((FireBlock) Blocks.FIRE).igniteOdds.getOrDefault(this.getHandle(), 0) > 0;
}
@Override
public boolean isOccluding() {
return this.block.defaultBlockState().isRedstoneConductor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
return this.getHandle().defaultBlockState().isRedstoneConductor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
}
@Override
public boolean hasGravity() {
return this.block instanceof Fallable;
return this.getHandle() instanceof Fallable;
}
@Override
public boolean isInteractable() {
return this.interactable;
return this.interactable.get();
}
@Override
public float getHardness() {
return this.block.defaultBlockState().destroySpeed;
return this.getHandle().defaultBlockState().destroySpeed;
}
@Override
public float getBlastResistance() {
return this.block.getExplosionResistance();
return this.getHandle().getExplosionResistance();
}
@Override
public float getSlipperiness() {
return this.block.getFriction();
return this.getHandle().getFriction();
}
@NotNull
@Override
public String getTranslationKey() {
return this.block.getDescriptionId();
return this.getHandle().getDescriptionId();
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public Material asMaterial() {
return Registry.MATERIAL.get(this.key);
public @Nullable Material asMaterial() {
return Registry.MATERIAL.get(this.getKey());
}
// Paper start - add Translatable
@Override
public String translationKey() {
return this.block.getDescriptionId();
return this.getHandle().getDescriptionId();
}
// Paper end - add Translatable
// Paper start - hasCollision API
@Override
public boolean hasCollision() {
return this.block.hasCollision;
return this.getHandle().hasCollision;
}
// Paper end - hasCollision API
}

View File

@@ -9,8 +9,8 @@ import org.bukkit.inventory.BrewerInventory;
public class CraftBrewingStand extends CraftContainer<BrewingStandBlockEntity> implements BrewingStand {
public CraftBrewingStand(World world, BrewingStandBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBrewingStand(World world, BrewingStandBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBrewingStand(CraftBrewingStand state, Location location) {
@@ -28,7 +28,7 @@ public class CraftBrewingStand extends CraftContainer<BrewingStandBlockEntity> i
return this.getSnapshotInventory();
}
return new CraftInventoryBrewer(this.getTileEntity());
return new CraftInventoryBrewer(this.getBlockEntity());
}
@Override

View File

@@ -11,8 +11,8 @@ import org.bukkit.loot.LootTable;
public class CraftBrushableBlock extends CraftBlockEntityState<BrushableBlockEntity> implements BrushableBlock {
public CraftBrushableBlock(World world, BrushableBlockEntity tileEntity) {
super(world, tileEntity);
public CraftBrushableBlock(World world, BrushableBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftBrushableBlock(CraftBrushableBlock state, Location location) {
@@ -30,11 +30,11 @@ public class CraftBrushableBlock extends CraftBlockEntityState<BrushableBlockEnt
}
@Override
public void applyTo(BrushableBlockEntity lootable) {
super.applyTo(lootable);
public void applyTo(BrushableBlockEntity blockEntity) {
super.applyTo(blockEntity);
if (this.getSnapshot().lootTable == null) {
lootable.setLootTable(null, 0L);
blockEntity.setLootTable(null, 0L);
}
}

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.CalibratedSculkSensor;
public class CraftCalibratedSculkSensor extends CraftSculkSensor<CalibratedSculkSensorBlockEntity> implements CalibratedSculkSensor {
public CraftCalibratedSculkSensor(World world, CalibratedSculkSensorBlockEntity tileEntity) {
super(world, tileEntity);
public CraftCalibratedSculkSensor(World world, CalibratedSculkSensorBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftCalibratedSculkSensor(CraftCalibratedSculkSensor state, Location location) {

View File

@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
@@ -9,8 +10,8 @@ import org.bukkit.inventory.ItemStack;
public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> implements Campfire {
public CraftCampfire(World world, CampfireBlockEntity tileEntity) {
super(world, tileEntity);
public CraftCampfire(World world, CampfireBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftCampfire(CraftCampfire state, Location location) {
@@ -63,39 +64,37 @@ public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> im
return new CraftCampfire(this, location);
}
// Paper start
@Override
public void stopCooking() {
for (int i = 0; i < getSnapshot().stopCooking.length; ++i)
for (int i = 0; i < this.getSnapshot().stopCooking.length; ++i)
this.stopCooking(i);
}
@Override
public void startCooking() {
for (int i = 0; i < getSnapshot().stopCooking.length; ++i)
for (int i = 0; i < this.getSnapshot().stopCooking.length; ++i)
this.startCooking(i);
}
@Override
public boolean stopCooking(int index) {
org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
Preconditions.checkArgument(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
boolean previous = this.isCookingDisabled(index);
getSnapshot().stopCooking[index] = true;
this.getSnapshot().stopCooking[index] = true;
return previous;
}
@Override
public boolean startCooking(int index) {
org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
Preconditions.checkArgument(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
boolean previous = this.isCookingDisabled(index);
getSnapshot().stopCooking[index] = false;
this.getSnapshot().stopCooking[index] = false;
return previous;
}
@Override
public boolean isCookingDisabled(int index) {
org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
return getSnapshot().stopCooking[index];
Preconditions.checkArgument(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
return this.getSnapshot().stopCooking[index];
}
// Paper end
}

View File

@@ -16,8 +16,8 @@ import org.bukkit.inventory.Inventory;
public class CraftChest extends CraftLootable<ChestBlockEntity> implements Chest {
public CraftChest(World world, ChestBlockEntity tileEntity) {
super(world, tileEntity);
public CraftChest(World world, ChestBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftChest(CraftChest state, Location location) {
@@ -35,7 +35,7 @@ public class CraftChest extends CraftLootable<ChestBlockEntity> implements Chest
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override
@@ -60,27 +60,27 @@ public class CraftChest extends CraftLootable<ChestBlockEntity> implements Chest
@Override
public void open() {
this.requirePlaced();
if (!this.getTileEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getTileEntity().getBlockState();
int openCount = this.getTileEntity().openersCounter.getOpenerCount();
if (!this.getBlockEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getBlockEntity().getBlockState();
int openCount = this.getBlockEntity().openersCounter.getOpenerCount();
this.getTileEntity().openersCounter.onAPIOpen((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, openCount + 1);
this.getBlockEntity().openersCounter.onAPIOpen((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getBlockEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, openCount + 1);
}
this.getTileEntity().openersCounter.opened = true;
this.getBlockEntity().openersCounter.opened = true;
}
@Override
public void close() {
this.requirePlaced();
if (this.getTileEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getTileEntity().getBlockState();
int openCount = this.getTileEntity().openersCounter.getOpenerCount();
if (this.getBlockEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getBlockEntity().getBlockState();
int openCount = this.getBlockEntity().openersCounter.getOpenerCount();
this.getTileEntity().openersCounter.onAPIClose((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, 0);
this.getBlockEntity().openersCounter.onAPIClose((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getBlockEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, 0);
}
this.getTileEntity().openersCounter.opened = false;
this.getBlockEntity().openersCounter.opened = false;
}
@Override
@@ -96,7 +96,7 @@ public class CraftChest extends CraftLootable<ChestBlockEntity> implements Chest
// Paper start - More Lidded Block API
@Override
public boolean isOpen() {
return getTileEntity().openersCounter.opened;
return getBlockEntity().openersCounter.opened;
}
// Paper end - More Lidded Block API

View File

@@ -14,8 +14,8 @@ import org.bukkit.util.Vector;
public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookShelfBlockEntity> implements ChiseledBookshelf {
public CraftChiseledBookshelf(World world, ChiseledBookShelfBlockEntity tileEntity) {
super(world, tileEntity);
public CraftChiseledBookshelf(World world, ChiseledBookShelfBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftChiseledBookshelf(CraftChiseledBookshelf state, Location location) {
@@ -43,7 +43,7 @@ public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookSh
return this.getSnapshotInventory();
}
return new CraftInventoryChiseledBookshelf(this.getTileEntity());
return new CraftInventoryChiseledBookshelf(this.getBlockEntity());
}
@Override

View File

@@ -8,8 +8,8 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity> implements CommandBlock, io.papermc.paper.commands.PaperCommandBlockHolder {
public CraftCommandBlock(World world, CommandBlockEntity tileEntity) {
super(world, tileEntity);
public CraftCommandBlock(World world, CommandBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftCommandBlock(CraftCommandBlock state, Location location) {
@@ -46,20 +46,18 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
return new CraftCommandBlock(this, location);
}
// Paper start
@Override
public net.kyori.adventure.text.Component name() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getSnapshot().getCommandBlock().getName());
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getSnapshot().getCommandBlock().getName());
}
@Override
public void name(net.kyori.adventure.text.Component name) {
getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
this.getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
}
@Override
public net.minecraft.world.level.BaseCommandBlock getCommandBlockHandle() {
return getSnapshot().getCommandBlock();
return this.getSnapshot().getCommandBlock();
}
// Paper end
}

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.Comparator;
public class CraftComparator extends CraftBlockEntityState<ComparatorBlockEntity> implements Comparator {
public CraftComparator(World world, ComparatorBlockEntity tileEntity) {
super(world, tileEntity);
public CraftComparator(World world, ComparatorBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftComparator(CraftComparator state, Location location) {

View File

@@ -15,8 +15,8 @@ import org.bukkit.util.BoundingBox;
public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> implements Conduit {
public CraftConduit(World world, ConduitBlockEntity tileEntity) {
super(world, tileEntity);
public CraftConduit(World world, ConduitBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftConduit(CraftConduit state, Location location) {
@@ -36,14 +36,14 @@ public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> impl
@Override
public boolean isActive() {
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
return conduit != null && conduit.isActive();
}
@Override
public boolean isHunting() {
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
return conduit != null && conduit.isHunting();
}
@@ -52,7 +52,7 @@ public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> impl
this.ensureNoWorldGeneration();
Collection<Block> blocks = new ArrayList<>();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
if (conduit != null) {
for (BlockPos position : conduit.effectBlocks) {
blocks.add(CraftBlock.at(this.getWorldHandle(), position));
@@ -65,20 +65,20 @@ public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> impl
@Override
public int getFrameBlockCount() {
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
return (conduit != null) ? conduit.effectBlocks.size() : 0;
}
@Override
public int getRange() {
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
return (conduit != null) ? ConduitBlockEntity.getRange(conduit.effectBlocks) : 0;
}
@Override
public boolean setTarget(LivingEntity target) {
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
if (conduit == null) {
return false;
}
@@ -107,7 +107,7 @@ public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> impl
@Override
public LivingEntity getTarget() {
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
if (conduit == null) {
return null;
}
@@ -118,7 +118,7 @@ public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> impl
@Override
public boolean hasTarget() {
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getBlockEntityFromWorld();
return conduit != null && conduit.destroyTarget != null && conduit.destroyTarget.isAlive();
}

View File

@@ -2,9 +2,10 @@ package org.bukkit.craftbukkit.block;
import java.util.Collections;
import java.util.Optional;
import net.minecraft.advancements.critereon.DataComponentMatchers;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.component.DataComponentPredicate;
import net.minecraft.core.component.DataComponentExactPredicate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.LockCode;
@@ -18,8 +19,8 @@ import org.bukkit.inventory.ItemStack;
public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends CraftBlockEntityState<T> implements Container {
public CraftContainer(World world, T tileEntity) {
super(world, tileEntity);
public CraftContainer(World world, T blockEntity) {
super(world, blockEntity);
}
protected CraftContainer(CraftContainer<T> state, Location location) {
@@ -33,7 +34,7 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
@Override
public String getLock() {
Optional<? extends Component> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
Optional<? extends Component> customName = this.getSnapshot().lockKey.predicate().components().exact().asPatch().get(DataComponents.CUSTOM_NAME);
return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : "";
}
@@ -43,8 +44,8 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
if (key == null) {
this.getSnapshot().lockKey = LockCode.NO_LOCK;
} else {
DataComponentPredicate predicate = DataComponentPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build();
this.getSnapshot().lockKey = new LockCode(new ItemPredicate(Optional.empty(), MinMaxBounds.Ints.ANY, predicate, Collections.emptyMap()));
DataComponentExactPredicate predicate = DataComponentExactPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build();
this.getSnapshot().lockKey = new LockCode(new ItemPredicate(Optional.empty(), MinMaxBounds.Ints.ANY, new DataComponentMatchers(predicate, Collections.emptyMap())));
}
}
@@ -57,18 +58,16 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
}
}
// Paper start
@Override
public net.kyori.adventure.text.Component customName() {
final T be = this.getSnapshot();
return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
final T blockEntity = this.getSnapshot();
return blockEntity.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(blockEntity.getCustomName()) : null;
}
@Override
public void customName(final net.kyori.adventure.text.Component customName) {
this.getSnapshot().name = (customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
this.getSnapshot().name = customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null;
}
// Paper end
@Override
public String getCustomName() {
@@ -82,11 +81,11 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
}
@Override
public void applyTo(T container) {
super.applyTo(container);
public void applyTo(T blockEntity) {
super.applyTo(blockEntity);
if (this.getSnapshot().name == null) {
container.name = null;
blockEntity.name = null;
}
}

View File

@@ -10,8 +10,8 @@ import org.bukkit.inventory.Inventory;
public class CraftCrafter extends CraftLootable<CrafterBlockEntity> implements Crafter {
public CraftCrafter(World world, CrafterBlockEntity tileEntity) {
super(world, tileEntity);
public CraftCrafter(World world, CrafterBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftCrafter(CraftCrafter state, Location location) {
@@ -29,7 +29,7 @@ public class CraftCrafter extends CraftLootable<CrafterBlockEntity> implements C
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.CreakingHeart;
public class CraftCreakingHeart extends CraftBlockEntityState<CreakingHeartBlockEntity> implements CreakingHeart {
public CraftCreakingHeart(World world, CreakingHeartBlockEntity tileEntity) {
super(world, tileEntity);
public CraftCreakingHeart(World world, CreakingHeartBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftCreakingHeart(CraftCreakingHeart state, Location location) {

View File

@@ -11,8 +11,8 @@ import java.util.stream.Collectors;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.InclusiveRange;
import net.minecraft.util.RandomSource;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.random.WeightedEntry.Wrapper;
import net.minecraft.util.random.Weighted;
import net.minecraft.util.random.WeightedList;
import net.minecraft.world.entity.EquipmentTable;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.SpawnData;
@@ -31,8 +31,8 @@ import org.bukkit.entity.EntityType;
public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEntity> implements CreatureSpawner, org.bukkit.craftbukkit.spawner.PaperSharedSpawnerLogic { // Paper - more spawner API
public CraftCreatureSpawner(World world, SpawnerBlockEntity tileEntity) {
super(world, tileEntity);
public CraftCreatureSpawner(World world, SpawnerBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftCreatureSpawner(CraftCreatureSpawner state, Location location) {
@@ -53,7 +53,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
@Override
public void setSpawnedType(EntityType entityType) {
if (entityType == null) {
this.getSnapshot().getSpawner().spawnPotentials = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
this.getSnapshot().getSpawner().spawnPotentials = WeightedList.of(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
this.getSnapshot().getSpawner().nextSpawnData = new SpawnData();
return;
}
@@ -86,7 +86,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
}
public static void setSpawnedEntity(BaseSpawner spawner, EntitySnapshot snapshot, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
spawner.spawnPotentials = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
spawner.spawnPotentials = WeightedList.of(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
if (snapshot == null) {
spawner.nextSpawnData = new SpawnData();
@@ -107,8 +107,8 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
CompoundTag compoundTag = ((CraftEntitySnapshot) snapshot).getData();
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder
spawner.spawnPotentials.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
WeightedList.Builder<SpawnData> builder = WeightedList.builder();
spawner.spawnPotentials.unwrap().forEach(entry -> builder.add(entry.value(), entry.weight()));
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment)), weight);
spawner.spawnPotentials = builder.build();
}
@@ -128,7 +128,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
public static void setPotentialSpawns(BaseSpawner spawner, Collection<SpawnerEntry> entries) {
Preconditions.checkArgument(entries != null, "Entries cannot be null");
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder();
WeightedList.Builder<SpawnData> builder = WeightedList.builder();
for (SpawnerEntry spawnerEntry : entries) {
CompoundTag compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData();
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnerEntry.getSpawnRule())), CraftCreatureSpawner.getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight());
@@ -144,18 +144,18 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
public static List<SpawnerEntry> getPotentialSpawns(BaseSpawner spawner) {
List<SpawnerEntry> entries = new ArrayList<>();
for (Wrapper<SpawnData> entry : spawner.spawnPotentials.unwrap()) { // PAIL rename Wrapper
CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.data().getEntityToSpawn());
for (Weighted<SpawnData> entry : spawner.spawnPotentials.unwrap()) {
CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.value().getEntityToSpawn());
if (snapshot != null) {
SpawnRule rule = entry.data().customSpawnRules().map(CraftCreatureSpawner::fromMinecraftRule).orElse(null);
entries.add(new SpawnerEntry(snapshot, entry.getWeight().asInt(), rule, CraftCreatureSpawner.getEquipment(entry.data().equipment())));
SpawnRule rule = entry.value().customSpawnRules().map(CraftCreatureSpawner::fromMinecraftRule).orElse(null);
entries.add(new SpawnerEntry(snapshot, entry.weight(), rule, CraftCreatureSpawner.getEquipment(entry.value().equipment())));
}
}
return entries;
}
public static SpawnData.CustomSpawnRules toMinecraftRule(SpawnRule rule) { // PAIL rename CustomSpawnRules
public static SpawnData.CustomSpawnRules toMinecraftRule(SpawnRule rule) {
if (rule == null) {
return null;
}
@@ -292,7 +292,6 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
)).orElse(null);
}
// Paper start - more spawner API
@Override
public boolean isActivated() {
requirePlaced();
@@ -324,5 +323,4 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
public net.minecraft.world.level.Level getInternalWorld() {
return this.world.getHandle();
}
// Paper end - more spawner API
}

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.DaylightDetector;
public class CraftDaylightDetector extends CraftBlockEntityState<DaylightDetectorBlockEntity> implements DaylightDetector {
public CraftDaylightDetector(World world, DaylightDetectorBlockEntity tileEntity) {
super(world, tileEntity);
public CraftDaylightDetector(World world, DaylightDetectorBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftDaylightDetector(CraftDaylightDetector state, Location location) {

View File

@@ -21,8 +21,8 @@ import org.bukkit.inventory.DecoratedPotInventory;
public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEntity> implements DecoratedPot {
public CraftDecoratedPot(World world, DecoratedPotBlockEntity tileEntity) {
super(world, tileEntity);
public CraftDecoratedPot(World world, DecoratedPotBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftDecoratedPot(CraftDecoratedPot state, Location location) {
@@ -40,7 +40,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
return this.getSnapshotInventory();
}
return new CraftInventoryDecoratedPot(this.getTileEntity());
return new CraftInventoryDecoratedPot(this.getBlockEntity());
}
// Paper start - expose loot table

View File

@@ -16,8 +16,8 @@ import org.bukkit.projectiles.BlockProjectileSource;
public class CraftDispenser extends CraftLootable<DispenserBlockEntity> implements Dispenser {
public CraftDispenser(World world, DispenserBlockEntity tileEntity) {
super(world, tileEntity);
public CraftDispenser(World world, DispenserBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftDispenser(CraftDispenser state, Location location) {
@@ -35,7 +35,7 @@ public class CraftDispenser extends CraftLootable<DispenserBlockEntity> implemen
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override
@@ -46,7 +46,7 @@ public class CraftDispenser extends CraftLootable<DispenserBlockEntity> implemen
return null;
}
return new CraftBlockProjectileSource((DispenserBlockEntity) this.getTileEntityFromWorld());
return new CraftBlockProjectileSource((DispenserBlockEntity) this.getBlockEntityFromWorld());
}
@Override

View File

@@ -14,8 +14,8 @@ import org.bukkit.inventory.Inventory;
public class CraftDropper extends CraftLootable<DropperBlockEntity> implements Dropper {
public CraftDropper(World world, DropperBlockEntity tileEntity) {
super(world, tileEntity);
public CraftDropper(World world, DropperBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftDropper(CraftDropper state, Location location) {
@@ -33,7 +33,7 @@ public class CraftDropper extends CraftLootable<DropperBlockEntity> implements D
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override

View File

@@ -8,26 +8,24 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
public class CraftEnchantingTable extends CraftBlockEntityState<EnchantingTableBlockEntity> implements EnchantingTable {
public CraftEnchantingTable(World world, EnchantingTableBlockEntity tileEntity) {
super(world, tileEntity);
public CraftEnchantingTable(World world, EnchantingTableBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftEnchantingTable(CraftEnchantingTable state, Location location) {
super(state, location);
}
// Paper start
@Override
public net.kyori.adventure.text.Component customName() {
final EnchantingTableBlockEntity be = this.getSnapshot();
return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
final EnchantingTableBlockEntity enchantingTable = this.getSnapshot();
return enchantingTable.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(enchantingTable.getCustomName()) : null;
}
@Override
public void customName(final net.kyori.adventure.text.Component customName) {
this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
}
// Paper end
@Override
public String getCustomName() {
@@ -41,11 +39,11 @@ public class CraftEnchantingTable extends CraftBlockEntityState<EnchantingTableB
}
@Override
public void applyTo(EnchantingTableBlockEntity enchantingTable) {
super.applyTo(enchantingTable);
public void applyTo(EnchantingTableBlockEntity blockEntity) {
super.applyTo(blockEntity);
if (!this.getSnapshot().hasCustomName()) {
enchantingTable.setCustomName(null);
blockEntity.setCustomName(null);
}
}

View File

@@ -10,8 +10,8 @@ import org.bukkit.craftbukkit.util.CraftLocation;
public class CraftEndGateway extends CraftBlockEntityState<TheEndGatewayBlockEntity> implements EndGateway {
public CraftEndGateway(World world, TheEndGatewayBlockEntity tileEntity) {
super(world, tileEntity);
public CraftEndGateway(World world, TheEndGatewayBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftEndGateway(CraftEndGateway state, Location location) {
@@ -56,11 +56,11 @@ public class CraftEndGateway extends CraftBlockEntityState<TheEndGatewayBlockEnt
}
@Override
public void applyTo(TheEndGatewayBlockEntity endGateway) {
super.applyTo(endGateway);
public void applyTo(TheEndGatewayBlockEntity blockEntity) {
super.applyTo(blockEntity);
if (this.getSnapshot().exitPortal == null) {
endGateway.exitPortal = null;
blockEntity.exitPortal = null;
}
}

View File

@@ -6,8 +6,8 @@ import org.bukkit.World;
public class CraftEndPortal extends CraftBlockEntityState<TheEndPortalBlockEntity> {
public CraftEndPortal(World world, TheEndPortalBlockEntity tileEntity) {
super(world, tileEntity);
public CraftEndPortal(World world, TheEndPortalBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftEndPortal(CraftEndPortal state, Location location) {

View File

@@ -8,8 +8,8 @@ import org.bukkit.block.EnderChest;
public class CraftEnderChest extends CraftBlockEntityState<EnderChestBlockEntity> implements EnderChest {
public CraftEnderChest(World world, EnderChestBlockEntity tileEntity) {
super(world, tileEntity);
public CraftEnderChest(World world, EnderChestBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftEnderChest(CraftEnderChest state, Location location) {
@@ -19,27 +19,27 @@ public class CraftEnderChest extends CraftBlockEntityState<EnderChestBlockEntity
@Override
public void open() {
this.requirePlaced();
if (!this.getTileEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getTileEntity().getBlockState();
int openCount = this.getTileEntity().openersCounter.getOpenerCount();
if (!this.getBlockEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getBlockEntity().getBlockState();
int openCount = this.getBlockEntity().openersCounter.getOpenerCount();
this.getTileEntity().openersCounter.onAPIOpen((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, openCount + 1);
this.getBlockEntity().openersCounter.onAPIOpen((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getBlockEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, openCount + 1);
}
this.getTileEntity().openersCounter.opened = true;
this.getBlockEntity().openersCounter.opened = true;
}
@Override
public void close() {
this.requirePlaced();
if (this.getTileEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getTileEntity().getBlockState();
int openCount = this.getTileEntity().openersCounter.getOpenerCount();
if (this.getBlockEntity().openersCounter.opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
BlockState block = this.getBlockEntity().getBlockState();
int openCount = this.getBlockEntity().openersCounter.getOpenerCount();
this.getTileEntity().openersCounter.onAPIClose((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, 0);
this.getBlockEntity().openersCounter.onAPIClose((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block);
this.getBlockEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.Level) this.getWorldHandle(), this.getPosition(), block, openCount, 0);
}
this.getTileEntity().openersCounter.opened = false;
this.getBlockEntity().openersCounter.opened = false;
}
@Override
@@ -55,7 +55,7 @@ public class CraftEnderChest extends CraftBlockEntityState<EnderChestBlockEntity
// Paper start - More Lidded Block API
@Override
public boolean isOpen() {
return getTileEntity().openersCounter.opened;
return getBlockEntity().openersCounter.opened;
}
// Paper end - More Lidded Block API

View File

@@ -16,8 +16,8 @@ import org.bukkit.inventory.Recipe;
public abstract class CraftFurnace<T extends AbstractFurnaceBlockEntity> extends CraftContainer<T> implements Furnace {
public CraftFurnace(World world, T tileEntity) {
super(world, tileEntity);
public CraftFurnace(World world, T blockEntity) {
super(world, blockEntity);
}
protected CraftFurnace(CraftFurnace<T> state, Location location) {
@@ -35,7 +35,7 @@ public abstract class CraftFurnace<T extends AbstractFurnaceBlockEntity> extends
return this.getSnapshotInventory();
}
return new CraftInventoryFurnace(this.getTileEntity());
return new CraftInventoryFurnace(this.getBlockEntity());
}
@Override

View File

@@ -6,8 +6,8 @@ import org.bukkit.World;
public class CraftFurnaceFurnace extends CraftFurnace<FurnaceBlockEntity> {
public CraftFurnaceFurnace(World world, FurnaceBlockEntity tileEntity) {
super(world, tileEntity);
public CraftFurnaceFurnace(World world, FurnaceBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftFurnaceFurnace(CraftFurnaceFurnace state, Location location) {

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.HangingSign;
public class CraftHangingSign extends CraftSign<HangingSignBlockEntity> implements HangingSign {
public CraftHangingSign(World world, HangingSignBlockEntity tileEntity) {
super(world, tileEntity);
public CraftHangingSign(World world, HangingSignBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftHangingSign(CraftHangingSign state, Location location) {

View File

@@ -9,8 +9,8 @@ import org.bukkit.inventory.Inventory;
public class CraftHopper extends CraftLootable<HopperBlockEntity> implements Hopper {
public CraftHopper(World world, HopperBlockEntity tileEntity) {
super(world, tileEntity);
public CraftHopper(World world, HopperBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftHopper(CraftHopper state, Location location) {
@@ -28,7 +28,7 @@ public class CraftHopper extends CraftLootable<HopperBlockEntity> implements Hop
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.Jigsaw;
public class CraftJigsaw extends CraftBlockEntityState<JigsawBlockEntity> implements Jigsaw {
public CraftJigsaw(World world, JigsawBlockEntity tileEntity) {
super(world, tileEntity);
public CraftJigsaw(World world, JigsawBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftJigsaw(CraftJigsaw state, Location location) {

View File

@@ -15,8 +15,8 @@ import org.bukkit.inventory.JukeboxInventory;
public class CraftJukebox extends CraftBlockEntityState<JukeboxBlockEntity> implements Jukebox {
public CraftJukebox(World world, JukeboxBlockEntity tileEntity) {
super(world, tileEntity);
public CraftJukebox(World world, JukeboxBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftJukebox(CraftJukebox state, Location location) {
@@ -34,7 +34,7 @@ public class CraftJukebox extends CraftBlockEntityState<JukeboxBlockEntity> impl
return this.getSnapshotInventory();
}
return new CraftInventoryJukebox(this.getTileEntity());
return new CraftInventoryJukebox(this.getBlockEntity());
}
@Override
@@ -44,8 +44,8 @@ public class CraftJukebox extends CraftBlockEntityState<JukeboxBlockEntity> impl
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
this.getWorldHandle().setBlock(this.getPosition(), this.data, 3);
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof JukeboxBlockEntity jukebox) {
BlockEntity blockEntity = this.getBlockEntityFromWorld();
if (blockEntity instanceof JukeboxBlockEntity jukebox) {
jukebox.setTheItem(jukebox.getTheItem());
}
}
@@ -92,16 +92,16 @@ public class CraftJukebox extends CraftBlockEntityState<JukeboxBlockEntity> impl
public boolean isPlaying() {
this.requirePlaced();
BlockEntity tileEntity = this.getTileEntityFromWorld();
return tileEntity instanceof JukeboxBlockEntity jukebox && jukebox.getSongPlayer().isPlaying();
BlockEntity blockEntity = this.getBlockEntityFromWorld();
return blockEntity instanceof JukeboxBlockEntity jukebox && jukebox.getSongPlayer().isPlaying();
}
@Override
public boolean startPlaying() {
this.requirePlaced();
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof JukeboxBlockEntity jukebox)) {
BlockEntity blockEntity = this.getBlockEntityFromWorld();
if (!(blockEntity instanceof JukeboxBlockEntity jukebox)) {
return false;
}
@@ -118,22 +118,22 @@ public class CraftJukebox extends CraftBlockEntityState<JukeboxBlockEntity> impl
public void stopPlaying() {
this.requirePlaced();
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof JukeboxBlockEntity jukebox)) {
BlockEntity blockEntity = this.getBlockEntityFromWorld();
if (!(blockEntity instanceof JukeboxBlockEntity jukebox)) {
return;
}
jukebox.getSongPlayer().stop(tileEntity.getLevel(), tileEntity.getBlockState());
jukebox.getSongPlayer().stop(blockEntity.getLevel(), blockEntity.getBlockState());
}
@Override
public boolean eject() {
this.ensureNoWorldGeneration();
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof JukeboxBlockEntity)) return false;
BlockEntity blockEntity = this.getBlockEntityFromWorld();
if (!(blockEntity instanceof JukeboxBlockEntity)) return false;
JukeboxBlockEntity jukebox = (JukeboxBlockEntity) tileEntity;
JukeboxBlockEntity jukebox = (JukeboxBlockEntity) blockEntity;
boolean result = !jukebox.getTheItem().isEmpty();
jukebox.popOutTheItem();
return result;

View File

@@ -11,8 +11,8 @@ import org.bukkit.inventory.Inventory;
public class CraftLectern extends CraftBlockEntityState<LecternBlockEntity> implements Lectern {
public CraftLectern(World world, LecternBlockEntity tileEntity) {
super(world, tileEntity);
public CraftLectern(World world, LecternBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftLectern(CraftLectern state, Location location) {
@@ -40,7 +40,7 @@ public class CraftLectern extends CraftBlockEntityState<LecternBlockEntity> impl
return this.getSnapshotInventory();
}
return new CraftInventoryLectern(this.getTileEntity().bookAccess);
return new CraftInventoryLectern(this.getBlockEntity().bookAccess);
}
@Override

View File

@@ -10,8 +10,8 @@ import org.bukkit.loot.Lootable;
public abstract class CraftLootable<T extends RandomizableContainerBlockEntity> extends CraftContainer<T> implements Nameable, Lootable, com.destroystokyo.paper.loottable.PaperLootableBlockInventory { // Paper
public CraftLootable(World world, T tileEntity) {
super(world, tileEntity);
public CraftLootable(World world, T blockEntity) {
super(world, blockEntity);
}
protected CraftLootable(CraftLootable<T> state, Location location) {
@@ -19,11 +19,11 @@ public abstract class CraftLootable<T extends RandomizableContainerBlockEntity>
}
@Override
public void applyTo(T lootable) {
super.applyTo(lootable);
public void applyTo(T blockEntity) {
super.applyTo(blockEntity);
if (this.getSnapshot().lootTable == null) {
lootable.setLootTable(null, 0L);
blockEntity.setLootTable(null, 0L);
}
}

View File

@@ -6,8 +6,8 @@ import org.bukkit.World;
public class CraftMovingPiston extends CraftBlockEntityState<PistonMovingBlockEntity> implements io.papermc.paper.block.MovingPiston { // Paper - Add Moving Piston API
public CraftMovingPiston(World world, PistonMovingBlockEntity tileEntity) {
super(world, tileEntity);
public CraftMovingPiston(World world, PistonMovingBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftMovingPiston(CraftMovingPiston state, Location location) {
@@ -27,22 +27,22 @@ public class CraftMovingPiston extends CraftBlockEntityState<PistonMovingBlockEn
// Paper start - Add Moving Piston API
@Override
public org.bukkit.block.data.BlockData getMovingBlock() {
return org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(this.getTileEntity().getMovedState());
return org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(this.getBlockEntity().getMovedState());
}
@Override
public org.bukkit.block.BlockFace getDirection() {
return org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(this.getTileEntity().getDirection());
return org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(this.getBlockEntity().getDirection());
}
@Override
public boolean isExtending() {
return this.getTileEntity().isExtending();
return this.getBlockEntity().isExtending();
}
@Override
public boolean isPistonHead() {
return this.getTileEntity().isSourcePiston();
return this.getBlockEntity().isSourcePiston();
}
// Paper end - Add Moving Piston API
}

View File

@@ -10,8 +10,8 @@ import org.bukkit.block.SculkCatalyst;
public class CraftSculkCatalyst extends CraftBlockEntityState<SculkCatalystBlockEntity> implements SculkCatalyst {
public CraftSculkCatalyst(World world, SculkCatalystBlockEntity tileEntity) {
super(world, tileEntity);
public CraftSculkCatalyst(World world, SculkCatalystBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftSculkCatalyst(CraftSculkCatalyst state, Location location) {
@@ -25,8 +25,8 @@ public class CraftSculkCatalyst extends CraftBlockEntityState<SculkCatalystBlock
this.requirePlaced();
// bloom() is for visual blooming effect, cursors are what changes the blocks.
this.getTileEntity().getListener().bloom(this.world.getHandle(), this.getPosition(), this.getHandle(), this.world.getHandle().getRandom());
this.getTileEntity().getListener().getSculkSpreader().addCursors(new BlockPos(block.getX(), block.getY(), block.getZ()), charge);
this.getBlockEntity().getListener().bloom(this.world.getHandle(), this.getPosition(), this.getHandle(), this.world.getHandle().getRandom());
this.getBlockEntity().getListener().getSculkSpreader().addCursors(new BlockPos(block.getX(), block.getY(), block.getZ()), charge);
}
@Override
@@ -45,13 +45,13 @@ public class CraftSculkCatalyst extends CraftBlockEntityState<SculkCatalystBlock
com.google.common.base.Preconditions.checkNotNull(position);
requirePlaced();
getTileEntity().getListener().bloom(
getBlockEntity().getListener().bloom(
world.getHandle(),
getTileEntity().getBlockPos(),
getTileEntity().getBlockState(),
getBlockEntity().getBlockPos(),
getBlockEntity().getBlockState(),
world.getHandle().getRandom()
);
getTileEntity().getListener().getSculkSpreader().addCursors(io.papermc.paper.util.MCUtil.toBlockPos(position), charge);
getBlockEntity().getListener().getSculkSpreader().addCursors(io.papermc.paper.util.MCUtil.toBlockPos(position), charge);
}
// Paper end
}

View File

@@ -8,8 +8,8 @@ import org.bukkit.block.SculkSensor;
public class CraftSculkSensor<T extends SculkSensorBlockEntity> extends CraftBlockEntityState<T> implements SculkSensor {
public CraftSculkSensor(World world, T tileEntity) {
super(world, tileEntity);
public CraftSculkSensor(World world, T blockEntity) {
super(world, blockEntity);
}
protected CraftSculkSensor(CraftSculkSensor<T> state, Location location) {

View File

@@ -10,8 +10,8 @@ import org.bukkit.entity.Player;
public class CraftSculkShrieker extends CraftBlockEntityState<SculkShriekerBlockEntity> implements SculkShrieker {
public CraftSculkShrieker(World world, SculkShriekerBlockEntity tileEntity) {
super(world, tileEntity);
public CraftSculkShrieker(World world, SculkShriekerBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftSculkShrieker(CraftSculkShrieker state, Location location) {
@@ -32,8 +32,8 @@ public class CraftSculkShrieker extends CraftBlockEntityState<SculkShriekerBlock
public void tryShriek(Player player) {
this.requirePlaced();
ServerPlayer entityPlayer = (player == null) ? null : ((CraftPlayer) player).getHandle();
this.getTileEntity().tryShriek(this.world.getHandle(), entityPlayer);
ServerPlayer serverPlayer = player == null ? null : ((CraftPlayer) player).getHandle();
this.getBlockEntity().tryShriek(this.world.getHandle(), serverPlayer);
}
@Override

View File

@@ -13,8 +13,8 @@ import org.bukkit.inventory.Inventory;
public class CraftShulkerBox extends CraftLootable<ShulkerBoxBlockEntity> implements ShulkerBox {
public CraftShulkerBox(World world, ShulkerBoxBlockEntity tileEntity) {
super(world, tileEntity);
public CraftShulkerBox(World world, ShulkerBoxBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftShulkerBox(CraftShulkerBox state, Location location) {
@@ -32,7 +32,7 @@ public class CraftShulkerBox extends CraftLootable<ShulkerBoxBlockEntity> implem
return this.getSnapshotInventory();
}
return new CraftInventory(this.getTileEntity());
return new CraftInventory(this.getBlockEntity());
}
@Override
@@ -45,23 +45,23 @@ public class CraftShulkerBox extends CraftLootable<ShulkerBoxBlockEntity> implem
@Override
public void open() {
this.requirePlaced();
if (!this.getTileEntity().opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
net.minecraft.world.level.Level world = this.getTileEntity().getLevel();
world.blockEvent(this.getPosition(), this.getTileEntity().getBlockState().getBlock(), 1, 1);
if (!this.getBlockEntity().opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
net.minecraft.world.level.Level world = this.getBlockEntity().getLevel();
world.blockEvent(this.getPosition(), this.getBlockEntity().getBlockState().getBlock(), 1, 1);
world.playSound(null, this.getPosition(), SoundEvents.SHULKER_BOX_OPEN, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
}
this.getTileEntity().opened = true;
this.getBlockEntity().opened = true;
}
@Override
public void close() {
this.requirePlaced();
if (this.getTileEntity().opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
net.minecraft.world.level.Level world = this.getTileEntity().getLevel();
world.blockEvent(this.getPosition(), this.getTileEntity().getBlockState().getBlock(), 1, 0);
if (this.getBlockEntity().opened && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
net.minecraft.world.level.Level world = this.getBlockEntity().getLevel();
world.blockEvent(this.getPosition(), this.getBlockEntity().getBlockState().getBlock(), 1, 0);
world.playSound(null, this.getPosition(), SoundEvents.SHULKER_BOX_CLOSE, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); // Paper - More Lidded Block API (Wrong sound)
}
this.getTileEntity().opened = false;
this.getBlockEntity().opened = false;
}
@Override
@@ -77,7 +77,7 @@ public class CraftShulkerBox extends CraftLootable<ShulkerBoxBlockEntity> implem
// Paper start - More Lidded Block API
@Override
public boolean isOpen() {
return getTileEntity().opened;
return getBlockEntity().opened;
}
// Paper end - More Lidded Block API
}

View File

@@ -24,8 +24,8 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
private final CraftSignSide front;
private final CraftSignSide back;
public CraftSign(World world, T tileEntity) {
super(world, tileEntity);
public CraftSign(World world, T blockEntity) {
super(world, blockEntity);
this.front = new CraftSignSide(this.getSnapshot().getFrontText());
this.back = new CraftSignSide(this.getSnapshot().getBackText());
}
@@ -129,8 +129,8 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
public Player getAllowedEditor() {
this.ensureNoWorldGeneration();
// getPlayerWhoMayEdit is always null for the snapshot, so we use the wrapped TileEntity
UUID id = this.getTileEntity().getPlayerWhoMayEdit();
// getPlayerWhoMayEdit is always null for the snapshot, so we use the wrapped BlockEntity
UUID id = this.getBlockEntity().getPlayerWhoMayEdit();
return (id == null) ? null : Bukkit.getPlayer(id);
}
@@ -145,11 +145,11 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
}
@Override
public void applyTo(T sign) {
public void applyTo(T blockEntity) {
this.getSnapshot().setText(this.front.applyLegacyStringToSignSide(), true);
this.getSnapshot().setText(this.back.applyLegacyStringToSignSide(), false);
super.applyTo(sign);
super.applyTo(blockEntity);
}
@Override
@@ -178,10 +178,10 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
}
} // Paper - Add PlayerOpenSignEvent
SignBlockEntity handle = ((CraftSign<?>) sign).getTileEntity();
handle.setAllowedPlayerEditor(player.getUniqueId());
SignBlockEntity blockEntity = ((CraftSign<?>) sign).getBlockEntity();
blockEntity.setAllowedPlayerEditor(player.getUniqueId());
((CraftPlayer) player).getHandle().openTextEdit(handle, Side.FRONT == side);
((CraftPlayer) player).getHandle().openTextEdit(blockEntity, Side.FRONT == side);
}
// Paper start
@@ -202,13 +202,13 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
@Override
public java.util.UUID getAllowedEditorUniqueId() {
this.ensureNoWorldGeneration();
return this.getTileEntity().getPlayerWhoMayEdit();
return this.getBlockEntity().getPlayerWhoMayEdit();
}
@Override
public void setAllowedEditorUniqueId(java.util.UUID uuid) {
this.ensureNoWorldGeneration();
this.getTileEntity().setAllowedPlayerEditor(uuid);
this.getBlockEntity().setAllowedPlayerEditor(uuid);
}
@Override

View File

@@ -31,8 +31,8 @@ public class CraftSkull extends CraftBlockEntityState<SkullBlockEntity> implemen
private static final int MAX_OWNER_LENGTH = 16;
private ResolvableProfile profile;
public CraftSkull(World world, SkullBlockEntity tileEntity) {
super(world, tileEntity);
public CraftSkull(World world, SkullBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftSkull(CraftSkull state, Location location) {
@@ -40,10 +40,10 @@ public class CraftSkull extends CraftBlockEntityState<SkullBlockEntity> implemen
}
@Override
public void load(SkullBlockEntity skull) {
super.load(skull);
public void load(SkullBlockEntity blockEntity) {
super.load(blockEntity);
ResolvableProfile owner = skull.getOwnerProfile();
ResolvableProfile owner = blockEntity.getOwnerProfile();
if (owner != null) {
this.profile = owner;
}
@@ -201,11 +201,11 @@ public class CraftSkull extends CraftBlockEntityState<SkullBlockEntity> implemen
}
@Override
public void applyTo(SkullBlockEntity skull) {
super.applyTo(skull);
public void applyTo(SkullBlockEntity blockEntity) {
super.applyTo(blockEntity);
if (this.getSkullType() == SkullType.PLAYER) {
skull.setOwner(this.hasOwner() ? this.profile : null);
blockEntity.setOwner(this.hasOwner() ? this.profile : null);
}
}

View File

@@ -7,8 +7,8 @@ import org.bukkit.block.Smoker;
public class CraftSmoker extends CraftFurnace<SmokerBlockEntity> implements Smoker {
public CraftSmoker(World world, SmokerBlockEntity tileEntity) {
super(world, tileEntity);
public CraftSmoker(World world, SmokerBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftSmoker(CraftSmoker state, Location location) {

View File

@@ -19,8 +19,8 @@ public class CraftStructureBlock extends CraftBlockEntityState<StructureBlockEnt
private static final int MAX_SIZE = 48;
public CraftStructureBlock(World world, StructureBlockEntity tileEntity) {
super(world, tileEntity);
public CraftStructureBlock(World world, StructureBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftStructureBlock(CraftStructureBlock state, Location location) {
@@ -180,19 +180,19 @@ public class CraftStructureBlock extends CraftBlockEntityState<StructureBlockEnt
}
@Override
protected void applyTo(StructureBlockEntity tileEntity) {
super.applyTo(tileEntity);
protected void applyTo(StructureBlockEntity blockEntity) {
super.applyTo(blockEntity);
net.minecraft.world.level.LevelAccessor access = this.getWorldHandle();
// Ensure block type is correct
if (access instanceof net.minecraft.world.level.Level) {
tileEntity.setMode(tileEntity.getMode());
blockEntity.setMode(blockEntity.getMode());
} else if (access != null) {
// Custom handle during world generation
// From TileEntityStructure#setUsageMode(BlockPropertyStructureMode)
net.minecraft.world.level.block.state.BlockState data = access.getBlockState(this.getPosition());
if (data.is(net.minecraft.world.level.block.Blocks.STRUCTURE_BLOCK)) {
access.setBlock(this.getPosition(), data.setValue(net.minecraft.world.level.block.StructureBlock.MODE, tileEntity.getMode()), 2);
// From StructureBlockEntity#setMode(BlockPropertyStructureMode)
net.minecraft.world.level.block.state.BlockState state = access.getBlockState(this.getPosition());
if (state.is(net.minecraft.world.level.block.Blocks.STRUCTURE_BLOCK)) {
access.setBlock(this.getPosition(), state.setValue(net.minecraft.world.level.block.StructureBlock.MODE, blockEntity.getMode()), 2);
}
}
}

View File

@@ -1,27 +0,0 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.BrushableBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.SuspiciousSand;
public class CraftSuspiciousSand extends CraftBrushableBlock implements SuspiciousSand {
public CraftSuspiciousSand(World world, BrushableBlockEntity tileEntity) {
super(world, tileEntity);
}
protected CraftSuspiciousSand(CraftSuspiciousSand state, Location location) {
super(state, location);
}
@Override
public CraftSuspiciousSand copy() {
return new CraftSuspiciousSand(this, null);
}
@Override
public CraftSuspiciousSand copy(Location location) {
return new CraftSuspiciousSand(this, location);
}
}

View File

@@ -0,0 +1,27 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TestBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.TestBlock;
public class CraftTestBlock extends CraftBlockEntityState<TestBlockEntity> implements TestBlock {
public CraftTestBlock(World world, TestBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftTestBlock(CraftTestBlock state, Location location) {
super(state, location);
}
@Override
public CraftTestBlock copy() {
return new CraftTestBlock(this, null);
}
@Override
public CraftTestBlock copy(Location location) {
return new CraftTestBlock(this, location);
}
}

View File

@@ -0,0 +1,27 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TestInstanceBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.TestInstanceBlock;
public class CraftTestInstanceBlock extends CraftBlockEntityState<TestInstanceBlockEntity> implements TestInstanceBlock {
public CraftTestInstanceBlock(World world, TestInstanceBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftTestInstanceBlock(CraftTestInstanceBlock state, Location location) {
super(state, location);
}
@Override
public CraftTestInstanceBlock copy() {
return new CraftTestInstanceBlock(this, null);
}
@Override
public CraftTestInstanceBlock copy(Location location) {
return new CraftTestInstanceBlock(this, location);
}
}

View File

@@ -21,10 +21,10 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
private final CraftTrialSpawnerConfiguration normalConfig;
private final CraftTrialSpawnerConfiguration ominousConfig;
public CraftTrialSpawner(World world, TrialSpawnerBlockEntity tileEntity) {
super(world, tileEntity);
this.normalConfig = new CraftTrialSpawnerConfiguration(tileEntity.getTrialSpawner().getNormalConfig(), this.getSnapshot());
this.ominousConfig = new CraftTrialSpawnerConfiguration(tileEntity.getTrialSpawner().getOminousConfig(), this.getSnapshot());
public CraftTrialSpawner(World world, TrialSpawnerBlockEntity blockEntity) {
super(world, blockEntity);
this.normalConfig = new CraftTrialSpawnerConfiguration(blockEntity.getTrialSpawner().getNormalConfig(), this.getSnapshot());
this.ominousConfig = new CraftTrialSpawnerConfiguration(blockEntity.getTrialSpawner().getOminousConfig(), this.getSnapshot());
}
protected CraftTrialSpawner(CraftTrialSpawner state, Location location) {
@@ -169,11 +169,11 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
}
@Override
protected void applyTo(TrialSpawnerBlockEntity tileEntity) {
super.applyTo(tileEntity);
protected void applyTo(TrialSpawnerBlockEntity blockEntity) {
super.applyTo(blockEntity);
tileEntity.trialSpawner.normalConfig = Holder.direct(this.normalConfig.toMinecraft());
tileEntity.trialSpawner.ominousConfig = Holder.direct(this.ominousConfig.toMinecraft());
blockEntity.trialSpawner.normalConfig = Holder.direct(this.normalConfig.toMinecraft());
blockEntity.trialSpawner.ominousConfig = Holder.direct(this.ominousConfig.toMinecraft());
}
private TrialSpawnerData getTrialData() {

View File

@@ -10,8 +10,9 @@ import java.util.Optional;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.random.WeightedEntry.Wrapper;
import net.minecraft.util.random.Weighted;
import net.minecraft.util.random.WeightedList;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerConfig;
@@ -35,8 +36,8 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
private float totalMobsAddedPerPlayer;
private float simultaneousMobsAddedPerPlayer;
private int ticksBetweenSpawn;
private SimpleWeightedRandomList<SpawnData> spawnPotentialsDefinition;
private SimpleWeightedRandomList<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> lootTablesToEject;
private WeightedList<SpawnData> spawnPotentialsDefinition;
private WeightedList<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> lootTablesToEject;
private ResourceKey<net.minecraft.world.level.storage.loot.LootTable> itemsToDropWhenOminous;
public CraftTrialSpawnerConfiguration(TrialSpawnerConfig minecraft, TrialSpawnerBlockEntity snapshot) {
@@ -59,7 +60,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
return null;
}
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(this.spawnPotentialsDefinition.unwrap().get(0).data().getEntityToSpawn());
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(this.spawnPotentialsDefinition.unwrap().get(0).value().getEntityToSpawn());
return type.map(CraftEntityType::minecraftToBukkit).orElse(null);
}
@@ -67,15 +68,15 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
public void setSpawnedType(EntityType entityType) {
if (entityType == null) {
this.getTrialData().nextSpawnData = Optional.empty();
this.spawnPotentialsDefinition = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
this.spawnPotentialsDefinition = WeightedList.of(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
return;
}
Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "Can't spawn EntityType %s from mob spawners!", entityType);
SpawnData data = new SpawnData();
data.getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(CraftEntityType.bukkitToMinecraft(entityType)).toString());
data.getEntityToSpawn().putString(Entity.ID_TAG, BuiltInRegistries.ENTITY_TYPE.getKey(CraftEntityType.bukkitToMinecraft(entityType)).toString());
this.getTrialData().nextSpawnData = Optional.of(data);
this.spawnPotentialsDefinition = SimpleWeightedRandomList.single(data);
this.spawnPotentialsDefinition = WeightedList.of(data);
}
@Override
@@ -142,12 +143,12 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
@Override
public EntitySnapshot getSpawnedEntity() {
SimpleWeightedRandomList<SpawnData> potentials = this.spawnPotentialsDefinition;
WeightedList<SpawnData> potentials = this.spawnPotentialsDefinition;
if (potentials.isEmpty()) {
return null;
}
return CraftEntitySnapshot.create(potentials.unwrap().get(0).data().getEntityToSpawn());
return CraftEntitySnapshot.create(potentials.unwrap().get(0).value().getEntityToSpawn());
}
@Override
@@ -165,7 +166,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
private void setSpawnedEntity(EntitySnapshot snapshot, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
if (snapshot == null) {
this.getTrialData().nextSpawnData = Optional.empty();
this.spawnPotentialsDefinition = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
this.spawnPotentialsDefinition = WeightedList.of(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
return;
}
@@ -173,7 +174,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
SpawnData data = new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment));
this.getTrialData().nextSpawnData = Optional.of(data);
this.spawnPotentialsDefinition = SimpleWeightedRandomList.single(data);
this.spawnPotentialsDefinition = WeightedList.of(data);
}
@Override
@@ -186,8 +187,8 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
CompoundTag compoundTag = ((CraftEntitySnapshot) snapshot).getData();
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder
this.spawnPotentialsDefinition.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
WeightedList.Builder<SpawnData> builder = WeightedList.builder();
this.spawnPotentialsDefinition.unwrap().forEach(entry -> builder.add(entry.value(), entry.weight()));
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment)), weight);
this.spawnPotentialsDefinition = builder.build();
}
@@ -203,7 +204,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
public void setPotentialSpawns(Collection<SpawnerEntry> entries) {
Preconditions.checkArgument(entries != null, "Entries cannot be null");
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder();
WeightedList.Builder<SpawnData> builder = WeightedList.builder();
for (SpawnerEntry spawnerEntry : entries) {
CompoundTag compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData();
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnerEntry.getSpawnRule())), CraftCreatureSpawner.getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight());
@@ -215,12 +216,12 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
public List<SpawnerEntry> getPotentialSpawns() {
List<SpawnerEntry> entries = new ArrayList<>();
for (Wrapper<SpawnData> entry : this.spawnPotentialsDefinition.unwrap()) { // PAIL rename Wrapper
CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.data().getEntityToSpawn());
for (Weighted<SpawnData> entry : this.spawnPotentialsDefinition.unwrap()) {
CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.value().getEntityToSpawn());
if (snapshot != null) {
SpawnRule rule = entry.data().customSpawnRules().map(CraftCreatureSpawner::fromMinecraftRule).orElse(null);
entries.add(new SpawnerEntry(snapshot, entry.getWeight().asInt(), rule));
SpawnRule rule = entry.value().customSpawnRules().map(CraftCreatureSpawner::fromMinecraftRule).orElse(null);
entries.add(new SpawnerEntry(snapshot, entry.weight(), rule));
}
}
return entries;
@@ -230,10 +231,10 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
public Map<LootTable, Integer> getPossibleRewards() {
Map<LootTable, Integer> tables = new HashMap<>();
for (Wrapper<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : this.lootTablesToEject.unwrap()) {
LootTable table = CraftLootTable.minecraftToBukkit(entry.data());
for (Weighted<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : this.lootTablesToEject.unwrap()) {
LootTable table = CraftLootTable.minecraftToBukkit(entry.value());
if (table != null) {
tables.put(table, entry.getWeight().asInt());
tables.put(table, entry.weight());
}
}
@@ -245,8 +246,8 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
Preconditions.checkArgument(table != null, "Table cannot be null");
Preconditions.checkArgument(weight >= 1, "Weight must be at least 1");
SimpleWeightedRandomList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
this.lootTablesToEject.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
WeightedList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = WeightedList.builder();
this.lootTablesToEject.unwrap().forEach(entry -> builder.add(entry.value(), entry.weight()));
builder.add(CraftLootTable.bukkitToMinecraft(table), weight);
this.lootTablesToEject = builder.build();
}
@@ -256,11 +257,11 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
Preconditions.checkArgument(table != null, "Key cannot be null");
ResourceKey<net.minecraft.world.level.storage.loot.LootTable> minecraftKey = CraftLootTable.bukkitToMinecraft(table);
SimpleWeightedRandomList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
WeightedList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = WeightedList.builder();
for (Wrapper<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : this.lootTablesToEject.unwrap()) {
if (!entry.data().equals(minecraftKey)) {
builder.add(entry.data(), entry.getWeight().asInt());
for (Weighted<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : this.lootTablesToEject.unwrap()) {
if (!entry.value().equals(minecraftKey)) {
builder.add(entry.value(), entry.weight());
}
}
this.lootTablesToEject = builder.build();
@@ -269,11 +270,11 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
@Override
public void setPossibleRewards(Map<LootTable, Integer> rewards) {
if (rewards == null || rewards.isEmpty()) {
this.lootTablesToEject = SimpleWeightedRandomList.empty();
this.lootTablesToEject = WeightedList.of();
return;
}
SimpleWeightedRandomList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
WeightedList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = WeightedList.builder();
rewards.forEach((table, weight) -> {
Preconditions.checkArgument(table != null, "Table cannot be null");
Preconditions.checkArgument(weight >= 1, "Weight must be at least 1");

View File

@@ -23,8 +23,8 @@ import java.util.UUID;
@NullMarked
public class CraftVault extends CraftBlockEntityState<VaultBlockEntity> implements Vault {
public CraftVault(World world, VaultBlockEntity tileEntity) {
super(world, tileEntity);
public CraftVault(World world, VaultBlockEntity blockEntity) {
super(world, blockEntity);
}
protected CraftVault(CraftVault state, @Nullable Location location) {

View File

@@ -1,23 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Ageable;
public abstract class CraftAgeable extends CraftBlockData implements Ageable {
private static final net.minecraft.world.level.block.state.properties.IntegerProperty AGE = getInteger("age");
@Override
public int getAge() {
return this.get(CraftAgeable.AGE);
}
@Override
public void setAge(int age) {
this.set(CraftAgeable.AGE, age);
}
@Override
public int getMaximumAge() {
return getMax(CraftAgeable.AGE);
}
}

View File

@@ -1,23 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.AnaloguePowerable;
public abstract class CraftAnaloguePowerable extends CraftBlockData implements AnaloguePowerable {
private static final net.minecraft.world.level.block.state.properties.IntegerProperty POWER = getInteger("power");
@Override
public int getPower() {
return this.get(CraftAnaloguePowerable.POWER);
}
@Override
public void setPower(int power) {
this.set(CraftAnaloguePowerable.POWER, power);
}
@Override
public int getMaximumPower() {
return getMax(CraftAnaloguePowerable.POWER);
}
}

View File

@@ -1,18 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Attachable;
public abstract class CraftAttachable extends CraftBlockData implements Attachable {
private static final net.minecraft.world.level.block.state.properties.BooleanProperty ATTACHED = getBoolean("attached");
@Override
public boolean isAttached() {
return this.get(CraftAttachable.ATTACHED);
}
@Override
public void setAttached(boolean attached) {
this.set(CraftAttachable.ATTACHED, attached);
}
}

View File

@@ -1,18 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Bisected;
public class CraftBisected extends CraftBlockData implements Bisected {
private static final net.minecraft.world.level.block.state.properties.EnumProperty<?> HALF = getEnum("half");
@Override
public org.bukkit.block.data.Bisected.Half getHalf() {
return this.get(CraftBisected.HALF, org.bukkit.block.data.Bisected.Half.class);
}
@Override
public void setHalf(org.bukkit.block.data.Bisected.Half half) {
this.set(CraftBisected.HALF, half);
}
}

View File

@@ -340,15 +340,12 @@ public class CraftBlockData implements BlockData {
return state;
}
/**
* Get the minimum value allowed by the BlockStateInteger.
*
* @param state the state to check
* @return the minimum value allowed
*/
protected static int getMin(IntegerProperty state) {
return state.min;
}
public static final BlockFace[] ROTATION_CYCLE = {
BlockFace.SOUTH, BlockFace.SOUTH_SOUTH_WEST, BlockFace.SOUTH_WEST, BlockFace.WEST_SOUTH_WEST,
BlockFace.WEST, BlockFace.WEST_NORTH_WEST, BlockFace.NORTH_WEST, BlockFace.NORTH_NORTH_WEST,
BlockFace.NORTH, BlockFace.NORTH_NORTH_EAST, BlockFace.NORTH_EAST, BlockFace.EAST_NORTH_EAST,
BlockFace.EAST, BlockFace.EAST_SOUTH_EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_SOUTH_EAST
};
/**
* Get the maximum value allowed by the BlockStateInteger.
@@ -360,177 +357,176 @@ public class CraftBlockData implements BlockData {
return state.max;
}
//
private static final Map<Class<? extends Block>, Function<net.minecraft.world.level.block.state.BlockState, CraftBlockData>> MAP = new HashMap<>();
static {
//<editor-fold desc="CraftBlockData Registration" defaultstate="collapsed">
// Start generate - CraftBlockData#MAP
// @GeneratedFrom 1.21.5
register(net.minecraft.world.level.block.AmethystClusterBlock.class, org.bukkit.craftbukkit.block.impl.CraftAmethystCluster::new);
register(net.minecraft.world.level.block.BigDripleafBlock.class, org.bukkit.craftbukkit.block.impl.CraftBigDripleaf::new);
register(net.minecraft.world.level.block.BigDripleafStemBlock.class, org.bukkit.craftbukkit.block.impl.CraftBigDripleafStem::new);
register(net.minecraft.world.level.block.AnvilBlock.class, org.bukkit.craftbukkit.block.impl.CraftAnvil::new);
register(net.minecraft.world.level.block.BambooStalkBlock.class, org.bukkit.craftbukkit.block.impl.CraftBamboo::new);
register(net.minecraft.world.level.block.AttachedStemBlock.class, org.bukkit.craftbukkit.block.impl.CraftAttachedStem::new);
register(net.minecraft.world.level.block.BambooStalkBlock.class, org.bukkit.craftbukkit.block.impl.CraftBambooStalk::new);
register(net.minecraft.world.level.block.BannerBlock.class, org.bukkit.craftbukkit.block.impl.CraftBanner::new);
register(net.minecraft.world.level.block.WallBannerBlock.class, org.bukkit.craftbukkit.block.impl.CraftBannerWall::new);
register(net.minecraft.world.level.block.BarrelBlock.class, org.bukkit.craftbukkit.block.impl.CraftBarrel::new);
register(net.minecraft.world.level.block.BarrierBlock.class, org.bukkit.craftbukkit.block.impl.CraftBarrier::new);
register(net.minecraft.world.level.block.BaseCoralFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftBaseCoralFan::new);
register(net.minecraft.world.level.block.BaseCoralPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftBaseCoralPlant::new);
register(net.minecraft.world.level.block.BaseCoralWallFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftBaseCoralWallFan::new);
register(net.minecraft.world.level.block.BedBlock.class, org.bukkit.craftbukkit.block.impl.CraftBed::new);
register(net.minecraft.world.level.block.BeehiveBlock.class, org.bukkit.craftbukkit.block.impl.CraftBeehive::new);
register(net.minecraft.world.level.block.BeetrootBlock.class, org.bukkit.craftbukkit.block.impl.CraftBeetroot::new);
register(net.minecraft.world.level.block.BellBlock.class, org.bukkit.craftbukkit.block.impl.CraftBell::new);
register(net.minecraft.world.level.block.BigDripleafBlock.class, org.bukkit.craftbukkit.block.impl.CraftBigDripleaf::new);
register(net.minecraft.world.level.block.BigDripleafStemBlock.class, org.bukkit.craftbukkit.block.impl.CraftBigDripleafStem::new);
register(net.minecraft.world.level.block.BlastFurnaceBlock.class, org.bukkit.craftbukkit.block.impl.CraftBlastFurnace::new);
register(net.minecraft.world.level.block.BrewingStandBlock.class, org.bukkit.craftbukkit.block.impl.CraftBrewingStand::new);
register(net.minecraft.world.level.block.BrushableBlock.class, org.bukkit.craftbukkit.block.impl.CraftBrushable::new);
register(net.minecraft.world.level.block.BubbleColumnBlock.class, org.bukkit.craftbukkit.block.impl.CraftBubbleColumn::new);
register(net.minecraft.world.level.block.ButtonBlock.class, org.bukkit.craftbukkit.block.impl.CraftButtonAbstract::new);
register(net.minecraft.world.level.block.ButtonBlock.class, org.bukkit.craftbukkit.block.impl.CraftButton::new);
register(net.minecraft.world.level.block.CactusBlock.class, org.bukkit.craftbukkit.block.impl.CraftCactus::new);
register(net.minecraft.world.level.block.CakeBlock.class, org.bukkit.craftbukkit.block.impl.CraftCake::new);
register(net.minecraft.world.level.block.CampfireBlock.class, org.bukkit.craftbukkit.block.impl.CraftCampfire::new);
register(net.minecraft.world.level.block.CarrotBlock.class, org.bukkit.craftbukkit.block.impl.CraftCarrots::new);
register(net.minecraft.world.level.block.ChainBlock.class, org.bukkit.craftbukkit.block.impl.CraftChain::new);
register(net.minecraft.world.level.block.ChestBlock.class, org.bukkit.craftbukkit.block.impl.CraftChest::new);
register(net.minecraft.world.level.block.TrappedChestBlock.class, org.bukkit.craftbukkit.block.impl.CraftChestTrapped::new);
register(net.minecraft.world.level.block.ChorusFlowerBlock.class, org.bukkit.craftbukkit.block.impl.CraftChorusFlower::new);
register(net.minecraft.world.level.block.ChorusPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftChorusFruit::new);
register(net.minecraft.world.level.block.WallBlock.class, org.bukkit.craftbukkit.block.impl.CraftCobbleWall::new);
register(net.minecraft.world.level.block.CocoaBlock.class, org.bukkit.craftbukkit.block.impl.CraftCocoa::new);
register(net.minecraft.world.level.block.CommandBlock.class, org.bukkit.craftbukkit.block.impl.CraftCommand::new);
register(net.minecraft.world.level.block.ComposterBlock.class, org.bukkit.craftbukkit.block.impl.CraftComposter::new);
register(net.minecraft.world.level.block.ConduitBlock.class, org.bukkit.craftbukkit.block.impl.CraftConduit::new);
register(net.minecraft.world.level.block.BaseCoralPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralDead::new);
register(net.minecraft.world.level.block.CoralFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralFan::new);
register(net.minecraft.world.level.block.BaseCoralFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralFanAbstract::new);
register(net.minecraft.world.level.block.CoralWallFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralFanWall::new);
register(net.minecraft.world.level.block.BaseCoralWallFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralFanWallAbstract::new);
register(net.minecraft.world.level.block.CoralPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralPlant::new);
register(net.minecraft.world.level.block.CropBlock.class, org.bukkit.craftbukkit.block.impl.CraftCrops::new);
register(net.minecraft.world.level.block.DaylightDetectorBlock.class, org.bukkit.craftbukkit.block.impl.CraftDaylightDetector::new);
register(net.minecraft.world.level.block.SnowyDirtBlock.class, org.bukkit.craftbukkit.block.impl.CraftDirtSnow::new);
register(net.minecraft.world.level.block.DispenserBlock.class, org.bukkit.craftbukkit.block.impl.CraftDispenser::new);
register(net.minecraft.world.level.block.DoorBlock.class, org.bukkit.craftbukkit.block.impl.CraftDoor::new);
register(net.minecraft.world.level.block.DropperBlock.class, org.bukkit.craftbukkit.block.impl.CraftDropper::new);
register(net.minecraft.world.level.block.EndRodBlock.class, org.bukkit.craftbukkit.block.impl.CraftEndRod::new);
register(net.minecraft.world.level.block.EnderChestBlock.class, org.bukkit.craftbukkit.block.impl.CraftEnderChest::new);
register(net.minecraft.world.level.block.EndPortalFrameBlock.class, org.bukkit.craftbukkit.block.impl.CraftEnderPortalFrame::new);
register(net.minecraft.world.level.block.FenceBlock.class, org.bukkit.craftbukkit.block.impl.CraftFence::new);
register(net.minecraft.world.level.block.FenceGateBlock.class, org.bukkit.craftbukkit.block.impl.CraftFenceGate::new);
register(net.minecraft.world.level.block.FireBlock.class, org.bukkit.craftbukkit.block.impl.CraftFire::new);
register(net.minecraft.world.level.block.StandingSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftFloorSign::new);
register(net.minecraft.world.level.block.LiquidBlock.class, org.bukkit.craftbukkit.block.impl.CraftFluids::new);
register(net.minecraft.world.level.block.FurnaceBlock.class, org.bukkit.craftbukkit.block.impl.CraftFurnaceFurace::new);
register(net.minecraft.world.level.block.GlazedTerracottaBlock.class, org.bukkit.craftbukkit.block.impl.CraftGlazedTerracotta::new);
register(net.minecraft.world.level.block.GrassBlock.class, org.bukkit.craftbukkit.block.impl.CraftGrass::new);
register(net.minecraft.world.level.block.GrindstoneBlock.class, org.bukkit.craftbukkit.block.impl.CraftGrindstone::new);
register(net.minecraft.world.level.block.HayBlock.class, org.bukkit.craftbukkit.block.impl.CraftHay::new);
register(net.minecraft.world.level.block.HopperBlock.class, org.bukkit.craftbukkit.block.impl.CraftHopper::new);
register(net.minecraft.world.level.block.HugeMushroomBlock.class, org.bukkit.craftbukkit.block.impl.CraftHugeMushroom::new);
register(net.minecraft.world.level.block.FrostedIceBlock.class, org.bukkit.craftbukkit.block.impl.CraftIceFrost::new);
register(net.minecraft.world.level.block.IronBarsBlock.class, org.bukkit.craftbukkit.block.impl.CraftIronBars::new);
register(net.minecraft.world.level.block.JigsawBlock.class, org.bukkit.craftbukkit.block.impl.CraftJigsaw::new);
register(net.minecraft.world.level.block.JukeboxBlock.class, org.bukkit.craftbukkit.block.impl.CraftJukeBox::new);
register(net.minecraft.world.level.block.KelpBlock.class, org.bukkit.craftbukkit.block.impl.CraftKelp::new);
register(net.minecraft.world.level.block.LadderBlock.class, org.bukkit.craftbukkit.block.impl.CraftLadder::new);
register(net.minecraft.world.level.block.LanternBlock.class, org.bukkit.craftbukkit.block.impl.CraftLantern::new);
register(net.minecraft.world.level.block.LeavesBlock.class, org.bukkit.craftbukkit.block.impl.CraftLeaves::new);
register(net.minecraft.world.level.block.LecternBlock.class, org.bukkit.craftbukkit.block.impl.CraftLectern::new);
register(net.minecraft.world.level.block.LeverBlock.class, org.bukkit.craftbukkit.block.impl.CraftLever::new);
register(net.minecraft.world.level.block.LoomBlock.class, org.bukkit.craftbukkit.block.impl.CraftLoom::new);
register(net.minecraft.world.level.block.DetectorRailBlock.class, org.bukkit.craftbukkit.block.impl.CraftMinecartDetector::new);
register(net.minecraft.world.level.block.RailBlock.class, org.bukkit.craftbukkit.block.impl.CraftMinecartTrack::new);
register(net.minecraft.world.level.block.MyceliumBlock.class, org.bukkit.craftbukkit.block.impl.CraftMycel::new);
register(net.minecraft.world.level.block.NetherWartBlock.class, org.bukkit.craftbukkit.block.impl.CraftNetherWart::new);
register(net.minecraft.world.level.block.NoteBlock.class, org.bukkit.craftbukkit.block.impl.CraftNote::new);
register(net.minecraft.world.level.block.ObserverBlock.class, org.bukkit.craftbukkit.block.impl.CraftObserver::new);
register(net.minecraft.world.level.block.NetherPortalBlock.class, org.bukkit.craftbukkit.block.impl.CraftPortal::new);
register(net.minecraft.world.level.block.PotatoBlock.class, org.bukkit.craftbukkit.block.impl.CraftPotatoes::new);
register(net.minecraft.world.level.block.PoweredRailBlock.class, org.bukkit.craftbukkit.block.impl.CraftPoweredRail::new);
register(net.minecraft.world.level.block.PressurePlateBlock.class, org.bukkit.craftbukkit.block.impl.CraftPressurePlateBinary::new);
register(net.minecraft.world.level.block.WeightedPressurePlateBlock.class, org.bukkit.craftbukkit.block.impl.CraftPressurePlateWeighted::new);
register(net.minecraft.world.level.block.CarvedPumpkinBlock.class, org.bukkit.craftbukkit.block.impl.CraftPumpkinCarved::new);
register(net.minecraft.world.level.block.ComparatorBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneComparator::new);
register(net.minecraft.world.level.block.RedstoneLampBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneLamp::new);
register(net.minecraft.world.level.block.RedStoneOreBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneOre::new);
register(net.minecraft.world.level.block.RedstoneTorchBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneTorch::new);
register(net.minecraft.world.level.block.RedstoneWallTorchBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneTorchWall::new);
register(net.minecraft.world.level.block.RedStoneWireBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneWire::new);
register(net.minecraft.world.level.block.SugarCaneBlock.class, org.bukkit.craftbukkit.block.impl.CraftReed::new);
register(net.minecraft.world.level.block.RepeaterBlock.class, org.bukkit.craftbukkit.block.impl.CraftRepeater::new);
register(net.minecraft.world.level.block.RespawnAnchorBlock.class, org.bukkit.craftbukkit.block.impl.CraftRespawnAnchor::new);
register(net.minecraft.world.level.block.RotatedPillarBlock.class, org.bukkit.craftbukkit.block.impl.CraftRotatable::new);
register(net.minecraft.world.level.block.SaplingBlock.class, org.bukkit.craftbukkit.block.impl.CraftSapling::new);
register(net.minecraft.world.level.block.ScaffoldingBlock.class, org.bukkit.craftbukkit.block.impl.CraftScaffolding::new);
register(net.minecraft.world.level.block.SeaPickleBlock.class, org.bukkit.craftbukkit.block.impl.CraftSeaPickle::new);
register(net.minecraft.world.level.block.ShulkerBoxBlock.class, org.bukkit.craftbukkit.block.impl.CraftShulkerBox::new);
register(net.minecraft.world.level.block.SkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftSkull::new);
register(net.minecraft.world.level.block.PlayerHeadBlock.class, org.bukkit.craftbukkit.block.impl.CraftSkullPlayer::new);
register(net.minecraft.world.level.block.PlayerWallHeadBlock.class, org.bukkit.craftbukkit.block.impl.CraftSkullPlayerWall::new);
register(net.minecraft.world.level.block.WallSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftSkullWall::new);
register(net.minecraft.world.level.block.SmokerBlock.class, org.bukkit.craftbukkit.block.impl.CraftSmoker::new);
register(net.minecraft.world.level.block.SnowLayerBlock.class, org.bukkit.craftbukkit.block.impl.CraftSnow::new);
register(net.minecraft.world.level.block.FarmBlock.class, org.bukkit.craftbukkit.block.impl.CraftSoil::new);
register(net.minecraft.world.level.block.StainedGlassPaneBlock.class, org.bukkit.craftbukkit.block.impl.CraftStainedGlassPane::new);
register(net.minecraft.world.level.block.StairBlock.class, org.bukkit.craftbukkit.block.impl.CraftStairs::new);
register(net.minecraft.world.level.block.StemBlock.class, org.bukkit.craftbukkit.block.impl.CraftStem::new);
register(net.minecraft.world.level.block.AttachedStemBlock.class, org.bukkit.craftbukkit.block.impl.CraftStemAttached::new);
register(net.minecraft.world.level.block.SlabBlock.class, org.bukkit.craftbukkit.block.impl.CraftStepAbstract::new);
register(net.minecraft.world.level.block.StonecutterBlock.class, org.bukkit.craftbukkit.block.impl.CraftStonecutter::new);
register(net.minecraft.world.level.block.StructureBlock.class, org.bukkit.craftbukkit.block.impl.CraftStructure::new);
register(net.minecraft.world.level.block.SweetBerryBushBlock.class, org.bukkit.craftbukkit.block.impl.CraftSweetBerryBush::new);
register(net.minecraft.world.level.block.TntBlock.class, org.bukkit.craftbukkit.block.impl.CraftTNT::new);
register(net.minecraft.world.level.block.DoublePlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftTallPlant::new);
register(net.minecraft.world.level.block.TallFlowerBlock.class, org.bukkit.craftbukkit.block.impl.CraftTallPlantFlower::new);
register(net.minecraft.world.level.block.TargetBlock.class, org.bukkit.craftbukkit.block.impl.CraftTarget::new);
register(net.minecraft.world.level.block.WallTorchBlock.class, org.bukkit.craftbukkit.block.impl.CraftTorchWall::new);
register(net.minecraft.world.level.block.TrapDoorBlock.class, org.bukkit.craftbukkit.block.impl.CraftTrapdoor::new);
register(net.minecraft.world.level.block.TripWireBlock.class, org.bukkit.craftbukkit.block.impl.CraftTripwire::new);
register(net.minecraft.world.level.block.TripWireHookBlock.class, org.bukkit.craftbukkit.block.impl.CraftTripwireHook::new);
register(net.minecraft.world.level.block.TurtleEggBlock.class, org.bukkit.craftbukkit.block.impl.CraftTurtleEgg::new);
register(net.minecraft.world.level.block.TwistingVinesBlock.class, org.bukkit.craftbukkit.block.impl.CraftTwistingVines::new);
register(net.minecraft.world.level.block.VineBlock.class, org.bukkit.craftbukkit.block.impl.CraftVine::new);
register(net.minecraft.world.level.block.WallSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallSign::new);
register(net.minecraft.world.level.block.WeepingVinesBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeepingVines::new);
register(net.minecraft.world.level.block.WitherSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkull::new);
register(net.minecraft.world.level.block.WitherWallSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkullWall::new);
register(net.minecraft.world.level.block.BrushableBlock.class, org.bukkit.craftbukkit.block.impl.CraftBrushable::new);
register(net.minecraft.world.level.block.CalibratedSculkSensorBlock.class, org.bukkit.craftbukkit.block.impl.CraftCalibratedSculkSensor::new);
register(net.minecraft.world.level.block.CampfireBlock.class, org.bukkit.craftbukkit.block.impl.CraftCampfire::new);
register(net.minecraft.world.level.block.CandleBlock.class, org.bukkit.craftbukkit.block.impl.CraftCandle::new);
register(net.minecraft.world.level.block.CandleCakeBlock.class, org.bukkit.craftbukkit.block.impl.CraftCandleCake::new);
register(net.minecraft.world.level.block.CarrotBlock.class, org.bukkit.craftbukkit.block.impl.CraftCarrot::new);
register(net.minecraft.world.level.block.CarvedPumpkinBlock.class, org.bukkit.craftbukkit.block.impl.CraftCarvedPumpkin::new);
register(net.minecraft.world.level.block.CaveVinesBlock.class, org.bukkit.craftbukkit.block.impl.CraftCaveVines::new);
register(net.minecraft.world.level.block.CaveVinesPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftCaveVinesPlant::new);
register(net.minecraft.world.level.block.CeilingHangingSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftCeilingHangingSign::new);
register(net.minecraft.world.level.block.ChainBlock.class, org.bukkit.craftbukkit.block.impl.CraftChain::new);
register(net.minecraft.world.level.block.ChestBlock.class, org.bukkit.craftbukkit.block.impl.CraftChest::new);
register(net.minecraft.world.level.block.ChiseledBookShelfBlock.class, org.bukkit.craftbukkit.block.impl.CraftChiseledBookShelf::new);
register(net.minecraft.world.level.block.ChorusFlowerBlock.class, org.bukkit.craftbukkit.block.impl.CraftChorusFlower::new);
register(net.minecraft.world.level.block.ChorusPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftChorusPlant::new);
register(net.minecraft.world.level.block.CocoaBlock.class, org.bukkit.craftbukkit.block.impl.CraftCocoa::new);
register(net.minecraft.world.level.block.CommandBlock.class, org.bukkit.craftbukkit.block.impl.CraftCommandBlock::new);
register(net.minecraft.world.level.block.ComparatorBlock.class, org.bukkit.craftbukkit.block.impl.CraftComparator::new);
register(net.minecraft.world.level.block.ComposterBlock.class, org.bukkit.craftbukkit.block.impl.CraftComposter::new);
register(net.minecraft.world.level.block.ConduitBlock.class, org.bukkit.craftbukkit.block.impl.CraftConduit::new);
register(net.minecraft.world.level.block.CopperBulbBlock.class, org.bukkit.craftbukkit.block.impl.CraftCopperBulb::new);
register(net.minecraft.world.level.block.CoralFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralFan::new);
register(net.minecraft.world.level.block.CoralPlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralPlant::new);
register(net.minecraft.world.level.block.CoralWallFanBlock.class, org.bukkit.craftbukkit.block.impl.CraftCoralWallFan::new);
register(net.minecraft.world.level.block.CrafterBlock.class, org.bukkit.craftbukkit.block.impl.CraftCrafter::new);
register(net.minecraft.world.level.block.CreakingHeartBlock.class, org.bukkit.craftbukkit.block.impl.CraftCreakingHeart::new);
register(net.minecraft.world.level.block.CropBlock.class, org.bukkit.craftbukkit.block.impl.CraftCrop::new);
register(net.minecraft.world.level.block.DaylightDetectorBlock.class, org.bukkit.craftbukkit.block.impl.CraftDaylightDetector::new);
register(net.minecraft.world.level.block.DecoratedPotBlock.class, org.bukkit.craftbukkit.block.impl.CraftDecoratedPot::new);
register(net.minecraft.world.level.block.DetectorRailBlock.class, org.bukkit.craftbukkit.block.impl.CraftDetectorRail::new);
register(net.minecraft.world.level.block.DispenserBlock.class, org.bukkit.craftbukkit.block.impl.CraftDispenser::new);
register(net.minecraft.world.level.block.DoorBlock.class, org.bukkit.craftbukkit.block.impl.CraftDoor::new);
register(net.minecraft.world.level.block.DoublePlantBlock.class, org.bukkit.craftbukkit.block.impl.CraftDoublePlant::new);
register(net.minecraft.world.level.block.DropperBlock.class, org.bukkit.craftbukkit.block.impl.CraftDropper::new);
register(net.minecraft.world.level.block.EndPortalFrameBlock.class, org.bukkit.craftbukkit.block.impl.CraftEndPortalFrame::new);
register(net.minecraft.world.level.block.EndRodBlock.class, org.bukkit.craftbukkit.block.impl.CraftEndRod::new);
register(net.minecraft.world.level.block.EnderChestBlock.class, org.bukkit.craftbukkit.block.impl.CraftEnderChest::new);
register(net.minecraft.world.level.block.FarmBlock.class, org.bukkit.craftbukkit.block.impl.CraftFarm::new);
register(net.minecraft.world.level.block.FenceBlock.class, org.bukkit.craftbukkit.block.impl.CraftFence::new);
register(net.minecraft.world.level.block.FenceGateBlock.class, org.bukkit.craftbukkit.block.impl.CraftFenceGate::new);
register(net.minecraft.world.level.block.FireBlock.class, org.bukkit.craftbukkit.block.impl.CraftFire::new);
register(net.minecraft.world.level.block.FlowerBedBlock.class, org.bukkit.craftbukkit.block.impl.CraftFlowerBed::new);
register(net.minecraft.world.level.block.FrostedIceBlock.class, org.bukkit.craftbukkit.block.impl.CraftFrostedIce::new);
register(net.minecraft.world.level.block.FurnaceBlock.class, org.bukkit.craftbukkit.block.impl.CraftFurnace::new);
register(net.minecraft.world.level.block.GlazedTerracottaBlock.class, org.bukkit.craftbukkit.block.impl.CraftGlazedTerracotta::new);
register(net.minecraft.world.level.block.GlowLichenBlock.class, org.bukkit.craftbukkit.block.impl.CraftGlowLichen::new);
register(net.minecraft.world.level.block.GrassBlock.class, org.bukkit.craftbukkit.block.impl.CraftGrass::new);
register(net.minecraft.world.level.block.GrindstoneBlock.class, org.bukkit.craftbukkit.block.impl.CraftGrindstone::new);
register(net.minecraft.world.level.block.HangingMossBlock.class, org.bukkit.craftbukkit.block.impl.CraftHangingMoss::new);
register(net.minecraft.world.level.block.HangingRootsBlock.class, org.bukkit.craftbukkit.block.impl.CraftHangingRoots::new);
register(net.minecraft.world.level.block.HayBlock.class, org.bukkit.craftbukkit.block.impl.CraftHay::new);
register(net.minecraft.world.level.block.HeavyCoreBlock.class, org.bukkit.craftbukkit.block.impl.CraftHeavyCore::new);
register(net.minecraft.world.level.block.HopperBlock.class, org.bukkit.craftbukkit.block.impl.CraftHopper::new);
register(net.minecraft.world.level.block.HugeMushroomBlock.class, org.bukkit.craftbukkit.block.impl.CraftHugeMushroom::new);
register(net.minecraft.world.level.block.InfestedRotatedPillarBlock.class, org.bukkit.craftbukkit.block.impl.CraftInfestedRotatedPillar::new);
register(net.minecraft.world.level.block.IronBarsBlock.class, org.bukkit.craftbukkit.block.impl.CraftIronBars::new);
register(net.minecraft.world.level.block.JigsawBlock.class, org.bukkit.craftbukkit.block.impl.CraftJigsaw::new);
register(net.minecraft.world.level.block.JukeboxBlock.class, org.bukkit.craftbukkit.block.impl.CraftJukebox::new);
register(net.minecraft.world.level.block.KelpBlock.class, org.bukkit.craftbukkit.block.impl.CraftKelp::new);
register(net.minecraft.world.level.block.LadderBlock.class, org.bukkit.craftbukkit.block.impl.CraftLadder::new);
register(net.minecraft.world.level.block.LanternBlock.class, org.bukkit.craftbukkit.block.impl.CraftLantern::new);
register(net.minecraft.world.level.block.LayeredCauldronBlock.class, org.bukkit.craftbukkit.block.impl.CraftLayeredCauldron::new);
register(net.minecraft.world.level.block.LeafLitterBlock.class, org.bukkit.craftbukkit.block.impl.CraftLeafLitter::new);
register(net.minecraft.world.level.block.LecternBlock.class, org.bukkit.craftbukkit.block.impl.CraftLectern::new);
register(net.minecraft.world.level.block.LeverBlock.class, org.bukkit.craftbukkit.block.impl.CraftLever::new);
register(net.minecraft.world.level.block.LightBlock.class, org.bukkit.craftbukkit.block.impl.CraftLight::new);
register(net.minecraft.world.level.block.LightningRodBlock.class, org.bukkit.craftbukkit.block.impl.CraftLightningRod::new);
register(net.minecraft.world.level.block.LiquidBlock.class, org.bukkit.craftbukkit.block.impl.CraftLiquid::new);
register(net.minecraft.world.level.block.LoomBlock.class, org.bukkit.craftbukkit.block.impl.CraftLoom::new);
register(net.minecraft.world.level.block.MangroveLeavesBlock.class, org.bukkit.craftbukkit.block.impl.CraftMangroveLeaves::new);
register(net.minecraft.world.level.block.MangrovePropaguleBlock.class, org.bukkit.craftbukkit.block.impl.CraftMangrovePropagule::new);
register(net.minecraft.world.level.block.MangroveRootsBlock.class, org.bukkit.craftbukkit.block.impl.CraftMangroveRoots::new);
register(net.minecraft.world.level.block.MossyCarpetBlock.class, org.bukkit.craftbukkit.block.impl.CraftMossyCarpet::new);
register(net.minecraft.world.level.block.MultifaceBlock.class, org.bukkit.craftbukkit.block.impl.CraftMultiface::new);
register(net.minecraft.world.level.block.ParticleLeavesBlock.class, org.bukkit.craftbukkit.block.impl.CraftParticleLeaves::new);
register(net.minecraft.world.level.block.MyceliumBlock.class, org.bukkit.craftbukkit.block.impl.CraftMycelium::new);
register(net.minecraft.world.level.block.NetherPortalBlock.class, org.bukkit.craftbukkit.block.impl.CraftNetherPortal::new);
register(net.minecraft.world.level.block.NetherWartBlock.class, org.bukkit.craftbukkit.block.impl.CraftNetherWart::new);
register(net.minecraft.world.level.block.NoteBlock.class, org.bukkit.craftbukkit.block.impl.CraftNoteBlock::new);
register(net.minecraft.world.level.block.ObserverBlock.class, org.bukkit.craftbukkit.block.impl.CraftObserver::new);
register(net.minecraft.world.level.block.PiglinWallSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftPiglinWallSkull::new);
register(net.minecraft.world.level.block.PinkPetalsBlock.class, org.bukkit.craftbukkit.block.impl.CraftPinkPetals::new);
register(net.minecraft.world.level.block.PitcherCropBlock.class, org.bukkit.craftbukkit.block.impl.CraftPitcherCrop::new);
register(net.minecraft.world.level.block.PlayerHeadBlock.class, org.bukkit.craftbukkit.block.impl.CraftPlayerHead::new);
register(net.minecraft.world.level.block.PlayerWallHeadBlock.class, org.bukkit.craftbukkit.block.impl.CraftPlayerWallHead::new);
register(net.minecraft.world.level.block.PointedDripstoneBlock.class, org.bukkit.craftbukkit.block.impl.CraftPointedDripstone::new);
register(net.minecraft.world.level.block.PotatoBlock.class, org.bukkit.craftbukkit.block.impl.CraftPotato::new);
register(net.minecraft.world.level.block.PoweredRailBlock.class, org.bukkit.craftbukkit.block.impl.CraftPoweredRail::new);
register(net.minecraft.world.level.block.PressurePlateBlock.class, org.bukkit.craftbukkit.block.impl.CraftPressurePlate::new);
register(net.minecraft.world.level.block.RailBlock.class, org.bukkit.craftbukkit.block.impl.CraftRail::new);
register(net.minecraft.world.level.block.RedStoneOreBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedStoneOre::new);
register(net.minecraft.world.level.block.RedStoneWireBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedStoneWire::new);
register(net.minecraft.world.level.block.RedstoneLampBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneLamp::new);
register(net.minecraft.world.level.block.RedstoneTorchBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneTorch::new);
register(net.minecraft.world.level.block.RedstoneWallTorchBlock.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneWallTorch::new);
register(net.minecraft.world.level.block.RepeaterBlock.class, org.bukkit.craftbukkit.block.impl.CraftRepeater::new);
register(net.minecraft.world.level.block.RespawnAnchorBlock.class, org.bukkit.craftbukkit.block.impl.CraftRespawnAnchor::new);
register(net.minecraft.world.level.block.RotatedPillarBlock.class, org.bukkit.craftbukkit.block.impl.CraftRotatedPillar::new);
register(net.minecraft.world.level.block.SaplingBlock.class, org.bukkit.craftbukkit.block.impl.CraftSapling::new);
register(net.minecraft.world.level.block.ScaffoldingBlock.class, org.bukkit.craftbukkit.block.impl.CraftScaffolding::new);
register(net.minecraft.world.level.block.SculkCatalystBlock.class, org.bukkit.craftbukkit.block.impl.CraftSculkCatalyst::new);
register(net.minecraft.world.level.block.SculkSensorBlock.class, org.bukkit.craftbukkit.block.impl.CraftSculkSensor::new);
register(net.minecraft.world.level.block.SculkShriekerBlock.class, org.bukkit.craftbukkit.block.impl.CraftSculkShrieker::new);
register(net.minecraft.world.level.block.SculkVeinBlock.class, org.bukkit.craftbukkit.block.impl.CraftSculkVein::new);
register(net.minecraft.world.level.block.SeaPickleBlock.class, org.bukkit.craftbukkit.block.impl.CraftSeaPickle::new);
register(net.minecraft.world.level.block.ShulkerBoxBlock.class, org.bukkit.craftbukkit.block.impl.CraftShulkerBox::new);
register(net.minecraft.world.level.block.SkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftSkull::new);
register(net.minecraft.world.level.block.SlabBlock.class, org.bukkit.craftbukkit.block.impl.CraftSlab::new);
register(net.minecraft.world.level.block.SmallDripleafBlock.class, org.bukkit.craftbukkit.block.impl.CraftSmallDripleaf::new);
register(net.minecraft.world.level.block.SmokerBlock.class, org.bukkit.craftbukkit.block.impl.CraftSmoker::new);
register(net.minecraft.world.level.block.SnifferEggBlock.class, org.bukkit.craftbukkit.block.impl.CraftSnifferEgg::new);
register(net.minecraft.world.level.block.SnowLayerBlock.class, org.bukkit.craftbukkit.block.impl.CraftSnowLayer::new);
register(net.minecraft.world.level.block.SnowyDirtBlock.class, org.bukkit.craftbukkit.block.impl.CraftSnowyDirt::new);
register(net.minecraft.world.level.block.StainedGlassPaneBlock.class, org.bukkit.craftbukkit.block.impl.CraftStainedGlassPane::new);
register(net.minecraft.world.level.block.StairBlock.class, org.bukkit.craftbukkit.block.impl.CraftStair::new);
register(net.minecraft.world.level.block.StandingSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftStandingSign::new);
register(net.minecraft.world.level.block.StemBlock.class, org.bukkit.craftbukkit.block.impl.CraftStem::new);
register(net.minecraft.world.level.block.StonecutterBlock.class, org.bukkit.craftbukkit.block.impl.CraftStonecutter::new);
register(net.minecraft.world.level.block.StructureBlock.class, org.bukkit.craftbukkit.block.impl.CraftStructureBlock::new);
register(net.minecraft.world.level.block.SugarCaneBlock.class, org.bukkit.craftbukkit.block.impl.CraftSugarCane::new);
register(net.minecraft.world.level.block.SweetBerryBushBlock.class, org.bukkit.craftbukkit.block.impl.CraftSweetBerryBush::new);
register(net.minecraft.world.level.block.TallFlowerBlock.class, org.bukkit.craftbukkit.block.impl.CraftTallFlower::new);
register(net.minecraft.world.level.block.TallSeagrassBlock.class, org.bukkit.craftbukkit.block.impl.CraftTallSeagrass::new);
register(net.minecraft.world.level.block.TargetBlock.class, org.bukkit.craftbukkit.block.impl.CraftTarget::new);
register(net.minecraft.world.level.block.TestBlock.class, org.bukkit.craftbukkit.block.impl.CraftTestBlock::new);
register(net.minecraft.world.level.block.TintedParticleLeavesBlock.class, org.bukkit.craftbukkit.block.impl.CraftTintedParticleLeaves::new);
register(net.minecraft.world.level.block.TntBlock.class, org.bukkit.craftbukkit.block.impl.CraftTnt::new);
register(net.minecraft.world.level.block.TorchflowerCropBlock.class, org.bukkit.craftbukkit.block.impl.CraftTorchflowerCrop::new);
register(net.minecraft.world.level.block.TrapDoorBlock.class, org.bukkit.craftbukkit.block.impl.CraftTrapDoor::new);
register(net.minecraft.world.level.block.TrappedChestBlock.class, org.bukkit.craftbukkit.block.impl.CraftTrappedChest::new);
register(net.minecraft.world.level.block.TrialSpawnerBlock.class, org.bukkit.craftbukkit.block.impl.CraftTrialSpawner::new);
register(net.minecraft.world.level.block.TripWireBlock.class, org.bukkit.craftbukkit.block.impl.CraftTripWire::new);
register(net.minecraft.world.level.block.TripWireHookBlock.class, org.bukkit.craftbukkit.block.impl.CraftTripWireHook::new);
register(net.minecraft.world.level.block.TurtleEggBlock.class, org.bukkit.craftbukkit.block.impl.CraftTurtleEgg::new);
register(net.minecraft.world.level.block.TwistingVinesBlock.class, org.bukkit.craftbukkit.block.impl.CraftTwistingVines::new);
register(net.minecraft.world.level.block.UntintedParticleLeavesBlock.class, org.bukkit.craftbukkit.block.impl.CraftUntintedParticleLeaves::new);
register(net.minecraft.world.level.block.VaultBlock.class, org.bukkit.craftbukkit.block.impl.CraftVault::new);
register(net.minecraft.world.level.block.VineBlock.class, org.bukkit.craftbukkit.block.impl.CraftVine::new);
register(net.minecraft.world.level.block.WallBannerBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallBanner::new);
register(net.minecraft.world.level.block.WallBlock.class, org.bukkit.craftbukkit.block.impl.CraftWall::new);
register(net.minecraft.world.level.block.WallHangingSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallHangingSign::new);
register(net.minecraft.world.level.block.WallSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallSign::new);
register(net.minecraft.world.level.block.WallSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallSkull::new);
register(net.minecraft.world.level.block.WallTorchBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallTorch::new);
register(net.minecraft.world.level.block.WaterloggedTransparentBlock.class, org.bukkit.craftbukkit.block.impl.CraftWaterloggedTransparent::new);
register(net.minecraft.world.level.block.WeatheringCopperBulbBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeatheringCopperBulb::new);
register(net.minecraft.world.level.block.WeatheringCopperDoorBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeatheringCopperDoor::new);
@@ -538,9 +534,14 @@ public class CraftBlockData implements BlockData {
register(net.minecraft.world.level.block.WeatheringCopperSlabBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeatheringCopperSlab::new);
register(net.minecraft.world.level.block.WeatheringCopperStairBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeatheringCopperStair::new);
register(net.minecraft.world.level.block.WeatheringCopperTrapDoorBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeatheringCopperTrapDoor::new);
register(net.minecraft.world.level.block.piston.PistonBaseBlock.class, org.bukkit.craftbukkit.block.impl.CraftPiston::new);
register(net.minecraft.world.level.block.piston.PistonHeadBlock.class, org.bukkit.craftbukkit.block.impl.CraftPistonExtension::new);
register(net.minecraft.world.level.block.piston.MovingPistonBlock.class, org.bukkit.craftbukkit.block.impl.CraftPistonMoving::new);
register(net.minecraft.world.level.block.WeepingVinesBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeepingVines::new);
register(net.minecraft.world.level.block.WeightedPressurePlateBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeightedPressurePlate::new);
register(net.minecraft.world.level.block.WitherSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkull::new);
register(net.minecraft.world.level.block.WitherWallSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftWitherWallSkull::new);
register(net.minecraft.world.level.block.piston.MovingPistonBlock.class, org.bukkit.craftbukkit.block.impl.CraftMovingPiston::new);
register(net.minecraft.world.level.block.piston.PistonBaseBlock.class, org.bukkit.craftbukkit.block.impl.CraftPistonBase::new);
register(net.minecraft.world.level.block.piston.PistonHeadBlock.class, org.bukkit.craftbukkit.block.impl.CraftPistonHead::new);
// End generate - CraftBlockData#MAP
//</editor-fold>
}
@@ -612,7 +613,7 @@ public class CraftBlockData implements BlockData {
// Paper start - optimize creating BlockData to not need a map lookup
static {
// Initialize cached data for all IBlockData instances after registration
// Initialize cached data for all BlockState instances after registration
Block.BLOCK_STATE_REGISTRY.iterator().forEachRemaining(net.minecraft.world.level.block.state.BlockState::createCraftBlockData);
}
public static CraftBlockData fromData(net.minecraft.world.level.block.state.BlockState data) {

View File

@@ -1,23 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Brushable;
public abstract class CraftBrushable extends CraftBlockData implements Brushable {
private static final net.minecraft.world.level.block.state.properties.IntegerProperty DUSTED = getInteger("dusted");
@Override
public int getDusted() {
return this.get(CraftBrushable.DUSTED);
}
@Override
public void setDusted(int dusted) {
this.set(CraftBrushable.DUSTED, dusted);
}
@Override
public int getMaximumDusted() {
return getMax(CraftBrushable.DUSTED);
}
}

View File

@@ -1,23 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Directional;
public abstract class CraftDirectional extends CraftBlockData implements Directional {
private static final net.minecraft.world.level.block.state.properties.EnumProperty<?> FACING = getEnum("facing");
@Override
public org.bukkit.block.BlockFace getFacing() {
return this.get(CraftDirectional.FACING, org.bukkit.block.BlockFace.class);
}
@Override
public void setFacing(org.bukkit.block.BlockFace facing) {
this.set(CraftDirectional.FACING, facing);
}
@Override
public java.util.Set<org.bukkit.block.BlockFace> getFaces() {
return this.getValues(CraftDirectional.FACING, org.bukkit.block.BlockFace.class);
}
}

View File

@@ -1,18 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.FaceAttachable;
public abstract class CraftFaceAttachable extends CraftBlockData implements FaceAttachable {
private static final net.minecraft.world.level.block.state.properties.EnumProperty<?> ATTACH_FACE = getEnum("face");
@Override
public org.bukkit.block.data.FaceAttachable.AttachedFace getAttachedFace() {
return this.get(CraftFaceAttachable.ATTACH_FACE, org.bukkit.block.data.FaceAttachable.AttachedFace.class);
}
@Override
public void setAttachedFace(org.bukkit.block.data.FaceAttachable.AttachedFace face) {
this.set(CraftFaceAttachable.ATTACH_FACE, face);
}
}

View File

@@ -1,18 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Hangable;
public abstract class CraftHangable extends CraftBlockData implements Hangable {
private static final net.minecraft.world.level.block.state.properties.BooleanProperty HANGING = getBoolean("hanging");
@Override
public boolean isHanging() {
return this.get(CraftHangable.HANGING);
}
@Override
public void setHanging(boolean hanging) {
this.set(CraftHangable.HANGING, hanging);
}
}

View File

@@ -1,23 +0,0 @@
package org.bukkit.craftbukkit.block.data;
import org.bukkit.block.data.Hatchable;
public abstract class CraftHatchable extends CraftBlockData implements Hatchable {
private static final net.minecraft.world.level.block.state.properties.IntegerProperty HATCH = getInteger("hatch");
@Override
public int getHatch() {
return this.get(CraftHatchable.HATCH);
}
@Override
public void setHatch(int hatch) {
this.set(CraftHatchable.HATCH, hatch);
}
@Override
public int getMaximumHatch() {
return getMax(CraftHatchable.HATCH);
}
}

Some files were not shown because too many files have changed in this diff Show More