Remap CraftBukkit to Mojang+Yarn Mappings

By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:55 +01:00
parent a265d64138
commit 30e4583dbe
1780 changed files with 44628 additions and 41274 deletions

View File

@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.decoration.PaintingVariant;
import org.bukkit.Art;
@@ -21,7 +20,7 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
}
public static Art minecraftHolderToBukkit(Holder<PaintingVariant> minecraft) {
return minecraftToBukkit(minecraft.value());
return CraftArt.minecraftToBukkit(minecraft.value());
}
public static PaintingVariant bukkitToMinecraft(Art bukkit) {
@@ -31,9 +30,9 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
public static Holder<PaintingVariant> bukkitToMinecraftHolder(Art bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<PaintingVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT);
net.minecraft.core.Registry<PaintingVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<PaintingVariant> holder) {
if (registry.wrapAsHolder(CraftArt.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<PaintingVariant> holder) {
return holder;
}
@@ -58,55 +57,55 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
} else {
this.name = key.toString();
}
this.ordinal = count++;
this.ordinal = CraftArt.count++;
}
@Override
public PaintingVariant getHandle() {
return paintingVariant;
return this.paintingVariant;
}
@Override
public int getBlockWidth() {
return paintingVariant.width();
return this.paintingVariant.width();
}
@Override
public int getBlockHeight() {
return paintingVariant.height();
return this.paintingVariant.height();
}
@Override
public int getId() {
return CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).getId(paintingVariant);
return CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).getId(this.paintingVariant);
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
public int compareTo(@NotNull Art art) {
return ordinal - art.ordinal();
return this.ordinal - art.ordinal();
}
@NotNull
@Override
public String name() {
return name;
return this.name;
}
@Override
public int ordinal() {
return ordinal;
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return name();
return this.name();
}
@Override
@@ -119,11 +118,11 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
return false;
}
return getKey().equals(otherArt.getKey());
return this.getKey().equals(otherArt.getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
}

View File

@@ -9,33 +9,31 @@ import java.util.Objects;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.SectionPosition;
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.DynamicOpsNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.level.WorldServer;
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.ChunkCoordIntPair;
import net.minecraft.world.level.EnumSkyBlock;
import net.minecraft.world.level.biome.BiomeBase;
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.block.state.IBlockData;
import net.minecraft.world.level.chunk.ChunkSection;
import net.minecraft.world.level.chunk.DataPaletteBlock;
import net.minecraft.world.level.chunk.IChunkAccess;
import net.minecraft.world.level.chunk.NibbleArray;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.DataLayer;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
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.ProtoChunkExtension;
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.SeededRandom;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
@@ -55,20 +53,20 @@ import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.plugin.Plugin;
public class CraftChunk implements Chunk {
private final WorldServer worldServer;
private final ServerLevel worldServer;
private final int x;
private final int z;
private static final DataPaletteBlock<IBlockData> emptyBlockIDs = new DataPaletteBlock<>(net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), DataPaletteBlock.d.SECTION_STATES);
private static final PalettedContainer<net.minecraft.world.level.block.state.BlockState> emptyBlockIDs = new PalettedContainer<>(net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
private static final byte[] FULL_LIGHT = new byte[2048];
private static final byte[] EMPTY_LIGHT = new byte[2048];
public CraftChunk(net.minecraft.world.level.chunk.Chunk chunk) {
worldServer = chunk.level;
x = chunk.getPos().x;
z = chunk.getPos().z;
public CraftChunk(net.minecraft.world.level.chunk.LevelChunk chunk) {
this.worldServer = chunk.level;
this.x = chunk.getPos().x;
this.z = chunk.getPos().z;
}
public CraftChunk(WorldServer worldServer, int x, int z) {
public CraftChunk(ServerLevel worldServer, int x, int z) {
this.worldServer = worldServer;
this.x = x;
this.z = z;
@@ -76,18 +74,18 @@ public class CraftChunk implements Chunk {
@Override
public World getWorld() {
return worldServer.getWorld();
return this.worldServer.getWorld();
}
public CraftWorld getCraftWorld() {
return (CraftWorld) getWorld();
return (CraftWorld) this.getWorld();
}
public IChunkAccess getHandle(ChunkStatus chunkStatus) {
IChunkAccess chunkAccess = worldServer.getChunk(x, z, chunkStatus);
public ChunkAccess getHandle(ChunkStatus chunkStatus) {
ChunkAccess chunkAccess = this.worldServer.getChunk(this.x, this.z, chunkStatus);
// SPIGOT-7332: Get unwrapped extension
if (chunkAccess instanceof ProtoChunkExtension extension) {
if (chunkAccess instanceof ImposterProtoChunk extension) {
return extension.getWrapped();
}
@@ -96,42 +94,42 @@ public class CraftChunk implements Chunk {
@Override
public int getX() {
return x;
return this.x;
}
@Override
public int getZ() {
return z;
return this.z;
}
@Override
public String toString() {
return "CraftChunk{" + "x=" + getX() + "z=" + getZ() + '}';
return "CraftChunk{" + "x=" + this.getX() + "z=" + this.getZ() + '}';
}
@Override
public Block getBlock(int x, int y, int z) {
validateChunkCoordinates(worldServer.getMinY(), worldServer.getMaxY(), x, y, z);
CraftChunk.validateChunkCoordinates(this.worldServer.getMinY(), this.worldServer.getMaxY(), x, y, z);
return new CraftBlock(worldServer, new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z));
return new CraftBlock(this.worldServer, new BlockPos((this.x << 4) | x, y, (this.z << 4) | z));
}
@Override
public boolean isEntitiesLoaded() {
return getCraftWorld().getHandle().entityManager.areEntitiesLoaded(ChunkCoordIntPair.asLong(x, z));
return this.getCraftWorld().getHandle().entityManager.areEntitiesLoaded(ChunkPos.asLong(this.x, this.z));
}
@Override
public Entity[] getEntities() {
if (!isLoaded()) {
getWorld().getChunkAt(x, z); // Transient load for this tick
if (!this.isLoaded()) {
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
}
PersistentEntitySectionManager<net.minecraft.world.entity.Entity> entityManager = getCraftWorld().getHandle().entityManager;
long pair = ChunkCoordIntPair.asLong(x, z);
PersistentEntitySectionManager<net.minecraft.world.entity.Entity> entityManager = this.getCraftWorld().getHandle().entityManager;
long pair = ChunkPos.asLong(this.x, this.z);
if (entityManager.areEntitiesLoaded(pair)) {
return entityManager.getEntities(new ChunkCoordIntPair(x, z)).stream()
return entityManager.getEntities(new ChunkPos(this.x, this.z)).stream()
.map(net.minecraft.world.entity.Entity::getBukkitEntity)
.filter(Objects::nonNull).toArray(Entity[]::new);
}
@@ -169,23 +167,23 @@ public class CraftChunk implements Chunk {
}
}
return entityManager.getEntities(new ChunkCoordIntPair(x, z)).stream()
return entityManager.getEntities(new ChunkPos(this.x, this.z)).stream()
.map(net.minecraft.world.entity.Entity::getBukkitEntity)
.filter(Objects::nonNull).toArray(Entity[]::new);
}
@Override
public BlockState[] getTileEntities() {
if (!isLoaded()) {
getWorld().getChunkAt(x, z); // Transient load for this tick
if (!this.isLoaded()) {
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
}
int index = 0;
IChunkAccess chunk = getHandle(ChunkStatus.FULL);
ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
BlockState[] entities = new BlockState[chunk.blockEntities.size()];
for (BlockPosition position : chunk.blockEntities.keySet()) {
entities[index++] = worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
for (BlockPos position : chunk.blockEntities.keySet()) {
entities[index++] = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
}
return entities;
@@ -193,84 +191,84 @@ public class CraftChunk implements Chunk {
@Override
public boolean isGenerated() {
IChunkAccess chunk = getHandle(ChunkStatus.EMPTY);
ChunkAccess chunk = this.getHandle(ChunkStatus.EMPTY);
return chunk.getPersistedStatus().isOrAfter(ChunkStatus.FULL);
}
@Override
public boolean isLoaded() {
return getWorld().isChunkLoaded(this);
return this.getWorld().isChunkLoaded(this);
}
@Override
public boolean load() {
return getWorld().loadChunk(getX(), getZ(), true);
return this.getWorld().loadChunk(this.getX(), this.getZ(), true);
}
@Override
public boolean load(boolean generate) {
return getWorld().loadChunk(getX(), getZ(), generate);
return this.getWorld().loadChunk(this.getX(), this.getZ(), generate);
}
@Override
public boolean unload() {
return getWorld().unloadChunk(getX(), getZ());
return this.getWorld().unloadChunk(this.getX(), this.getZ());
}
@Override
public boolean isSlimeChunk() {
// 987234911L is deterimined in EntitySlime when seeing if a slime can spawn in a chunk
return SeededRandom.seedSlimeChunk(getX(), getZ(), getWorld().getSeed(), 987234911L).nextInt(10) == 0;
return WorldgenRandom.seedSlimeChunk(this.getX(), this.getZ(), this.getWorld().getSeed(), 987234911L).nextInt(10) == 0;
}
@Override
public boolean unload(boolean save) {
return getWorld().unloadChunk(getX(), getZ(), save);
return this.getWorld().unloadChunk(this.getX(), this.getZ(), save);
}
@Override
public boolean isForceLoaded() {
return getWorld().isChunkForceLoaded(getX(), getZ());
return this.getWorld().isChunkForceLoaded(this.getX(), this.getZ());
}
@Override
public void setForceLoaded(boolean forced) {
getWorld().setChunkForceLoaded(getX(), getZ(), forced);
this.getWorld().setChunkForceLoaded(this.getX(), this.getZ(), forced);
}
@Override
public boolean addPluginChunkTicket(Plugin plugin) {
return getWorld().addPluginChunkTicket(getX(), getZ(), plugin);
return this.getWorld().addPluginChunkTicket(this.getX(), this.getZ(), plugin);
}
@Override
public boolean removePluginChunkTicket(Plugin plugin) {
return getWorld().removePluginChunkTicket(getX(), getZ(), plugin);
return this.getWorld().removePluginChunkTicket(this.getX(), this.getZ(), plugin);
}
@Override
public Collection<Plugin> getPluginChunkTickets() {
return getWorld().getPluginChunkTickets(getX(), getZ());
return this.getWorld().getPluginChunkTickets(this.getX(), this.getZ());
}
@Override
public long getInhabitedTime() {
return getHandle(ChunkStatus.EMPTY).getInhabitedTime();
return this.getHandle(ChunkStatus.EMPTY).getInhabitedTime();
}
@Override
public void setInhabitedTime(long ticks) {
Preconditions.checkArgument(ticks >= 0, "ticks cannot be negative");
getHandle(ChunkStatus.STRUCTURE_STARTS).setInhabitedTime(ticks);
this.getHandle(ChunkStatus.STRUCTURE_STARTS).setInhabitedTime(ticks);
}
@Override
public boolean contains(BlockData block) {
Preconditions.checkArgument(block != null, "Block cannot be null");
Predicate<IBlockData> nms = Predicates.equalTo(((CraftBlockData) block).getState());
for (ChunkSection section : getHandle(ChunkStatus.FULL).getSections()) {
Predicate<net.minecraft.world.level.block.state.BlockState> nms = Predicates.equalTo(((CraftBlockData) block).getState());
for (LevelChunkSection section : this.getHandle(ChunkStatus.FULL).getSections()) {
if (section != null && section.getStates().maybeHas(nms)) {
return true;
}
@@ -283,9 +281,9 @@ public class CraftChunk implements Chunk {
public boolean contains(Biome biome) {
Preconditions.checkArgument(biome != null, "Biome cannot be null");
IChunkAccess chunk = getHandle(ChunkStatus.BIOMES);
Predicate<Holder<BiomeBase>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
for (ChunkSection section : chunk.getSections()) {
ChunkAccess chunk = this.getHandle(ChunkStatus.BIOMES);
Predicate<Holder<net.minecraft.world.level.biome.Biome>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
for (LevelChunkSection section : chunk.getSections()) {
if (section != null && section.getBiomes().maybeHas(nms)) {
return true;
}
@@ -296,71 +294,71 @@ public class CraftChunk implements Chunk {
@Override
public ChunkSnapshot getChunkSnapshot() {
return getChunkSnapshot(true, false, false);
return this.getChunkSnapshot(true, false, false);
}
@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain) {
IChunkAccess chunk = getHandle(ChunkStatus.FULL);
ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
ChunkSection[] cs = chunk.getSections();
DataPaletteBlock[] sectionBlockIDs = new DataPaletteBlock[cs.length];
LevelChunkSection[] cs = chunk.getSections();
PalettedContainer[] sectionBlockIDs = new PalettedContainer[cs.length];
byte[][] sectionSkyLights = new byte[cs.length][];
byte[][] sectionEmitLights = new byte[cs.length][];
boolean[] sectionEmpty = new boolean[cs.length];
PalettedContainerRO<Holder<BiomeBase>>[] biome = (includeBiome || includeBiomeTempRain) ? new DataPaletteBlock[cs.length] : null;
PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>[] biome = (includeBiome || includeBiomeTempRain) ? new PalettedContainer[cs.length] : null;
IRegistry<BiomeBase> iregistry = worldServer.registryAccess().lookupOrThrow(Registries.BIOME);
Codec<PalettedContainerRO<Holder<BiomeBase>>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
Registry<net.minecraft.world.level.biome.Biome> iregistry = this.worldServer.registryAccess().lookupOrThrow(Registries.BIOME);
Codec<PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>>> biomeCodec = PalettedContainer.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
for (int i = 0; i < cs.length; i++) {
NBTTagCompound data = new NBTTagCompound();
CompoundTag data = new CompoundTag();
data.put("block_states", SerializableChunkData.BLOCK_STATE_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getStates()).getOrThrow());
sectionBlockIDs[i] = SerializableChunkData.BLOCK_STATE_CODEC.parse(DynamicOpsNBT.INSTANCE, data.getCompound("block_states")).getOrThrow(SerializableChunkData.a::new);
data.put("block_states", SerializableChunkData.BLOCK_STATE_CODEC.encodeStart(NbtOps.INSTANCE, cs[i].getStates()).getOrThrow());
sectionBlockIDs[i] = SerializableChunkData.BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, data.getCompound("block_states")).getOrThrow(SerializableChunkData.ChunkReadException::new);
sectionEmpty[i] = cs[i].hasOnlyAir();
LevelLightEngine lightengine = worldServer.getLightEngine();
NibbleArray skyLightArray = lightengine.getLayerListener(EnumSkyBlock.SKY).getDataLayerData(SectionPosition.of(x, chunk.getSectionYFromSectionIndex(i), z)); // SPIGOT-7498: Convert section index
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] = worldServer.dimensionType().hasSkyLight() ? FULL_LIGHT : EMPTY_LIGHT;
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);
}
NibbleArray emitLightArray = lightengine.getLayerListener(EnumSkyBlock.BLOCK).getDataLayerData(SectionPosition.of(x, chunk.getSectionYFromSectionIndex(i), z)); // SPIGOT-7498: Convert section index
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] = EMPTY_LIGHT;
sectionEmitLights[i] = CraftChunk.EMPTY_LIGHT;
} else {
sectionEmitLights[i] = new byte[2048];
System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
}
if (biome != null) {
data.put("biomes", biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getBiomes()).getOrThrow());
biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).getOrThrow(SerializableChunkData.a::new);
data.put("biomes", biomeCodec.encodeStart(NbtOps.INSTANCE, cs[i].getBiomes()).getOrThrow());
biome[i] = biomeCodec.parse(NbtOps.INSTANCE, data.getCompound("biomes")).getOrThrow(SerializableChunkData.ChunkReadException::new);
}
}
HeightMap hmap = null;
Heightmap hmap = null;
if (includeMaxBlockY) {
hmap = new HeightMap(chunk, HeightMap.Type.MOTION_BLOCKING);
hmap.setRawData(chunk, HeightMap.Type.MOTION_BLOCKING, chunk.heightmaps.get(HeightMap.Type.MOTION_BLOCKING).getRawData());
hmap = new Heightmap(chunk, Heightmap.Types.MOTION_BLOCKING);
hmap.setRawData(chunk, Heightmap.Types.MOTION_BLOCKING, chunk.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).getRawData());
}
World world = getWorld();
return new CraftChunkSnapshot(getX(), getZ(), chunk.getMinY(), chunk.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, iregistry, biome);
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);
}
@Override
public PersistentDataContainer getPersistentDataContainer() {
return getHandle(ChunkStatus.STRUCTURE_STARTS).persistentDataContainer;
return this.getHandle(ChunkStatus.STRUCTURE_STARTS).persistentDataContainer;
}
@Override
public LoadLevel getLoadLevel() {
net.minecraft.world.level.chunk.Chunk chunk = worldServer.getChunkIfLoaded(getX(), getZ());
net.minecraft.world.level.chunk.LevelChunk chunk = this.worldServer.getChunkIfLoaded(this.getX(), this.getZ());
if (chunk == null) {
return LoadLevel.UNLOADED;
}
@@ -369,64 +367,64 @@ public class CraftChunk implements Chunk {
@Override
public Collection<GeneratedStructure> getStructures() {
return getCraftWorld().getStructures(getX(), getZ());
return this.getCraftWorld().getStructures(this.getX(), this.getZ());
}
@Override
public Collection<GeneratedStructure> getStructures(Structure structure) {
return getCraftWorld().getStructures(getX(), getZ(), structure);
return this.getCraftWorld().getStructures(this.getX(), this.getZ(), structure);
}
@Override
public Collection<Player> getPlayersSeeingChunk() {
return getWorld().getPlayersSeeingChunk(this);
return this.getWorld().getPlayersSeeingChunk(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (o == null || this.getClass() != o.getClass()) return false;
CraftChunk that = (CraftChunk) o;
if (x != that.x) return false;
if (z != that.z) return false;
return worldServer.equals(that.worldServer);
if (this.x != that.x) return false;
if (this.z != that.z) return false;
return this.worldServer.equals(that.worldServer);
}
@Override
public int hashCode() {
int result = worldServer.hashCode();
result = 31 * result + x;
result = 31 * result + z;
int result = this.worldServer.hashCode();
result = 31 * result + this.x;
result = 31 * result + this.z;
return result;
}
public static ChunkSnapshot getEmptyChunkSnapshot(int x, int z, CraftWorld world, boolean includeBiome, boolean includeBiomeTempRain) {
IChunkAccess actual = world.getHandle().getChunk(x, z, (includeBiome || includeBiomeTempRain) ? ChunkStatus.BIOMES : ChunkStatus.EMPTY);
ChunkAccess actual = world.getHandle().getChunk(x, z, (includeBiome || includeBiomeTempRain) ? ChunkStatus.BIOMES : ChunkStatus.EMPTY);
/* Fill with empty data */
int hSection = actual.getSectionsCount();
DataPaletteBlock[] blockIDs = new DataPaletteBlock[hSection];
PalettedContainer[] blockIDs = new PalettedContainer[hSection];
byte[][] skyLight = new byte[hSection][];
byte[][] emitLight = new byte[hSection][];
boolean[] empty = new boolean[hSection];
IRegistry<BiomeBase> iregistry = world.getHandle().registryAccess().lookupOrThrow(Registries.BIOME);
DataPaletteBlock<Holder<BiomeBase>>[] biome = (includeBiome || includeBiomeTempRain) ? new DataPaletteBlock[hSection] : null;
Codec<PalettedContainerRO<Holder<BiomeBase>>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
Registry<net.minecraft.world.level.biome.Biome> iregistry = 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));
for (int i = 0; i < hSection; i++) {
blockIDs[i] = emptyBlockIDs;
skyLight[i] = world.getHandle().dimensionType().hasSkyLight() ? FULL_LIGHT : EMPTY_LIGHT;
emitLight[i] = EMPTY_LIGHT;
blockIDs[i] = CraftChunk.emptyBlockIDs;
skyLight[i] = world.getHandle().dimensionType().hasSkyLight() ? CraftChunk.FULL_LIGHT : CraftChunk.EMPTY_LIGHT;
emitLight[i] = CraftChunk.EMPTY_LIGHT;
empty[i] = true;
if (biome != null) {
biome[i] = (DataPaletteBlock<Holder<BiomeBase>>) biomeCodec.parse(DynamicOpsNBT.INSTANCE, biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, actual.getSection(i).getBiomes()).getOrThrow()).getOrThrow(SerializableChunkData.a::new);
biome[i] = (PalettedContainer<Holder<net.minecraft.world.level.biome.Biome>>) biomeCodec.parse(NbtOps.INSTANCE, biomeCodec.encodeStart(NbtOps.INSTANCE, actual.getSection(i).getBiomes()).getOrThrow()).getOrThrow(SerializableChunkData.ChunkReadException::new);
}
}
return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxHeight(), world.getSeaLevel(), world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new HeightMap(actual, HeightMap.Type.MOTION_BLOCKING), iregistry, biome);
return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxHeight(), world.getSeaLevel(), world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new Heightmap(actual, Heightmap.Types.MOTION_BLOCKING), iregistry, biome);
}
static void validateChunkCoordinates(int minY, int maxY, int x, int y, int z) {

View File

@@ -3,14 +3,13 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import java.util.function.Predicate;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.chunk.DataPaletteBlock;
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;
import net.minecraft.world.level.levelgen.HeightMap;
import net.minecraft.world.level.levelgen.Heightmap;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Material;
import org.bukkit.block.Biome;
@@ -28,16 +27,16 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
private final int x, z;
private final int minHeight, maxHeight, seaLevel;
private final String worldname;
private final DataPaletteBlock<IBlockData>[] blockids;
private final PalettedContainer<BlockState>[] blockids;
private final byte[][] skylight;
private final byte[][] emitlight;
private final boolean[] empty;
private final HeightMap hmap; // Height map
private final Heightmap hmap; // Height map
private final long captureFulltime;
private final IRegistry<BiomeBase> biomeRegistry;
private final PalettedContainerRO<Holder<BiomeBase>>[] biome;
private final Registry<net.minecraft.world.level.biome.Biome> biomeRegistry;
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, DataPaletteBlock<IBlockData>[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, HeightMap hmap, IRegistry<BiomeBase> biomeRegistry, PalettedContainerRO<Holder<BiomeBase>>[] 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) {
this.x = x;
this.z = z;
this.minHeight = minHeight;
@@ -56,25 +55,25 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override
public int getX() {
return x;
return this.x;
}
@Override
public int getZ() {
return z;
return this.z;
}
@Override
public String getWorldName() {
return worldname;
return this.worldname;
}
@Override
public boolean contains(BlockData block) {
Preconditions.checkArgument(block != null, "Block cannot be null");
Predicate<IBlockData> nms = Predicates.equalTo(((CraftBlockData) block).getState());
for (DataPaletteBlock<IBlockData> palette : blockids) {
Predicate<BlockState> nms = Predicates.equalTo(((CraftBlockData) block).getState());
for (PalettedContainer<BlockState> palette : this.blockids) {
if (palette.maybeHas(nms)) {
return true;
}
@@ -87,8 +86,8 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
public boolean contains(Biome biome) {
Preconditions.checkArgument(biome != null, "Biome cannot be null");
Predicate<Holder<BiomeBase>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
for (PalettedContainerRO<Holder<BiomeBase>> palette : this.biome) {
Predicate<Holder<net.minecraft.world.level.biome.Biome>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
for (PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>> palette : this.biome) {
if (palette.maybeHas(nms)) {
return true;
}
@@ -99,92 +98,92 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override
public Material getBlockType(int x, int y, int z) {
validateChunkCoordinates(x, y, z);
this.validateChunkCoordinates(x, y, z);
return CraftBlockType.minecraftToBukkit(blockids[getSectionIndex(y)].get(x, y & 0xF, z).getBlock());
return CraftBlockType.minecraftToBukkit(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBlock());
}
@Override
public final BlockData getBlockData(int x, int y, int z) {
validateChunkCoordinates(x, y, z);
this.validateChunkCoordinates(x, y, z);
return CraftBlockData.fromData(blockids[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) {
validateChunkCoordinates(x, y, z);
this.validateChunkCoordinates(x, y, z);
return CraftMagicNumbers.toLegacyData(blockids[getSectionIndex(y)].get(x, y & 0xF, z));
return CraftMagicNumbers.toLegacyData(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z));
}
@Override
public final int getBlockSkyLight(int x, int y, int z) {
validateChunkCoordinates(x, y, z);
this.validateChunkCoordinates(x, y, z);
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (skylight[getSectionIndex(y)][off] >> ((x & 1) << 2)) & 0xF;
return (this.skylight[this.getSectionIndex(y)][off] >> ((x & 1) << 2)) & 0xF;
}
@Override
public final int getBlockEmittedLight(int x, int y, int z) {
validateChunkCoordinates(x, y, z);
this.validateChunkCoordinates(x, y, z);
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (emitlight[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(hmap != null, "ChunkSnapshot created without height map. Please call getSnapshot with includeMaxblocky=true");
validateChunkCoordinates(x, 0, z);
Preconditions.checkState(this.hmap != null, "ChunkSnapshot created without height map. Please call getSnapshot with includeMaxblocky=true");
this.validateChunkCoordinates(x, 0, z);
return hmap.getHighestTaken(x, z);
return this.hmap.getHighestTaken(x, z);
}
@Override
public final Biome getBiome(int x, int z) {
return getBiome(x, 0, z);
return this.getBiome(x, 0, z);
}
@Override
public final Biome getBiome(int x, int y, int z) {
Preconditions.checkState(biome != null, "ChunkSnapshot created without biome. Please call getSnapshot with includeBiome=true");
validateChunkCoordinates(x, y, z);
Preconditions.checkState(this.biome != null, "ChunkSnapshot created without biome. Please call getSnapshot with includeBiome=true");
this.validateChunkCoordinates(x, y, z);
PalettedContainerRO<Holder<BiomeBase>> biome = this.biome[getSectionIndex(y)]; // SPIGOT-7188: Don't need to convert y to biome coordinate scale since it is bound to the block chunk section
PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>> biome = this.biome[this.getSectionIndex(y)]; // SPIGOT-7188: Don't need to convert y to biome coordinate scale since it is bound to the block chunk section
return CraftBiome.minecraftHolderToBukkit(biome.get(x >> 2, (y & 0xF) >> 2, z >> 2));
}
@Override
public final double getRawBiomeTemperature(int x, int z) {
return getRawBiomeTemperature(x, 0, z);
return this.getRawBiomeTemperature(x, 0, z);
}
@Override
public final double getRawBiomeTemperature(int x, int y, int z) {
Preconditions.checkState(biome != null, "ChunkSnapshot created without biome. Please call getSnapshot with includeBiome=true");
validateChunkCoordinates(x, y, z);
Preconditions.checkState(this.biome != null, "ChunkSnapshot created without biome. Please call getSnapshot with includeBiome=true");
this.validateChunkCoordinates(x, y, z);
PalettedContainerRO<Holder<BiomeBase>> biome = this.biome[getSectionIndex(y)]; // SPIGOT-7188: Don't need to convert y to biome coordinate scale since it is bound to the block chunk section
return biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z), seaLevel);
PalettedContainerRO<Holder<net.minecraft.world.level.biome.Biome>> biome = this.biome[this.getSectionIndex(y)]; // SPIGOT-7188: Don't need to convert y to biome coordinate scale since it is bound to the block chunk section
return biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPos((this.x << 4) | x, y, (this.z << 4) | z), this.seaLevel);
}
@Override
public final long getCaptureFullTime() {
return captureFulltime;
return this.captureFulltime;
}
@Override
public final boolean isSectionEmpty(int sy) {
return empty[sy];
return this.empty[sy];
}
private int getSectionIndex(int y) {
return (y - minHeight) >> 4;
return (y - this.minHeight) >> 4;
}
private void validateChunkCoordinates(int x, int y, int z) {
CraftChunk.validateChunkCoordinates(minHeight, maxHeight, x, y, z);
CraftChunk.validateChunkCoordinates(this.minHeight, this.maxHeight, x, y, z);
}
}

View File

@@ -1,56 +1,55 @@
package org.bukkit.craftbukkit;
import java.util.Locale;
import net.minecraft.world.EnumHand;
import net.minecraft.world.entity.EnumItemSlot;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlotGroup;
import org.bukkit.inventory.EquipmentSlot;
public class CraftEquipmentSlot {
private static final EnumItemSlot[] slots = new EnumItemSlot[EquipmentSlot.values().length];
private static final EquipmentSlot[] enums = new EquipmentSlot[EnumItemSlot.values().length];
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, EnumItemSlot.MAINHAND);
set(EquipmentSlot.OFF_HAND, EnumItemSlot.OFFHAND);
set(EquipmentSlot.FEET, EnumItemSlot.FEET);
set(EquipmentSlot.LEGS, EnumItemSlot.LEGS);
set(EquipmentSlot.CHEST, EnumItemSlot.CHEST);
set(EquipmentSlot.HEAD, EnumItemSlot.HEAD);
set(EquipmentSlot.BODY, EnumItemSlot.BODY);
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 static void set(EquipmentSlot type, EnumItemSlot value) {
slots[type.ordinal()] = value;
enums[value.ordinal()] = type;
private static void set(EquipmentSlot type, net.minecraft.world.entity.EquipmentSlot value) {
CraftEquipmentSlot.slots[type.ordinal()] = value;
CraftEquipmentSlot.enums[value.ordinal()] = type;
}
public static EquipmentSlot getSlot(EnumItemSlot nms) {
return enums[nms.ordinal()];
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 EnumItemSlot getNMS(EquipmentSlot slot) {
return slots[slot.ordinal()];
public static net.minecraft.world.entity.EquipmentSlot getNMS(EquipmentSlot slot) {
return CraftEquipmentSlot.slots[slot.ordinal()];
}
public static EquipmentSlotGroup getNMSGroup(org.bukkit.inventory.EquipmentSlotGroup slot) {
return EquipmentSlotGroup.valueOf(slot.toString().toUpperCase(Locale.ROOT));
}
public static EquipmentSlot getHand(EnumHand enumhand) {
return (enumhand == EnumHand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
public static EquipmentSlot getHand(InteractionHand enumhand) {
return (enumhand == InteractionHand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
}
public static EnumHand getHand(EquipmentSlot hand) {
public static InteractionHand getHand(EquipmentSlot hand) {
if (hand == EquipmentSlot.HAND) {
return EnumHand.MAIN_HAND;
return InteractionHand.MAIN_HAND;
} else if (hand == EquipmentSlot.OFF_HAND) {
return EnumHand.OFF_HAND;
return InteractionHand.OFF_HAND;
}
throw new IllegalArgumentException("EquipmentSlot." + hand + " is not a hand");

View File

@@ -8,7 +8,7 @@ public final class CraftExplosionResult {
private CraftExplosionResult() {}
public static ExplosionResult toBukkit(Explosion.Effect effect) {
public static ExplosionResult toBukkit(Explosion.BlockInteraction effect) {
Preconditions.checkArgument(effect != null, "explosion effect cannot be null");
switch (effect) {

View File

@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import org.bukkit.FeatureFlag;
@@ -15,7 +15,7 @@ public class CraftFeatureFlag implements FeatureFlag {
private final NamespacedKey namespacedKey;
private final net.minecraft.world.flag.FeatureFlag featureFlag;
public CraftFeatureFlag(MinecraftKey minecraftKey, net.minecraft.world.flag.FeatureFlag featureFlag) {
public CraftFeatureFlag(ResourceLocation minecraftKey, net.minecraft.world.flag.FeatureFlag featureFlag) {
this.namespacedKey = CraftNamespacedKey.fromMinecraft(minecraftKey);
this.featureFlag = featureFlag;
}

View File

@@ -2,31 +2,30 @@ package org.bukkit.craftbukkit;
import java.util.Locale;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.material.FluidType;
import org.bukkit.Fluid;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftFluid implements Fluid, Handleable<FluidType> {
public class CraftFluid implements Fluid, Handleable<net.minecraft.world.level.material.Fluid> {
private static int count = 0;
public static Fluid minecraftToBukkit(FluidType minecraft) {
public static Fluid minecraftToBukkit(net.minecraft.world.level.material.Fluid minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.FLUID, Registry.FLUID);
}
public static FluidType bukkitToMinecraft(Fluid bukkit) {
public static net.minecraft.world.level.material.Fluid bukkitToMinecraft(Fluid bukkit) {
return CraftRegistry.bukkitToMinecraft(bukkit);
}
private final NamespacedKey key;
private final FluidType fluidType;
private final net.minecraft.world.level.material.Fluid fluidType;
private final String name;
private final int ordinal;
public CraftFluid(NamespacedKey key, FluidType fluidType) {
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,
@@ -38,40 +37,40 @@ public class CraftFluid implements Fluid, Handleable<FluidType> {
} else {
this.name = key.toString();
}
this.ordinal = count++;
this.ordinal = CraftFluid.count++;
}
@Override
public FluidType getHandle() {
return fluidType;
public net.minecraft.world.level.material.Fluid getHandle() {
return this.fluidType;
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
public int compareTo(@NotNull Fluid fluid) {
return ordinal - fluid.ordinal();
return this.ordinal - fluid.ordinal();
}
@NotNull
@Override
public String name() {
return name;
return this.name;
}
@Override
public int ordinal() {
return ordinal;
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return name();
return this.name();
}
@Override
@@ -84,11 +83,11 @@ public class CraftFluid implements Fluid, Handleable<FluidType> {
return false;
}
return getKey().equals(otherFluid.getKey());
return this.getKey().equals(otherFluid.getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
}

View File

@@ -1,22 +1,22 @@
package org.bukkit.craftbukkit;
import net.minecraft.world.level.RayTrace.FluidCollisionOption;
import net.minecraft.world.level.ClipContext.Fluid;
import org.bukkit.FluidCollisionMode;
public final class CraftFluidCollisionMode {
private CraftFluidCollisionMode() {}
public static FluidCollisionOption toNMS(FluidCollisionMode fluidCollisionMode) {
public static Fluid toNMS(FluidCollisionMode fluidCollisionMode) {
if (fluidCollisionMode == null) return null;
switch (fluidCollisionMode) {
case ALWAYS:
return FluidCollisionOption.ANY;
return Fluid.ANY;
case SOURCE_ONLY:
return FluidCollisionOption.SOURCE_ONLY;
return Fluid.SOURCE_ONLY;
case NEVER:
return FluidCollisionOption.NONE;
return Fluid.NONE;
default:
return null;
}

View File

@@ -27,13 +27,13 @@ public class CraftGameEvent extends GameEvent implements Handleable<net.minecraf
@Override
public net.minecraft.world.level.gameevent.GameEvent getHandle() {
return handle;
return this.handle;
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
@@ -46,16 +46,16 @@ public class CraftGameEvent extends GameEvent implements Handleable<net.minecraf
return false;
}
return getKey().equals(((GameEvent) other).getKey());
return this.getKey().equals(((GameEvent) other).getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
@Override
public String toString() {
return "CraftGameEvent{key=" + key + "}";
return "CraftGameEvent{key=" + this.key + "}";
}
}

View File

@@ -7,26 +7,26 @@ public final class CraftHeightMap {
private CraftHeightMap() {
}
public static net.minecraft.world.level.levelgen.HeightMap.Type toNMS(HeightMap bukkitHeightMap) {
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.Type.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.Type.OCEAN_FLOOR;
return net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR;
case OCEAN_FLOOR_WG:
return net.minecraft.world.level.levelgen.HeightMap.Type.OCEAN_FLOOR_WG;
return net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR_WG;
case WORLD_SURFACE:
return net.minecraft.world.level.levelgen.HeightMap.Type.WORLD_SURFACE;
return net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE;
case WORLD_SURFACE_WG:
return net.minecraft.world.level.levelgen.HeightMap.Type.WORLD_SURFACE_WG;
return net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE_WG;
case MOTION_BLOCKING:
return net.minecraft.world.level.levelgen.HeightMap.Type.MOTION_BLOCKING;
return net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING;
default:
throw new EnumConstantNotPresentException(net.minecraft.world.level.levelgen.HeightMap.Type.class, bukkitHeightMap.name());
throw new EnumConstantNotPresentException(net.minecraft.world.level.levelgen.Heightmap.Types.class, bukkitHeightMap.name());
}
}
public static HeightMap fromNMS(net.minecraft.world.level.levelgen.HeightMap.Type nmsHeightMapType) {
public static HeightMap fromNMS(net.minecraft.world.level.levelgen.Heightmap.Types nmsHeightMapType) {
switch (nmsHeightMapType) {
case WORLD_SURFACE_WG:
return HeightMap.WORLD_SURFACE_WG;

View File

@@ -13,37 +13,37 @@ public class CraftInput implements Input {
@Override
public boolean isForward() {
return handle.forward();
return this.handle.forward();
}
@Override
public boolean isBackward() {
return handle.backward();
return this.handle.backward();
}
@Override
public boolean isLeft() {
return handle.left();
return this.handle.left();
}
@Override
public boolean isRight() {
return handle.right();
return this.handle.right();
}
@Override
public boolean isJump() {
return handle.jump();
return this.handle.jump();
}
@Override
public boolean isSneak() {
return handle.shift();
return this.handle.shift();
}
@Override
public boolean isSprint() {
return handle.sprint();
return this.handle.sprint();
}
@Override
@@ -61,7 +61,7 @@ public class CraftInput implements Input {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (this.getClass() != obj.getClass()) {
return false;
}
final CraftInput other = (CraftInput) obj;
@@ -70,6 +70,6 @@ public class CraftInput implements Input {
@Override
public String toString() {
return "CraftInput{" + handle + '}';
return "CraftInput{" + this.handle + '}';
}
}

View File

@@ -2,7 +2,6 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.contents.TranslatableContents;
import org.bukkit.JukeboxSong;
@@ -18,7 +17,7 @@ public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.w
}
public static JukeboxSong minecraftHolderToBukkit(Holder<net.minecraft.world.item.JukeboxSong> minecraft) {
return minecraftToBukkit(minecraft.value());
return CraftJukeboxSong.minecraftToBukkit(minecraft.value());
}
public static net.minecraft.world.item.JukeboxSong bukkitToMinecraft(JukeboxSong bukkit) {
@@ -28,9 +27,9 @@ public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.w
public static Holder<net.minecraft.world.item.JukeboxSong> bukkitToMinecraftHolder(JukeboxSong bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<net.minecraft.world.item.JukeboxSong> registry = CraftRegistry.getMinecraftRegistry(Registries.JUKEBOX_SONG);
net.minecraft.core.Registry<net.minecraft.world.item.JukeboxSong> registry = CraftRegistry.getMinecraftRegistry(Registries.JUKEBOX_SONG);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<net.minecraft.world.item.JukeboxSong> holder) {
if (registry.wrapAsHolder(CraftJukeboxSong.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.item.JukeboxSong> holder) {
return holder;
}
@@ -48,18 +47,18 @@ public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.w
@Override
public net.minecraft.world.item.JukeboxSong getHandle() {
return handle;
return this.handle;
}
@Override
@NotNull
public NamespacedKey getKey() {
return key;
return this.key;
}
@NotNull
@Override
public String getTranslationKey() {
return ((TranslatableContents) handle.description().getContents()).getKey();
return ((TranslatableContents) this.handle.description().getContents()).getKey();
}
}

View File

@@ -6,19 +6,18 @@ import java.util.Collection;
import java.util.List;
import java.util.Random;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.WorldServer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.context.ContextKey;
import net.minecraft.util.context.ContextKeySet;
import net.minecraft.world.IInventory;
import net.minecraft.world.Container;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.LootTableInfo;
import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
@@ -34,12 +33,12 @@ import org.bukkit.loot.LootContext;
public class CraftLootTable implements org.bukkit.loot.LootTable {
public static org.bukkit.loot.LootTable minecraftToBukkit(MinecraftKey minecraft) {
public static org.bukkit.loot.LootTable minecraftToBukkit(ResourceLocation minecraft) {
return (minecraft == null) ? null : Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(minecraft));
}
public static org.bukkit.loot.LootTable minecraftToBukkit(ResourceKey<LootTable> minecraft) {
return (minecraft == null) ? null : Bukkit.getLootTable(minecraftToBukkitKey(minecraft));
return (minecraft == null) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft));
}
public static NamespacedKey minecraftToBukkitKey(ResourceKey<LootTable> minecraft) {
@@ -47,7 +46,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
public static ResourceKey<LootTable> bukkitToMinecraft(org.bukkit.loot.LootTable table) {
return (table == null) ? null : bukkitKeyToMinecraft(table.getKey());
return (table == null) ? null : CraftLootTable.bukkitKeyToMinecraft(table.getKey());
}
public static ResourceKey<LootTable> bukkitKeyToMinecraft(NamespacedKey key) {
@@ -63,14 +62,14 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
public LootTable getHandle() {
return handle;
return this.handle;
}
@Override
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
Preconditions.checkArgument(context != null, "LootContext cannot be null");
LootParams nmsContext = convertContext(context, random);
List<net.minecraft.world.item.ItemStack> nmsItems = handle.getRandomItems(nmsContext);
LootParams nmsContext = this.convertContext(context, random);
List<net.minecraft.world.item.ItemStack> nmsItems = this.handle.getRandomItems(nmsContext);
Collection<ItemStack> bukkit = new ArrayList<>(nmsItems.size());
for (net.minecraft.world.item.ItemStack item : nmsItems) {
@@ -87,87 +86,87 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
public void fillInventory(Inventory inventory, Random random, LootContext context) {
Preconditions.checkArgument(inventory != null, "Inventory cannot be null");
Preconditions.checkArgument(context != null, "LootContext cannot be null");
LootParams nmsContext = convertContext(context, random);
LootParams nmsContext = this.convertContext(context, random);
CraftInventory craftInventory = (CraftInventory) inventory;
IInventory handle = craftInventory.getInventory();
Container handle = craftInventory.getInventory();
// TODO: When events are added, call event here w/ custom reason?
getHandle().fillInventory(handle, nmsContext, random.nextLong(), true);
this.getHandle().fillInventory(handle, nmsContext, random.nextLong(), true);
}
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
private LootParams convertContext(LootContext context, Random random) {
Preconditions.checkArgument(context != null, "LootContext cannot be null");
Location loc = context.getLocation();
Preconditions.checkArgument(loc.getWorld() != null, "LootContext.getLocation#getWorld cannot be null");
WorldServer handle = ((CraftWorld) loc.getWorld()).getHandle();
ServerLevel handle = ((CraftWorld) loc.getWorld()).getHandle();
LootParams.a builder = new LootParams.a(handle);
LootParams.Builder builder = new LootParams.Builder(handle);
if (random != null) {
// builder = builder.withRandom(new RandomSourceWrapper(random));
}
setMaybe(builder, LootContextParameters.ORIGIN, CraftLocation.toVec3D(loc));
if (getHandle() != LootTable.EMPTY) {
this.setMaybe(builder, LootContextParams.ORIGIN, CraftLocation.toVec3D(loc));
if (this.getHandle() != LootTable.EMPTY) {
// builder.luck(context.getLuck());
if (context.getLootedEntity() != null) {
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
setMaybe(builder, LootContextParameters.THIS_ENTITY, nmsLootedEntity);
setMaybe(builder, LootContextParameters.DAMAGE_SOURCE, handle.damageSources().generic());
setMaybe(builder, LootContextParameters.ORIGIN, nmsLootedEntity.position());
this.setMaybe(builder, LootContextParams.THIS_ENTITY, nmsLootedEntity);
this.setMaybe(builder, LootContextParams.DAMAGE_SOURCE, handle.damageSources().generic());
this.setMaybe(builder, LootContextParams.ORIGIN, nmsLootedEntity.position());
}
if (context.getKiller() != null) {
EntityHuman nmsKiller = ((CraftHumanEntity) context.getKiller()).getHandle();
setMaybe(builder, LootContextParameters.ATTACKING_ENTITY, nmsKiller);
Player nmsKiller = ((CraftHumanEntity) context.getKiller()).getHandle();
this.setMaybe(builder, LootContextParams.ATTACKING_ENTITY, nmsKiller);
// If there is a player killer, damage source should reflect that in case loot tables use that information
setMaybe(builder, LootContextParameters.DAMAGE_SOURCE, handle.damageSources().playerAttack(nmsKiller));
setMaybe(builder, LootContextParameters.LAST_DAMAGE_PLAYER, nmsKiller); // SPIGOT-5603 - Set minecraft:killed_by_player
setMaybe(builder, LootContextParameters.TOOL, nmsKiller.getUseItem()); // SPIGOT-6925 - Set minecraft:match_tool
this.setMaybe(builder, LootContextParams.DAMAGE_SOURCE, handle.damageSources().playerAttack(nmsKiller));
this.setMaybe(builder, LootContextParams.LAST_DAMAGE_PLAYER, nmsKiller); // SPIGOT-5603 - Set minecraft:killed_by_player
this.setMaybe(builder, LootContextParams.TOOL, nmsKiller.getUseItem()); // SPIGOT-6925 - Set minecraft:match_tool
}
}
// SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
ContextKeySet.a nmsBuilder = new ContextKeySet.a();
for (ContextKey<?> param : getHandle().getParamSet().required()) {
ContextKeySet.Builder nmsBuilder = new ContextKeySet.Builder();
for (ContextKey<?> param : this.getHandle().getParamSet().required()) {
nmsBuilder.required(param);
}
for (ContextKey<?> param : getHandle().getParamSet().allowed()) {
if (!getHandle().getParamSet().required().contains(param)) {
for (ContextKey<?> param : this.getHandle().getParamSet().allowed()) {
if (!this.getHandle().getParamSet().required().contains(param)) {
nmsBuilder.optional(param);
}
}
return builder.create(getHandle().getParamSet());
return builder.create(this.getHandle().getParamSet());
}
private <T> void setMaybe(LootParams.a builder, ContextKey<T> param, T value) {
if (getHandle().getParamSet().required().contains(param) || getHandle().getParamSet().allowed().contains(param)) {
private <T> void setMaybe(LootParams.Builder builder, ContextKey<T> param, T value) {
if (this.getHandle().getParamSet().required().contains(param) || this.getHandle().getParamSet().allowed().contains(param)) {
builder.withParameter(param, value);
}
}
public static LootContext convertContext(LootTableInfo info) {
Vec3D position = info.getOptionalParameter(LootContextParameters.ORIGIN);
public static LootContext convertContext(net.minecraft.world.level.storage.loot.LootContext info) {
Vec3 position = info.getOptionalParameter(LootContextParams.ORIGIN);
if (position == null) {
position = info.getOptionalParameter(LootContextParameters.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 LootContextParameterSets
}
Location location = CraftLocation.toBukkit(position, info.getLevel().getWorld());
LootContext.Builder contextBuilder = new LootContext.Builder(location);
if (info.hasParameter(LootContextParameters.ATTACKING_ENTITY)) {
CraftEntity killer = info.getOptionalParameter(LootContextParameters.ATTACKING_ENTITY).getBukkitEntity();
if (info.hasParameter(LootContextParams.ATTACKING_ENTITY)) {
CraftEntity killer = info.getOptionalParameter(LootContextParams.ATTACKING_ENTITY).getBukkitEntity();
if (killer instanceof CraftHumanEntity) {
contextBuilder.killer((CraftHumanEntity) killer);
}
}
if (info.hasParameter(LootContextParameters.THIS_ENTITY)) {
contextBuilder.lootedEntity(info.getOptionalParameter(LootContextParameters.THIS_ENTITY).getBukkitEntity());
if (info.hasParameter(LootContextParams.THIS_ENTITY)) {
contextBuilder.lootedEntity(info.getOptionalParameter(LootContextParams.THIS_ENTITY).getBukkitEntity());
}
contextBuilder.luck(info.getLuck());
@@ -176,7 +175,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
@Override
public String toString() {
return getKey().toString();
return this.getKey().toString();
}
@Override

View File

@@ -2,7 +2,6 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.Instrument;
import org.bukkit.MusicInstrument;
@@ -18,7 +17,7 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
}
public static MusicInstrument minecraftHolderToBukkit(Holder<Instrument> minecraft) {
return minecraftToBukkit(minecraft.value());
return CraftMusicInstrument.minecraftToBukkit(minecraft.value());
}
public static Instrument bukkitToMinecraft(MusicInstrument bukkit) {
@@ -28,9 +27,9 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
public static Holder<Instrument> bukkitToMinecraftHolder(MusicInstrument bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<Instrument> registry = CraftRegistry.getMinecraftRegistry(Registries.INSTRUMENT);
net.minecraft.core.Registry<Instrument> registry = CraftRegistry.getMinecraftRegistry(Registries.INSTRUMENT);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<Instrument> holder) {
if (registry.wrapAsHolder(CraftMusicInstrument.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<Instrument> holder) {
return holder;
}
@@ -60,13 +59,13 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
@Override
public Instrument getHandle() {
return handle;
return this.handle;
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
@@ -79,16 +78,16 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
return false;
}
return getKey().equals(((MusicInstrument) other).getKey());
return this.getKey().equals(((MusicInstrument) other).getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
@Override
public String toString() {
return "CraftMusicInstrument{key=" + key + "}";
return "CraftMusicInstrument{key=" + this.key + "}";
}
}

View File

@@ -10,12 +10,12 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import net.minecraft.core.GlobalPos;
import net.minecraft.nbt.DynamicOpsNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.players.WhiteListEntry;
import net.minecraft.stats.ServerStatisticManager;
import net.minecraft.world.level.storage.WorldNBTStorage;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.server.players.UserWhiteListEntry;
import net.minecraft.stats.ServerStatsCounter;
import net.minecraft.world.level.storage.PlayerDataStorage;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
@@ -39,7 +39,7 @@ import org.bukkit.profile.PlayerProfile;
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
private final GameProfile profile;
private final CraftServer server;
private final WorldNBTStorage storage;
private final PlayerDataStorage storage;
protected CraftOfflinePlayer(CraftServer server, GameProfile profile) {
this.server = server;
@@ -50,22 +50,22 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public boolean isOnline() {
return getPlayer() != null;
return this.getPlayer() != null;
}
@Override
public String getName() {
Player player = getPlayer();
Player player = this.getPlayer();
if (player != null) {
return player.getName();
}
// This might not match lastKnownName but if not it should be more correct
if (!profile.getName().isEmpty()) {
return profile.getName();
if (!this.profile.getName().isEmpty()) {
return this.profile.getName();
}
NBTTagCompound data = getBukkitData();
CompoundTag data = this.getBukkitData();
if (data != null) {
if (data.contains("lastKnownName")) {
@@ -78,75 +78,75 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public UUID getUniqueId() {
return profile.getId();
return this.profile.getId();
}
@Override
public PlayerProfile getPlayerProfile() {
return new CraftPlayerProfile(profile);
return new CraftPlayerProfile(this.profile);
}
public Server getServer() {
return server;
return this.server;
}
@Override
public boolean isOp() {
return server.getHandle().isOp(profile);
return this.server.getHandle().isOp(this.profile);
}
@Override
public void setOp(boolean value) {
if (value == isOp()) {
if (value == this.isOp()) {
return;
}
if (value) {
server.getHandle().op(profile);
this.server.getHandle().op(this.profile);
} else {
server.getHandle().deop(profile);
this.server.getHandle().deop(this.profile);
}
}
@Override
public boolean isBanned() {
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).isBanned(getPlayerProfile());
return ((ProfileBanList) this.server.getBanList(BanList.Type.PROFILE)).isBanned(this.getPlayerProfile());
}
@Override
public BanEntry<PlayerProfile> ban(String reason, Date expires, String source) {
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, expires, source);
return ((ProfileBanList) this.server.getBanList(BanList.Type.PROFILE)).addBan(this.getPlayerProfile(), reason, expires, source);
}
@Override
public BanEntry<PlayerProfile> ban(String reason, Instant expires, String source) {
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, expires, source);
return ((ProfileBanList) this.server.getBanList(BanList.Type.PROFILE)).addBan(this.getPlayerProfile(), reason, expires, source);
}
@Override
public BanEntry<PlayerProfile> ban(String reason, Duration duration, String source) {
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, duration, source);
return ((ProfileBanList) this.server.getBanList(BanList.Type.PROFILE)).addBan(this.getPlayerProfile(), reason, duration, source);
}
public void setBanned(boolean value) {
if (value) {
((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), null, (Date) null, null);
((ProfileBanList) this.server.getBanList(BanList.Type.PROFILE)).addBan(this.getPlayerProfile(), null, (Date) null, null);
} else {
((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).pardon(getPlayerProfile());
((ProfileBanList) this.server.getBanList(BanList.Type.PROFILE)).pardon(this.getPlayerProfile());
}
}
@Override
public boolean isWhitelisted() {
return server.getHandle().getWhiteList().isWhiteListed(profile);
return this.server.getHandle().getWhiteList().isWhiteListed(this.profile);
}
@Override
public void setWhitelisted(boolean value) {
if (value) {
server.getHandle().getWhiteList().add(new WhiteListEntry(profile));
this.server.getHandle().getWhiteList().add(new UserWhiteListEntry(this.profile));
} else {
server.getHandle().getWhiteList().remove(profile);
this.server.getHandle().getWhiteList().remove(this.profile);
}
}
@@ -154,7 +154,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<>();
result.put("UUID", profile.getId().toString());
result.put("UUID", this.profile.getId().toString());
return result;
}
@@ -170,12 +170,12 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public String toString() {
return getClass().getSimpleName() + "[UUID=" + profile.getId() + "]";
return this.getClass().getSimpleName() + "[UUID=" + this.profile.getId() + "]";
}
@Override
public Player getPlayer() {
return server.getPlayer(getUniqueId());
return this.server.getPlayer(this.getUniqueId());
}
@Override
@@ -198,16 +198,16 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return hash;
}
private NBTTagCompound getData() {
return storage.load(profile.getName(), profile.getId().toString()).orElse(null);
private CompoundTag getData() {
return this.storage.load(this.profile.getName(), this.profile.getId().toString()).orElse(null);
}
private NBTTagCompound getBukkitData() {
NBTTagCompound result = getData();
private CompoundTag getBukkitData() {
CompoundTag result = this.getData();
if (result != null) {
if (!result.contains("bukkit")) {
result.put("bukkit", new NBTTagCompound());
result.put("bukkit", new CompoundTag());
}
result = result.getCompound("bukkit");
}
@@ -216,21 +216,21 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
}
private File getDataFile() {
return new File(storage.getPlayerDir(), getUniqueId() + ".dat");
return new File(this.storage.getPlayerDir(), this.getUniqueId() + ".dat");
}
@Override
public long getFirstPlayed() {
Player player = getPlayer();
Player player = this.getPlayer();
if (player != null) return player.getFirstPlayed();
NBTTagCompound data = getBukkitData();
CompoundTag data = this.getBukkitData();
if (data != null) {
if (data.contains("firstPlayed")) {
return data.getLong("firstPlayed");
} else {
File file = getDataFile();
File file = this.getDataFile();
return file.lastModified();
}
} else {
@@ -240,16 +240,16 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public long getLastPlayed() {
Player player = getPlayer();
Player player = this.getPlayer();
if (player != null) return player.getLastPlayed();
NBTTagCompound data = getBukkitData();
CompoundTag data = this.getBukkitData();
if (data != null) {
if (data.contains("lastPlayed")) {
return data.getLong("lastPlayed");
} else {
File file = getDataFile();
File file = this.getDataFile();
return file.lastModified();
}
} else {
@@ -259,31 +259,31 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public boolean hasPlayedBefore() {
return getData() != null;
return this.getData() != null;
}
@Override
public Location getLastDeathLocation() {
if (getData().contains("LastDeathLocation", 10)) {
return GlobalPos.CODEC.parse(DynamicOpsNBT.INSTANCE, getData().get("LastDeathLocation")).result().map(CraftMemoryMapper::fromNms).orElse(null);
if (this.getData().contains("LastDeathLocation", 10)) {
return GlobalPos.CODEC.parse(NbtOps.INSTANCE, this.getData().get("LastDeathLocation")).result().map(CraftMemoryMapper::fromNms).orElse(null);
}
return null;
}
@Override
public Location getLocation() {
NBTTagCompound data = getData();
CompoundTag data = this.getData();
if (data == null) {
return null;
}
if (data.contains("Pos") && data.contains("Rotation")) {
NBTTagList position = (NBTTagList) data.get("Pos");
NBTTagList rotation = (NBTTagList) data.get("Rotation");
ListTag position = (ListTag) data.get("Pos");
ListTag rotation = (ListTag) data.get("Rotation");
UUID uuid = new UUID(data.getLong("WorldUUIDMost"), data.getLong("WorldUUIDLeast"));
return new Location(server.getWorld(uuid),
return new Location(this.server.getWorld(uuid),
position.getDouble(0),
position.getDouble(1),
position.getDouble(2),
@@ -297,50 +297,50 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public Location getBedSpawnLocation() {
return getRespawnLocation();
return this.getRespawnLocation();
}
@Override
public Location getRespawnLocation() {
NBTTagCompound data = getData();
CompoundTag data = this.getData();
if (data == null) return null;
if (data.contains("SpawnX") && data.contains("SpawnY") && data.contains("SpawnZ")) {
String spawnWorld = data.getString("SpawnWorld");
if (spawnWorld.equals("")) {
spawnWorld = server.getWorlds().get(0).getName();
spawnWorld = this.server.getWorlds().get(0).getName();
}
return new Location(server.getWorld(spawnWorld), data.getInt("SpawnX"), data.getInt("SpawnY"), data.getInt("SpawnZ"));
return new Location(this.server.getWorld(spawnWorld), data.getInt("SpawnX"), data.getInt("SpawnY"), data.getInt("SpawnZ"));
}
return null;
}
public void setMetadata(String metadataKey, MetadataValue metadataValue) {
server.getPlayerMetadata().setMetadata(this, metadataKey, metadataValue);
this.server.getPlayerMetadata().setMetadata(this, metadataKey, metadataValue);
}
public List<MetadataValue> getMetadata(String metadataKey) {
return server.getPlayerMetadata().getMetadata(this, metadataKey);
return this.server.getPlayerMetadata().getMetadata(this, metadataKey);
}
public boolean hasMetadata(String metadataKey) {
return server.getPlayerMetadata().hasMetadata(this, metadataKey);
return this.server.getPlayerMetadata().hasMetadata(this, metadataKey);
}
public void removeMetadata(String metadataKey, Plugin plugin) {
server.getPlayerMetadata().removeMetadata(this, metadataKey, plugin);
this.server.getPlayerMetadata().removeMetadata(this, metadataKey, plugin);
}
private ServerStatisticManager getStatisticManager() {
return server.getHandle().getPlayerStats(getUniqueId(), getName());
private ServerStatsCounter getStatisticManager() {
return this.server.getHandle().getPlayerStats(this.getUniqueId(), this.getName());
}
@Override
public void incrementStatistic(Statistic statistic) {
if (isOnline()) {
getPlayer().incrementStatistic(statistic);
if (this.isOnline()) {
this.getPlayer().incrementStatistic(statistic);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.incrementStatistic(manager, statistic, null);
manager.save();
}
@@ -348,10 +348,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void decrementStatistic(Statistic statistic) {
if (isOnline()) {
getPlayer().decrementStatistic(statistic);
if (this.isOnline()) {
this.getPlayer().decrementStatistic(statistic);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.decrementStatistic(manager, statistic, null);
manager.save();
}
@@ -359,19 +359,19 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public int getStatistic(Statistic statistic) {
if (isOnline()) {
return getPlayer().getStatistic(statistic);
if (this.isOnline()) {
return this.getPlayer().getStatistic(statistic);
} else {
return CraftStatistic.getStatistic(getStatisticManager(), statistic);
return CraftStatistic.getStatistic(this.getStatisticManager(), statistic);
}
}
@Override
public void incrementStatistic(Statistic statistic, int amount) {
if (isOnline()) {
getPlayer().incrementStatistic(statistic, amount);
if (this.isOnline()) {
this.getPlayer().incrementStatistic(statistic, amount);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.incrementStatistic(manager, statistic, amount, null);
manager.save();
}
@@ -379,10 +379,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void decrementStatistic(Statistic statistic, int amount) {
if (isOnline()) {
getPlayer().decrementStatistic(statistic, amount);
if (this.isOnline()) {
this.getPlayer().decrementStatistic(statistic, amount);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.decrementStatistic(manager, statistic, amount, null);
manager.save();
}
@@ -390,10 +390,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void setStatistic(Statistic statistic, int newValue) {
if (isOnline()) {
getPlayer().setStatistic(statistic, newValue);
if (this.isOnline()) {
this.getPlayer().setStatistic(statistic, newValue);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.setStatistic(manager, statistic, newValue, null);
manager.save();
}
@@ -401,10 +401,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void incrementStatistic(Statistic statistic, Material material) {
if (isOnline()) {
getPlayer().incrementStatistic(statistic, material);
if (this.isOnline()) {
this.getPlayer().incrementStatistic(statistic, material);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.incrementStatistic(manager, statistic, material, null);
manager.save();
}
@@ -412,10 +412,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void decrementStatistic(Statistic statistic, Material material) {
if (isOnline()) {
getPlayer().decrementStatistic(statistic, material);
if (this.isOnline()) {
this.getPlayer().decrementStatistic(statistic, material);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.decrementStatistic(manager, statistic, material, null);
manager.save();
}
@@ -423,19 +423,19 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public int getStatistic(Statistic statistic, Material material) {
if (isOnline()) {
return getPlayer().getStatistic(statistic, material);
if (this.isOnline()) {
return this.getPlayer().getStatistic(statistic, material);
} else {
return CraftStatistic.getStatistic(getStatisticManager(), statistic, material);
return CraftStatistic.getStatistic(this.getStatisticManager(), statistic, material);
}
}
@Override
public void incrementStatistic(Statistic statistic, Material material, int amount) {
if (isOnline()) {
getPlayer().incrementStatistic(statistic, material, amount);
if (this.isOnline()) {
this.getPlayer().incrementStatistic(statistic, material, amount);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.incrementStatistic(manager, statistic, material, amount, null);
manager.save();
}
@@ -443,10 +443,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void decrementStatistic(Statistic statistic, Material material, int amount) {
if (isOnline()) {
getPlayer().decrementStatistic(statistic, material, amount);
if (this.isOnline()) {
this.getPlayer().decrementStatistic(statistic, material, amount);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.decrementStatistic(manager, statistic, material, amount, null);
manager.save();
}
@@ -454,10 +454,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void setStatistic(Statistic statistic, Material material, int newValue) {
if (isOnline()) {
getPlayer().setStatistic(statistic, material, newValue);
if (this.isOnline()) {
this.getPlayer().setStatistic(statistic, material, newValue);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.setStatistic(manager, statistic, material, newValue, null);
manager.save();
}
@@ -465,10 +465,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void incrementStatistic(Statistic statistic, EntityType entityType) {
if (isOnline()) {
getPlayer().incrementStatistic(statistic, entityType);
if (this.isOnline()) {
this.getPlayer().incrementStatistic(statistic, entityType);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.incrementStatistic(manager, statistic, entityType, null);
manager.save();
}
@@ -476,10 +476,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void decrementStatistic(Statistic statistic, EntityType entityType) {
if (isOnline()) {
getPlayer().decrementStatistic(statistic, entityType);
if (this.isOnline()) {
this.getPlayer().decrementStatistic(statistic, entityType);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.decrementStatistic(manager, statistic, entityType, null);
manager.save();
}
@@ -487,19 +487,19 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public int getStatistic(Statistic statistic, EntityType entityType) {
if (isOnline()) {
return getPlayer().getStatistic(statistic, entityType);
if (this.isOnline()) {
return this.getPlayer().getStatistic(statistic, entityType);
} else {
return CraftStatistic.getStatistic(getStatisticManager(), statistic, entityType);
return CraftStatistic.getStatistic(this.getStatisticManager(), statistic, entityType);
}
}
@Override
public void incrementStatistic(Statistic statistic, EntityType entityType, int amount) {
if (isOnline()) {
getPlayer().incrementStatistic(statistic, entityType, amount);
if (this.isOnline()) {
this.getPlayer().incrementStatistic(statistic, entityType, amount);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.incrementStatistic(manager, statistic, entityType, amount, null);
manager.save();
}
@@ -507,10 +507,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void decrementStatistic(Statistic statistic, EntityType entityType, int amount) {
if (isOnline()) {
getPlayer().decrementStatistic(statistic, entityType, amount);
if (this.isOnline()) {
this.getPlayer().decrementStatistic(statistic, entityType, amount);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.decrementStatistic(manager, statistic, entityType, amount, null);
manager.save();
}
@@ -518,10 +518,10 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override
public void setStatistic(Statistic statistic, EntityType entityType, int newValue) {
if (isOnline()) {
getPlayer().setStatistic(statistic, entityType, newValue);
if (this.isOnline()) {
this.getPlayer().setStatistic(statistic, entityType, newValue);
} else {
ServerStatisticManager manager = getStatisticManager();
ServerStatsCounter manager = this.getStatisticManager();
CraftStatistic.setStatistic(manager, statistic, entityType, newValue, null);
manager.save();
}

View File

@@ -4,16 +4,15 @@ import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import net.minecraft.core.IRegistry;
import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ColorParticleOption;
import net.minecraft.core.particles.DustColorTransitionOptions;
import net.minecraft.core.particles.ParticleParam;
import net.minecraft.core.particles.ParticleParamBlock;
import net.minecraft.core.particles.ParticleParamItem;
import net.minecraft.core.particles.ParticleParamRedstone;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.SculkChargeParticleOptions;
import net.minecraft.core.particles.ShriekParticleOption;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.core.particles.TrailParticleOption;
import net.minecraft.core.particles.VibrationParticleOption;
import net.minecraft.core.registries.Registries;
@@ -43,10 +42,10 @@ public abstract class CraftParticle<D> implements Keyed {
private static final Registry<CraftParticle<?>> CRAFT_PARTICLE_REGISTRY = new CraftParticleRegistry(CraftRegistry.getMinecraftRegistry(Registries.PARTICLE_TYPE));
public static Particle minecraftToBukkit(net.minecraft.core.particles.Particle<?> minecraft) {
public static Particle minecraftToBukkit(net.minecraft.core.particles.ParticleType<?> minecraft) {
Preconditions.checkArgument(minecraft != null);
IRegistry<net.minecraft.core.particles.Particle<?>> registry = CraftRegistry.getMinecraftRegistry(Registries.PARTICLE_TYPE);
net.minecraft.core.Registry<net.minecraft.core.particles.ParticleType<?>> registry = CraftRegistry.getMinecraftRegistry(Registries.PARTICLE_TYPE);
Particle bukkit = Registry.PARTICLE_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
Preconditions.checkArgument(bukkit != null);
@@ -54,14 +53,14 @@ public abstract class CraftParticle<D> implements Keyed {
return bukkit;
}
public static net.minecraft.core.particles.Particle<?> bukkitToMinecraft(Particle bukkit) {
public static net.minecraft.core.particles.ParticleType<?> bukkitToMinecraft(Particle bukkit) {
Preconditions.checkArgument(bukkit != null);
return CraftRegistry.getMinecraftRegistry(Registries.PARTICLE_TYPE)
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
}
public static <D> ParticleParam createParticleParam(Particle particle, D data) {
public static <D> ParticleOptions createParticleParam(Particle particle, D data) {
Preconditions.checkArgument(particle != null, "particle cannot be null");
data = CraftParticle.convertLegacy(data);
@@ -72,7 +71,7 @@ public abstract class CraftParticle<D> implements Keyed {
Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType());
}
CraftParticle<D> craftParticle = (CraftParticle<D>) CRAFT_PARTICLE_REGISTRY.get(particle.getKey());
CraftParticle<D> craftParticle = (CraftParticle<D>) CraftParticle.CRAFT_PARTICLE_REGISTRY.get(particle.getKey());
Preconditions.checkArgument(craftParticle != null);
@@ -88,72 +87,72 @@ public abstract class CraftParticle<D> implements Keyed {
}
private final NamespacedKey key;
private final net.minecraft.core.particles.Particle<?> particle;
private final net.minecraft.core.particles.ParticleType<?> particle;
private final Class<D> clazz;
public CraftParticle(NamespacedKey key, net.minecraft.core.particles.Particle<?> particle, Class<D> clazz) {
public CraftParticle(NamespacedKey key, net.minecraft.core.particles.ParticleType<?> particle, Class<D> clazz) {
this.key = key;
this.particle = particle;
this.clazz = clazz;
}
public net.minecraft.core.particles.Particle<?> getHandle() {
return particle;
public net.minecraft.core.particles.ParticleType<?> getHandle() {
return this.particle;
}
public abstract ParticleParam createParticleParam(D data);
public abstract ParticleOptions createParticleParam(D data);
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
public static class CraftParticleRegistry extends CraftRegistry<CraftParticle<?>, net.minecraft.core.particles.Particle<?>> {
public static class CraftParticleRegistry extends CraftRegistry<CraftParticle<?>, net.minecraft.core.particles.ParticleType<?>> {
private static final Map<NamespacedKey, BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>>> PARTICLE_MAP = new HashMap<>();
private static final Map<NamespacedKey, BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>>> PARTICLE_MAP = new HashMap<>();
private static final BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> VOID_FUNCTION = (name, particle) -> new CraftParticle<>(name, particle, Void.class) {
private static final BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> VOID_FUNCTION = (name, particle) -> new CraftParticle<>(name, particle, Void.class) {
@Override
public ParticleParam createParticleParam(Void data) {
return (ParticleType) getHandle();
public ParticleOptions createParticleParam(Void data) {
return (SimpleParticleType) this.getHandle();
}
};
static {
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> dustOptionsFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.DustOptions.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> dustOptionsFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.DustOptions.class) {
@Override
public ParticleParam createParticleParam(Particle.DustOptions data) {
public ParticleOptions createParticleParam(Particle.DustOptions data) {
Color color = data.getColor();
return new ParticleParamRedstone(color.asRGB(), data.getSize());
return new DustParticleOptions(color.asRGB(), data.getSize());
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> itemStackFunction = (name, particle) -> new CraftParticle<>(name, particle, ItemStack.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> itemStackFunction = (name, particle) -> new CraftParticle<>(name, particle, ItemStack.class) {
@Override
public ParticleParam createParticleParam(ItemStack data) {
return new ParticleParamItem((net.minecraft.core.particles.Particle<ParticleParamItem>) getHandle(), CraftItemStack.asNMSCopy(data));
public ParticleOptions createParticleParam(ItemStack data) {
return new ItemParticleOption((net.minecraft.core.particles.ParticleType<ItemParticleOption>) this.getHandle(), CraftItemStack.asNMSCopy(data));
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> blockDataFunction = (name, particle) -> new CraftParticle<>(name, particle, BlockData.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> blockDataFunction = (name, particle) -> new CraftParticle<>(name, particle, BlockData.class) {
@Override
public ParticleParam createParticleParam(BlockData data) {
return new ParticleParamBlock((net.minecraft.core.particles.Particle<ParticleParamBlock>) getHandle(), ((CraftBlockData) data).getState());
public ParticleOptions createParticleParam(BlockData data) {
return new BlockParticleOption((net.minecraft.core.particles.ParticleType<BlockParticleOption>) this.getHandle(), ((CraftBlockData) data).getState());
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> dustTransitionFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.DustTransition.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> dustTransitionFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.DustTransition.class) {
@Override
public ParticleParam createParticleParam(Particle.DustTransition data) {
public ParticleOptions createParticleParam(Particle.DustTransition data) {
Color from = data.getColor();
Color to = data.getToColor();
return new DustColorTransitionOptions(from.asRGB(), to.asRGB(), data.getSize());
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> vibrationFunction = (name, particle) -> new CraftParticle<>(name, particle, Vibration.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> vibrationFunction = (name, particle) -> new CraftParticle<>(name, particle, Vibration.class) {
@Override
public ParticleParam createParticleParam(Vibration data) {
public ParticleOptions createParticleParam(Vibration data) {
PositionSource source;
if (data.getDestination() instanceof Vibration.Destination.BlockDestination) {
Location destination = ((Vibration.Destination.BlockDestination) data.getDestination()).getLocation();
@@ -169,30 +168,30 @@ public abstract class CraftParticle<D> implements Keyed {
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> floatFunction = (name, particle) -> new CraftParticle<>(name, particle, Float.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> floatFunction = (name, particle) -> new CraftParticle<>(name, particle, Float.class) {
@Override
public ParticleParam createParticleParam(Float data) {
public ParticleOptions createParticleParam(Float data) {
return new SculkChargeParticleOptions(data);
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> integerFunction = (name, particle) -> new CraftParticle<>(name, particle, Integer.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> integerFunction = (name, particle) -> new CraftParticle<>(name, particle, Integer.class) {
@Override
public ParticleParam createParticleParam(Integer data) {
public ParticleOptions createParticleParam(Integer data) {
return new ShriekParticleOption(data);
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> colorFunction = (name, particle) -> new CraftParticle<>(name, particle, Color.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> colorFunction = (name, particle) -> new CraftParticle<>(name, particle, Color.class) {
@Override
public ParticleParam createParticleParam(Color color) {
return ColorParticleOption.create((net.minecraft.core.particles.Particle<ColorParticleOption>) particle, color.asARGB());
public ParticleOptions createParticleParam(Color color) {
return ColorParticleOption.create((net.minecraft.core.particles.ParticleType<ColorParticleOption>) particle, color.asARGB());
}
};
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> trailFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.Trail.class) {
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> trailFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.Trail.class) {
@Override
public ParticleParam createParticleParam(Particle.Trail data) {
public ParticleOptions createParticleParam(Particle.Trail data) {
return new TrailParticleOption(CraftLocation.toVec3D(data.getTarget()), data.getColor().asRGB(), data.getDuration());
}
};
@@ -212,21 +211,21 @@ public abstract class CraftParticle<D> implements Keyed {
add("trail", trailFunction);
}
private static void add(String name, BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> function) {
PARTICLE_MAP.put(NamespacedKey.fromString(name), function);
private static void add(String name, BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> function) {
CraftParticleRegistry.PARTICLE_MAP.put(NamespacedKey.fromString(name), function);
}
public CraftParticleRegistry(IRegistry<net.minecraft.core.particles.Particle<?>> minecraftRegistry) {
public CraftParticleRegistry(net.minecraft.core.Registry<net.minecraft.core.particles.ParticleType<?>> minecraftRegistry) {
super(CraftParticle.class, minecraftRegistry, null, FieldRename.PARTICLE_TYPE_RENAME);
}
@Override
public CraftParticle<?> createBukkit(NamespacedKey namespacedKey, net.minecraft.core.particles.Particle<?> particle) {
public CraftParticle<?> createBukkit(NamespacedKey namespacedKey, net.minecraft.core.particles.ParticleType<?> particle) {
if (particle == null) {
return null;
}
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> function = PARTICLE_MAP.getOrDefault(namespacedKey, VOID_FUNCTION);
BiFunction<NamespacedKey, net.minecraft.core.particles.ParticleType<?>, CraftParticle<?>> function = CraftParticleRegistry.PARTICLE_MAP.getOrDefault(namespacedKey, CraftParticleRegistry.VOID_FUNCTION);
return function.apply(namespacedKey, particle);
}

View File

@@ -7,9 +7,8 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import net.minecraft.core.BlockPosition;
import net.minecraft.world.entity.raid.EntityRaider;
import net.minecraft.world.level.World;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.Raid;
import org.bukkit.Raid.RaidStatus;
@@ -26,40 +25,40 @@ public final class CraftRaid implements Raid {
@Override
public boolean isStarted() {
return handle.isStarted();
return this.handle.isStarted();
}
@Override
public long getActiveTicks() {
return handle.ticksActive;
return this.handle.ticksActive;
}
@Override
public int getBadOmenLevel() {
return handle.raidOmenLevel;
return this.handle.raidOmenLevel;
}
@Override
public void setBadOmenLevel(int badOmenLevel) {
int max = handle.getMaxRaidOmenLevel();
int max = this.handle.getMaxRaidOmenLevel();
Preconditions.checkArgument(0 <= badOmenLevel && badOmenLevel <= max, "Bad Omen level must be between 0 and %s", max);
handle.raidOmenLevel = badOmenLevel;
this.handle.raidOmenLevel = badOmenLevel;
}
@Override
public Location getLocation() {
BlockPosition pos = handle.getCenter();
World world = handle.getLevel();
BlockPos pos = this.handle.getCenter();
Level world = this.handle.getLevel();
return CraftLocation.toBukkit(pos, world.getWorld());
}
@Override
public RaidStatus getStatus() {
if (handle.isStopped()) {
if (this.handle.isStopped()) {
return RaidStatus.STOPPED;
} else if (handle.isVictory()) {
} else if (this.handle.isVictory()) {
return RaidStatus.VICTORY;
} else if (handle.isLoss()) {
} else if (this.handle.isLoss()) {
return RaidStatus.LOSS;
} else {
return RaidStatus.ONGOING;
@@ -68,40 +67,40 @@ public final class CraftRaid implements Raid {
@Override
public int getSpawnedGroups() {
return handle.getGroupsSpawned();
return this.handle.getGroupsSpawned();
}
@Override
public int getTotalGroups() {
return handle.numGroups + (handle.raidOmenLevel > 1 ? 1 : 0);
return this.handle.numGroups + (this.handle.raidOmenLevel > 1 ? 1 : 0);
}
@Override
public int getTotalWaves() {
return handle.numGroups;
return this.handle.numGroups;
}
@Override
public float getTotalHealth() {
return handle.getHealthOfLivingRaiders();
return this.handle.getHealthOfLivingRaiders();
}
@Override
public Set<UUID> getHeroes() {
return Collections.unmodifiableSet(handle.heroesOfTheVillage);
return Collections.unmodifiableSet(this.handle.heroesOfTheVillage);
}
@Override
public List<Raider> getRaiders() {
return handle.getRaiders().stream().map(new Function<EntityRaider, Raider>() {
return this.handle.getRaiders().stream().map(new Function<net.minecraft.world.entity.raid.Raider, Raider>() {
@Override
public Raider apply(EntityRaider entityRaider) {
public Raider apply(net.minecraft.world.entity.raid.Raider entityRaider) {
return (Raider) entityRaider.getBukkitEntity();
}
}).collect(ImmutableList.toImmutableList());
}
public net.minecraft.world.entity.raid.Raid getHandle() {
return handle;
return this.handle;
}
}

View File

@@ -7,23 +7,20 @@ import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
import java.util.function.Predicate;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
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.RandomSource;
import net.minecraft.world.entity.EntityInsentient;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.GroupDataEntity;
import net.minecraft.world.entity.projectile.EntityPotion;
import net.minecraft.world.level.GeneratorAccessSeed;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.block.BlockChorusFlower;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.ChorusFlowerBlock;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.WorldGenFeatureConfigured;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.portal.TeleportTransition;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -64,123 +61,123 @@ import org.bukkit.potion.PotionType;
public abstract class CraftRegionAccessor implements RegionAccessor {
public abstract GeneratorAccessSeed getHandle();
public abstract WorldGenLevel getHandle();
public boolean isNormalWorld() {
return getHandle() instanceof net.minecraft.server.level.WorldServer;
return this.getHandle() instanceof net.minecraft.server.level.ServerLevel;
}
@Override
public Biome getBiome(Location location) {
return getBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return this.getBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public Biome getBiome(int x, int y, int z) {
return CraftBiome.minecraftHolderToBukkit(getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
return CraftBiome.minecraftHolderToBukkit(this.getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
}
@Override
public void setBiome(Location location, Biome biome) {
setBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ(), biome);
this.setBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ(), biome);
}
@Override
public void setBiome(int x, int y, int z, Biome biome) {
Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot set the biome to %s", biome);
Holder<BiomeBase> biomeBase = CraftBiome.bukkitToMinecraftHolder(biome);
setBiome(x, y, z, biomeBase);
Holder<net.minecraft.world.level.biome.Biome> biomeBase = CraftBiome.bukkitToMinecraftHolder(biome);
this.setBiome(x, y, z, biomeBase);
}
public abstract void setBiome(int x, int y, int z, Holder<BiomeBase> biomeBase);
public abstract void setBiome(int x, int y, int z, Holder<net.minecraft.world.level.biome.Biome> biomeBase);
@Override
public BlockState getBlockState(Location location) {
return getBlockState(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return this.getBlockState(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public BlockState getBlockState(int x, int y, int z) {
return CraftBlock.at(getHandle(), new BlockPosition(x, y, z)).getState();
return CraftBlock.at(this.getHandle(), new BlockPos(x, y, z)).getState();
}
@Override
public BlockData getBlockData(Location location) {
return getBlockData(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return this.getBlockData(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public BlockData getBlockData(int x, int y, int z) {
return CraftBlockData.fromData(getData(x, y, z));
return CraftBlockData.fromData(this.getData(x, y, z));
}
@Override
public Material getType(Location location) {
return getType(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return this.getType(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public Material getType(int x, int y, int z) {
return CraftBlockType.minecraftToBukkit(getData(x, y, z).getBlock());
return CraftBlockType.minecraftToBukkit(this.getData(x, y, z).getBlock());
}
private IBlockData getData(int x, int y, int z) {
return getHandle().getBlockState(new BlockPosition(x, y, z));
private net.minecraft.world.level.block.state.BlockState getData(int x, int y, int z) {
return this.getHandle().getBlockState(new BlockPos(x, y, z));
}
@Override
public void setBlockData(Location location, BlockData blockData) {
setBlockData(location.getBlockX(), location.getBlockY(), location.getBlockZ(), blockData);
this.setBlockData(location.getBlockX(), location.getBlockY(), location.getBlockZ(), blockData);
}
@Override
public void setBlockData(int x, int y, int z, BlockData blockData) {
GeneratorAccessSeed world = getHandle();
BlockPosition pos = new BlockPosition(x, y, z);
IBlockData old = getHandle().getBlockState(pos);
WorldGenLevel world = this.getHandle();
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);
}
@Override
public void setType(Location location, Material material) {
setType(location.getBlockX(), location.getBlockY(), location.getBlockZ(), material);
this.setType(location.getBlockX(), location.getBlockY(), location.getBlockZ(), material);
}
@Override
public void setType(int x, int y, int z, Material material) {
setBlockData(x, y, z, material.createBlockData());
this.setBlockData(x, y, z, material.createBlockData());
}
@Override
public int getHighestBlockYAt(int x, int z) {
return getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING);
return this.getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING);
}
@Override
public int getHighestBlockYAt(Location location) {
return getHighestBlockYAt(location.getBlockX(), location.getBlockZ());
return this.getHighestBlockYAt(location.getBlockX(), location.getBlockZ());
}
@Override
public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) {
return getHandle().getHeight(CraftHeightMap.toNMS(heightMap), x, z);
return this.getHandle().getHeight(CraftHeightMap.toNMS(heightMap), x, z);
}
@Override
public int getHighestBlockYAt(Location location, org.bukkit.HeightMap heightMap) {
return getHighestBlockYAt(location.getBlockX(), location.getBlockZ(), heightMap);
return this.getHighestBlockYAt(location.getBlockX(), location.getBlockZ(), heightMap);
}
@Override
public boolean generateTree(Location location, Random random, TreeType treeType) {
BlockPosition pos = CraftLocation.toBlockPosition(location);
return generateTree(getHandle(), getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, new RandomSourceWrapper(random), treeType);
BlockPos pos = CraftLocation.toBlockPosition(location);
return this.generateTree(this.getHandle(), this.getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, new RandomSourceWrapper(random), treeType);
}
@Override
public boolean generateTree(Location location, Random random, TreeType treeType, Consumer<? super BlockState> consumer) {
return generateTree(location, random, treeType, (consumer == null) ? null : (block) -> {
return this.generateTree(location, random, treeType, (consumer == null) ? null : (block) -> {
consumer.accept(block);
return true;
});
@@ -188,9 +185,9 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
public boolean generateTree(Location location, Random random, TreeType treeType, Predicate<? super BlockState> predicate) {
BlockPosition pos = CraftLocation.toBlockPosition(location);
BlockStateListPopulator populator = new BlockStateListPopulator(getHandle());
boolean result = generateTree(populator, getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, new RandomSourceWrapper(random), treeType);
BlockPos pos = CraftLocation.toBlockPosition(location);
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()) {
@@ -202,8 +199,8 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
return result;
}
public boolean generateTree(GeneratorAccessSeed access, ChunkGenerator chunkGenerator, BlockPosition pos, RandomSource random, TreeType treeType) {
ResourceKey<WorldGenFeatureConfigured<?, ?>> gen;
public boolean generateTree(WorldGenLevel access, ChunkGenerator chunkGenerator, BlockPos pos, RandomSource random, TreeType treeType) {
ResourceKey<ConfiguredFeature<?, ?>> gen;
switch (treeType) {
case BIG_TREE:
gen = TreeFeatures.FANCY_OAK;
@@ -254,7 +251,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
gen = TreeFeatures.SUPER_BIRCH_BEES_0002;
break;
case CHORUS_PLANT:
((BlockChorusFlower) Blocks.CHORUS_FLOWER).generatePlant(access, pos, random, 8);
((ChorusFlowerBlock) Blocks.CHORUS_FLOWER).generatePlant(access, pos, random, 8);
return true;
case CRIMSON_FUNGUS:
gen = TreeFeatures.CRIMSON_FUNGUS_PLANTED;
@@ -286,29 +283,29 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
break;
}
Holder<WorldGenFeatureConfigured<?, ?>> holder = access.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(gen).orElse(null);
Holder<ConfiguredFeature<?, ?>> holder = access.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(gen).orElse(null);
return (holder != null) ? holder.value().place(access, chunkGenerator, random, pos) : false;
}
@Override
public Entity spawnEntity(Location location, EntityType entityType) {
return spawn(location, entityType.getEntityClass());
return this.spawn(location, entityType.getEntityClass());
}
@Override
public Entity spawnEntity(Location loc, EntityType type, boolean randomizeData) {
return spawn(loc, type.getEntityClass(), null, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData);
return this.spawn(loc, type.getEntityClass(), null, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData);
}
@Override
public List<Entity> getEntities() {
List<Entity> list = new ArrayList<Entity>();
getNMSEntities().forEach(entity -> {
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
// Assuming that bukkitEntity isn't null
if (bukkitEntity != null && (!isNormalWorld() || bukkitEntity.isValid())) {
if (bukkitEntity != null && (!this.isNormalWorld() || bukkitEntity.isValid())) {
list.add(bukkitEntity);
}
});
@@ -320,11 +317,11 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
public List<LivingEntity> getLivingEntities() {
List<LivingEntity> list = new ArrayList<LivingEntity>();
getNMSEntities().forEach(entity -> {
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
// Assuming that bukkitEntity isn't null
if (bukkitEntity != null && bukkitEntity instanceof LivingEntity && (!isNormalWorld() || bukkitEntity.isValid())) {
if (bukkitEntity != null && bukkitEntity instanceof LivingEntity && (!this.isNormalWorld() || bukkitEntity.isValid())) {
list.add((LivingEntity) bukkitEntity);
}
});
@@ -337,7 +334,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
public <T extends Entity> Collection<T> getEntitiesByClass(Class<T> clazz) {
Collection<T> list = new ArrayList<T>();
getNMSEntities().forEach(entity -> {
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
if (bukkitEntity == null) {
@@ -346,7 +343,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
Class<?> bukkitClass = bukkitEntity.getClass();
if (clazz.isAssignableFrom(bukkitClass) && (!isNormalWorld() || bukkitEntity.isValid())) {
if (clazz.isAssignableFrom(bukkitClass) && (!this.isNormalWorld() || bukkitEntity.isValid())) {
list.add((T) bukkitEntity);
}
});
@@ -358,7 +355,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
public Collection<Entity> getEntitiesByClasses(Class<?>... classes) {
Collection<Entity> list = new ArrayList<Entity>();
getNMSEntities().forEach(entity -> {
this.getNMSEntities().forEach(entity -> {
Entity bukkitEntity = entity.getBukkitEntity();
if (bukkitEntity == null) {
@@ -369,7 +366,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
for (Class<?> clazz : classes) {
if (clazz.isAssignableFrom(bukkitClass)) {
if (!isNormalWorld() || bukkitEntity.isValid()) {
if (!this.isNormalWorld() || bukkitEntity.isValid()) {
list.add(bukkitEntity);
}
break;
@@ -385,9 +382,9 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
@SuppressWarnings("unchecked")
public <T extends Entity> T createEntity(Location location, Class<T> clazz) throws IllegalArgumentException {
net.minecraft.world.entity.Entity entity = createEntity(location, clazz, true);
net.minecraft.world.entity.Entity entity = this.createEntity(location, clazz, true);
if (!isNormalWorld()) {
if (!this.isNormalWorld()) {
entity.generation = true;
}
@@ -396,27 +393,27 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
public <T extends Entity> T spawn(Location location, Class<T> clazz) throws IllegalArgumentException {
return spawn(location, clazz, null, CreatureSpawnEvent.SpawnReason.CUSTOM);
return this.spawn(location, clazz, null, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
@Override
public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<? super T> function) throws IllegalArgumentException {
return spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM);
return this.spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
@Override
public <T extends Entity> T spawn(Location location, Class<T> clazz, boolean randomizeData, Consumer<? super T> function) throws IllegalArgumentException {
return spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData);
return this.spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData);
}
public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<? super T> function, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException {
return spawn(location, clazz, function, reason, true);
return this.spawn(location, clazz, function, reason, true);
}
public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<? super T> function, CreatureSpawnEvent.SpawnReason reason, boolean randomizeData) throws IllegalArgumentException {
net.minecraft.world.entity.Entity entity = createEntity(location, clazz, randomizeData);
net.minecraft.world.entity.Entity entity = this.createEntity(location, clazz, randomizeData);
return addEntity(entity, reason, function, randomizeData);
return this.addEntity(entity, reason, function, randomizeData);
}
@Override
@@ -424,28 +421,28 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
public <T extends Entity> T addEntity(T entity) {
Preconditions.checkArgument(!entity.isInWorld(), "Entity has already been added to a world");
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity.level() != getHandle().getLevel()) {
nmsEntity = nmsEntity.teleport(new TeleportTransition(getHandle().getLevel(), nmsEntity, TeleportTransition.DO_NOTHING));
if (nmsEntity.level() != this.getHandle().getLevel()) {
nmsEntity = nmsEntity.teleport(new TeleportTransition(this.getHandle().getLevel(), nmsEntity, TeleportTransition.DO_NOTHING));
}
addEntityWithPassengers(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
this.addEntityWithPassengers(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
return (T) nmsEntity.getBukkitEntity();
}
@SuppressWarnings("unchecked")
public <T extends Entity> T addEntity(net.minecraft.world.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException {
return addEntity(entity, reason, null, true);
return this.addEntity(entity, reason, null, true);
}
@SuppressWarnings("unchecked")
public <T extends Entity> T addEntity(net.minecraft.world.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason, Consumer<? super T> function, boolean randomizeData) throws IllegalArgumentException {
Preconditions.checkArgument(entity != null, "Cannot spawn null entity");
if (randomizeData && entity instanceof EntityInsentient) {
((EntityInsentient) entity).finalizeSpawn(getHandle(), getHandle().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (GroupDataEntity) null);
if (randomizeData && entity instanceof Mob) {
((Mob) entity).finalizeSpawn(this.getHandle(), this.getHandle().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (SpawnGroupData) null);
}
if (!isNormalWorld()) {
if (!this.isNormalWorld()) {
entity.generation = true;
}
@@ -453,7 +450,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
function.accept((T) entity.getBukkitEntity());
}
addEntityToWorld(entity, reason);
this.addEntityToWorld(entity, reason);
return (T) entity.getBukkitEntity();
}
@@ -463,7 +460,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@SuppressWarnings("unchecked")
public net.minecraft.world.entity.Entity makeEntity(Location location, Class<? extends Entity> clazz) throws IllegalArgumentException {
return createEntity(location, clazz, true);
return this.createEntity(location, clazz, true);
}
@SuppressWarnings("unchecked")
@@ -481,7 +478,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
clazz = LargeFireball.class;
} else if (clazz == LingeringPotion.class) {
clazz = ThrownPotion.class;
runOld = other -> ((EntityPotion) other).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
runOld = other -> ((net.minecraft.world.entity.projectile.ThrownPotion) other).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else if (clazz == Minecart.class) {
clazz = RideableMinecart.class;
} else if (clazz == SizedFireball.class) {
@@ -505,11 +502,11 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
}
}
if (!entityTypeData.entityType().isEnabledByFeature(getHandle().getMinecraftWorld().getWorld())) {
if (!entityTypeData.entityType().isEnabledByFeature(this.getHandle().getMinecraftWorld().getWorld())) {
throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName() + " because it is not an enabled feature");
}
net.minecraft.world.entity.Entity entity = entityTypeData.spawnFunction().apply(new CraftEntityTypes.SpawnData(getHandle(), location, randomizeData, isNormalWorld()));
net.minecraft.world.entity.Entity entity = entityTypeData.spawnFunction().apply(new CraftEntityTypes.SpawnData(this.getHandle(), location, randomizeData, this.isNormalWorld()));
if (entity != null) {
runOld.accept(entity);

View File

@@ -7,8 +7,7 @@ import java.util.Map;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import org.bukkit.Art;
@@ -66,19 +65,19 @@ import org.jetbrains.annotations.NotNull;
public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
private static IRegistryCustom registry;
private static RegistryAccess registry;
public static void setMinecraftRegistry(IRegistryCustom registry) {
public static void setMinecraftRegistry(RegistryAccess registry) {
Preconditions.checkState(CraftRegistry.registry == null, "Registry already set");
CraftRegistry.registry = registry;
}
public static IRegistryCustom getMinecraftRegistry() {
return registry;
public static RegistryAccess getMinecraftRegistry() {
return CraftRegistry.registry;
}
public static <E> IRegistry<E> getMinecraftRegistry(ResourceKey<IRegistry<E>> key) {
return getMinecraftRegistry().lookupOrThrow(key);
public static <E> net.minecraft.core.Registry<E> getMinecraftRegistry(ResourceKey<net.minecraft.core.Registry<E>> key) {
return CraftRegistry.getMinecraftRegistry().lookupOrThrow(key);
}
/**
@@ -90,10 +89,10 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
* @param bukkitRegistry the bukkit registry to use
* @return the bukkit representation of the minecraft value
*/
public static <B extends Keyed, M> B minecraftToBukkit(M minecraft, ResourceKey<IRegistry<M>> registryKey, Registry<B> bukkitRegistry) {
public static <B extends Keyed, M> B minecraftToBukkit(M minecraft, ResourceKey<net.minecraft.core.Registry<M>> registryKey, Registry<B> bukkitRegistry) {
Preconditions.checkArgument(minecraft != null);
IRegistry<M> registry = CraftRegistry.getMinecraftRegistry(registryKey);
net.minecraft.core.Registry<M> registry = CraftRegistry.getMinecraftRegistry(registryKey);
B bukkit = bukkitRegistry.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft)
.orElseThrow(() -> new IllegalStateException(String.format("Cannot convert '%s' to bukkit representation, since it is not registered.", minecraft))).location()));
@@ -115,12 +114,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
return ((Handleable<M>) bukkit).getHandle();
}
public static <B extends Keyed, M> Holder<M> bukkitToMinecraftHolder(B bukkit, ResourceKey<IRegistry<M>> registryKey) {
public static <B extends Keyed, M> Holder<M> bukkitToMinecraftHolder(B bukkit, ResourceKey<net.minecraft.core.Registry<M>> registryKey) {
Preconditions.checkArgument(bukkit != null);
IRegistry<M> registry = CraftRegistry.getMinecraftRegistry(registryKey);
net.minecraft.core.Registry<M> registry = CraftRegistry.getMinecraftRegistry(registryKey);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<M> holder) {
if (registry.wrapAsHolder(CraftRegistry.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<M> holder) {
return holder;
}
@@ -135,7 +134,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
* @param registryHolder the minecraft registry holder
* @return the bukkit registry of the provided class
*/
public static <B extends Keyed> Registry<?> createRegistry(Class<? super B> bukkitClass, IRegistryCustom registryHolder) {
public static <B extends Keyed> Registry<?> createRegistry(Class<? super B> bukkitClass, RegistryAccess registryHolder) {
if (bukkitClass == Art.class) {
return new CraftRegistry<>(Art.class, registryHolder.lookupOrThrow(Registries.PAINTING_VARIANT), CraftArt::new, FieldRename.NONE);
}
@@ -237,12 +236,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
private final Class<? super B> bukkitClass;
private final Map<NamespacedKey, B> cache = new HashMap<>();
private final IRegistry<M> minecraftRegistry;
private final net.minecraft.core.Registry<M> minecraftRegistry;
private final BiFunction<NamespacedKey, M, B> minecraftToBukkit;
private final BiFunction<NamespacedKey, ApiVersion, NamespacedKey> updater;
private boolean init;
public CraftRegistry(Class<? super B> bukkitClass, IRegistry<M> minecraftRegistry, BiFunction<NamespacedKey, M, B> minecraftToBukkit, BiFunction<NamespacedKey, ApiVersion, NamespacedKey> updater) {
public CraftRegistry(Class<? super B> bukkitClass, net.minecraft.core.Registry<M> minecraftRegistry, BiFunction<NamespacedKey, M, B> minecraftToBukkit, BiFunction<NamespacedKey, ApiVersion, NamespacedKey> updater) {
this.bukkitClass = bukkitClass;
this.minecraftRegistry = minecraftRegistry;
this.minecraftToBukkit = minecraftToBukkit;
@@ -250,12 +249,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
}
public B get(NamespacedKey namespacedKey, ApiVersion apiVersion) {
return get(updater.apply(namespacedKey, apiVersion));
return this.get(this.updater.apply(namespacedKey, apiVersion));
}
@Override
public B get(NamespacedKey namespacedKey) {
B cached = cache.get(namespacedKey);
B cached = this.cache.get(namespacedKey);
if (cached != null) {
return cached;
}
@@ -270,23 +269,23 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
// With this code (when bukkit class is not loaded):
// Registry#get -> (load class -> create default) -> Registry#get -> get from cache
// Result: Registry#get == <bukkitClass>.<field>
if (!init) {
init = true;
if (!this.init) {
this.init = true;
try {
Class.forName(bukkitClass.getName());
Class.forName(this.bukkitClass.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not load registry class " + bukkitClass, e);
throw new RuntimeException("Could not load registry class " + this.bukkitClass, e);
}
return get(namespacedKey);
return this.get(namespacedKey);
}
B bukkit = createBukkit(namespacedKey, minecraftRegistry.getOptional(CraftNamespacedKey.toMinecraft(namespacedKey)).orElse(null));
B bukkit = this.createBukkit(namespacedKey, this.minecraftRegistry.getOptional(CraftNamespacedKey.toMinecraft(namespacedKey)).orElse(null));
if (bukkit == null) {
return null;
}
cache.put(namespacedKey, bukkit);
this.cache.put(namespacedKey, bukkit);
return bukkit;
}
@@ -294,9 +293,9 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
@NotNull
@Override
public B getOrThrow(@NotNull NamespacedKey namespacedKey) {
B object = get(namespacedKey);
B object = this.get(namespacedKey);
Preconditions.checkArgument(object != null, "No %s registry entry found for key %s.", minecraftRegistry.key(), namespacedKey);
Preconditions.checkArgument(object != null, "No %s registry entry found for key %s.", this.minecraftRegistry.key(), namespacedKey);
return object;
}
@@ -304,12 +303,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
@NotNull
@Override
public Stream<B> stream() {
return minecraftRegistry.keySet().stream().map(minecraftKey -> get(CraftNamespacedKey.fromMinecraft(minecraftKey)));
return this.minecraftRegistry.keySet().stream().map(minecraftKey -> this.get(CraftNamespacedKey.fromMinecraft(minecraftKey)));
}
@Override
public Iterator<B> iterator() {
return stream().iterator();
return this.stream().iterator();
}
public B createBukkit(NamespacedKey namespacedKey, M minecraft) {
@@ -317,6 +316,6 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
return null;
}
return minecraftToBukkit.apply(namespacedKey, minecraft);
return this.minecraftToBukkit.apply(namespacedKey, minecraft);
}
}

View File

@@ -30,12 +30,12 @@ public class CraftServerLinks implements ServerLinks {
public ServerLink getLink(Type type) {
Preconditions.checkArgument(type != null, "type cannot be null");
return getServerLinks().findKnownType(fromBukkit(type)).map(CraftServerLink::new).orElse(null);
return this.getServerLinks().findKnownType(CraftServerLinks.fromBukkit(type)).map(CraftServerLink::new).orElse(null);
}
@Override
public List<ServerLink> getLinks() {
return getServerLinks().entries().stream().map(nms -> (ServerLink) new CraftServerLink(nms)).toList();
return this.getServerLinks().entries().stream().map(nms -> (ServerLink) new CraftServerLink(nms)).toList();
}
@Override
@@ -43,11 +43,11 @@ public class CraftServerLinks implements ServerLinks {
Preconditions.checkArgument(type != null, "type cannot be null");
Preconditions.checkArgument(url != null, "url cannot be null");
ServerLink existing = getLink(type);
ServerLink existing = this.getLink(type);
if (existing != null) {
removeLink(existing);
this.removeLink(existing);
}
return addLink(type, url);
return this.addLink(type, url);
}
@Override
@@ -55,8 +55,8 @@ public class CraftServerLinks implements ServerLinks {
Preconditions.checkArgument(type != null, "type cannot be null");
Preconditions.checkArgument(url != null, "url cannot be null");
CraftServerLink link = new CraftServerLink(net.minecraft.server.ServerLinks.Entry.knownType(fromBukkit(type), url));
addLink(link);
CraftServerLink link = new CraftServerLink(net.minecraft.server.ServerLinks.Entry.knownType(CraftServerLinks.fromBukkit(type), url));
this.addLink(link);
return link;
}
@@ -67,42 +67,42 @@ public class CraftServerLinks implements ServerLinks {
Preconditions.checkArgument(url != null, "url cannot be null");
CraftServerLink link = new CraftServerLink(net.minecraft.server.ServerLinks.Entry.custom(CraftChatMessage.fromStringOrNull(displayName), url));
addLink(link);
this.addLink(link);
return link;
}
private void addLink(CraftServerLink link) {
List<net.minecraft.server.ServerLinks.Entry> lst = new ArrayList<>(getServerLinks().entries());
List<net.minecraft.server.ServerLinks.Entry> lst = new ArrayList<>(this.getServerLinks().entries());
lst.add(link.handle);
setLinks(new net.minecraft.server.ServerLinks(lst));
this.setLinks(new net.minecraft.server.ServerLinks(lst));
}
@Override
public boolean removeLink(ServerLink link) {
Preconditions.checkArgument(link != null, "link cannot be null");
List<net.minecraft.server.ServerLinks.Entry> lst = new ArrayList<>(getServerLinks().entries());
List<net.minecraft.server.ServerLinks.Entry> lst = new ArrayList<>(this.getServerLinks().entries());
boolean result = lst.remove(((CraftServerLink) link).handle);
setLinks(new net.minecraft.server.ServerLinks(lst));
this.setLinks(new net.minecraft.server.ServerLinks(lst));
return result;
}
@Override
public ServerLinks copy() {
return new CraftServerLinks(getServerLinks());
return new CraftServerLinks(this.getServerLinks());
}
public net.minecraft.server.ServerLinks getServerLinks() {
return (server != null) ? server.serverLinks() : serverLinks;
return (this.server != null) ? this.server.serverLinks() : this.serverLinks;
}
private void setLinks(net.minecraft.server.ServerLinks links) {
if (server != null) {
server.serverLinks = links;
if (this.server != null) {
this.server.serverLinks = links;
} else {
this.serverLinks = links;
}
@@ -126,17 +126,17 @@ public class CraftServerLinks implements ServerLinks {
@Override
public Type getType() {
return handle.type().left().map(CraftServerLinks::fromNMS).orElse(null);
return this.handle.type().left().map(CraftServerLinks::fromNMS).orElse(null);
}
@Override
public String getDisplayName() {
return CraftChatMessage.fromComponent(handle.displayName());
return CraftChatMessage.fromComponent(this.handle.displayName());
}
@Override
public URI getUrl() {
return handle.link();
return this.handle.link();
}
}
}

View File

@@ -16,78 +16,78 @@ final class CraftServerTickManager implements ServerTickManager {
@Override
public boolean isRunningNormally() {
return manager.runsNormally();
return this.manager.runsNormally();
}
@Override
public boolean isStepping() {
return manager.isSteppingForward();
return this.manager.isSteppingForward();
}
@Override
public boolean isSprinting() {
return manager.isSprinting();
return this.manager.isSprinting();
}
@Override
public boolean isFrozen() {
return manager.isFrozen();
return this.manager.isFrozen();
}
@Override
public float getTickRate() {
return manager.tickrate();
return this.manager.tickrate();
}
@Override
public void setTickRate(final float tickRate) {
Preconditions.checkArgument(tickRate >= 1.0F && tickRate <= 10_000.0F, "The given tick rate must not be less than 1.0 or greater than 10,000.0");
manager.setTickRate(tickRate);
this.manager.setTickRate(tickRate);
}
@Override
public void setFrozen(final boolean frozen) {
if (frozen) {
if (manager.isSprinting()) {
manager.stopSprinting();
if (this.manager.isSprinting()) {
this.manager.stopSprinting();
}
if (manager.isSteppingForward()) {
manager.stopStepping();
if (this.manager.isSteppingForward()) {
this.manager.stopStepping();
}
}
manager.setFrozen(frozen);
this.manager.setFrozen(frozen);
}
@Override
public boolean stepGameIfFrozen(final int ticks) {
return manager.stepGameIfPaused(ticks);
return this.manager.stepGameIfPaused(ticks);
}
@Override
public boolean stopStepping() {
return manager.stopStepping();
return this.manager.stopStepping();
}
@Override
public boolean requestGameToSprint(final int ticks) {
return manager.requestGameToSprint(ticks);
return this.manager.requestGameToSprint(ticks);
}
@Override
public boolean stopSprinting() {
return manager.stopSprinting();
return this.manager.stopSprinting();
}
@Override
public boolean isFrozen(final Entity entity) {
Preconditions.checkArgument(entity != null, "The given entity must not be null");
return manager.isEntityFrozen(((CraftEntity) entity).getHandle());
return this.manager.isEntityFrozen(((CraftEntity) entity).getHandle());
}
@Override
public int getFrozenTicksToRun() {
return manager.frozenTicksToRun();
return this.manager.frozenTicksToRun();
}
}

View File

@@ -3,33 +3,32 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.sounds.SoundEffect;
import net.minecraft.sounds.SoundEvent;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftSound implements Sound, Handleable<SoundEffect> {
public class CraftSound implements Sound, Handleable<SoundEvent> {
private static int count = 0;
public static Sound minecraftToBukkit(SoundEffect minecraft) {
public static Sound minecraftToBukkit(SoundEvent minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.SOUND_EVENT, Registry.SOUNDS);
}
public static SoundEffect bukkitToMinecraft(Sound bukkit) {
public static SoundEvent bukkitToMinecraft(Sound bukkit) {
return CraftRegistry.bukkitToMinecraft(bukkit);
}
public static Holder<SoundEffect> bukkitToMinecraftHolder(Sound bukkit) {
public static Holder<SoundEvent> bukkitToMinecraftHolder(Sound bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<SoundEffect> registry = CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT);
net.minecraft.core.Registry<SoundEvent> registry = CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<SoundEffect> holder) {
if (registry.wrapAsHolder(CraftSound.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<SoundEvent> holder) {
return holder;
}
@@ -38,11 +37,11 @@ public class CraftSound implements Sound, Handleable<SoundEffect> {
}
private final NamespacedKey key;
private final SoundEffect soundEffect;
private final SoundEvent soundEffect;
private final String name;
private final int ordinal;
public CraftSound(NamespacedKey key, SoundEffect soundEffect) {
public CraftSound(NamespacedKey key, SoundEvent soundEffect) {
this.key = key;
this.soundEffect = soundEffect;
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
@@ -54,40 +53,40 @@ public class CraftSound implements Sound, Handleable<SoundEffect> {
} else {
this.name = key.toString();
}
this.ordinal = count++;
this.ordinal = CraftSound.count++;
}
@Override
public SoundEffect getHandle() {
return soundEffect;
public SoundEvent getHandle() {
return this.soundEffect;
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
public int compareTo(@NotNull Sound sound) {
return ordinal - sound.ordinal();
return this.ordinal - sound.ordinal();
}
@NotNull
@Override
public String name() {
return name;
return this.name;
}
@Override
public int ordinal() {
return ordinal;
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return name();
return this.name();
}
@Override
@@ -100,11 +99,11 @@ public class CraftSound implements Sound, Handleable<SoundEffect> {
return false;
}
return getKey().equals(otherSound.getKey());
return this.getKey().equals(otherSound.getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
}

View File

@@ -1,59 +1,59 @@
package org.bukkit.craftbukkit;
import java.util.HashMap;
import net.minecraft.world.level.block.SoundEffectType;
import net.minecraft.world.level.block.SoundType;
import org.bukkit.Sound;
import org.bukkit.SoundGroup;
public class CraftSoundGroup implements SoundGroup {
private final net.minecraft.world.level.block.SoundEffectType handle;
private static final HashMap<SoundEffectType, CraftSoundGroup> SOUND_GROUPS = new HashMap<>();
private final net.minecraft.world.level.block.SoundType handle;
private static final HashMap<SoundType, CraftSoundGroup> SOUND_GROUPS = new HashMap<>();
public static SoundGroup getSoundGroup(SoundEffectType soundEffectType) {
return SOUND_GROUPS.computeIfAbsent(soundEffectType, CraftSoundGroup::new);
public static SoundGroup getSoundGroup(SoundType soundEffectType) {
return CraftSoundGroup.SOUND_GROUPS.computeIfAbsent(soundEffectType, CraftSoundGroup::new);
}
private CraftSoundGroup(net.minecraft.world.level.block.SoundEffectType soundEffectType) {
private CraftSoundGroup(net.minecraft.world.level.block.SoundType soundEffectType) {
this.handle = soundEffectType;
}
public net.minecraft.world.level.block.SoundEffectType getHandle() {
return handle;
public net.minecraft.world.level.block.SoundType getHandle() {
return this.handle;
}
@Override
public float getVolume() {
return getHandle().getVolume();
return this.getHandle().getVolume();
}
@Override
public float getPitch() {
return getHandle().getPitch();
return this.getHandle().getPitch();
}
@Override
public Sound getBreakSound() {
return CraftSound.minecraftToBukkit(getHandle().breakSound);
return CraftSound.minecraftToBukkit(this.getHandle().breakSound);
}
@Override
public Sound getStepSound() {
return CraftSound.minecraftToBukkit(getHandle().getStepSound());
return CraftSound.minecraftToBukkit(this.getHandle().getStepSound());
}
@Override
public Sound getPlaceSound() {
return CraftSound.minecraftToBukkit(getHandle().getPlaceSound());
return CraftSound.minecraftToBukkit(this.getHandle().getPlaceSound());
}
@Override
public Sound getHitSound() {
return CraftSound.minecraftToBukkit(getHandle().hitSound);
return CraftSound.minecraftToBukkit(this.getHandle().hitSound);
}
@Override
public Sound getFallSound() {
return CraftSound.minecraftToBukkit(getHandle().getFallSound());
return CraftSound.minecraftToBukkit(this.getHandle().getFallSound());
}
}

View File

@@ -3,13 +3,12 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.core.IRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.stats.ServerStatisticManager;
import net.minecraft.stats.StatisticList;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.ServerStatsCounter;
import net.minecraft.stats.Stats;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import org.bukkit.Material;
@@ -21,95 +20,95 @@ import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.entity.EntityType;
public enum CraftStatistic {
DAMAGE_DEALT(StatisticList.DAMAGE_DEALT),
DAMAGE_TAKEN(StatisticList.DAMAGE_TAKEN),
DEATHS(StatisticList.DEATHS),
MOB_KILLS(StatisticList.MOB_KILLS),
PLAYER_KILLS(StatisticList.PLAYER_KILLS),
FISH_CAUGHT(StatisticList.FISH_CAUGHT),
ANIMALS_BRED(StatisticList.ANIMALS_BRED),
LEAVE_GAME(StatisticList.LEAVE_GAME),
JUMP(StatisticList.JUMP),
DROP_COUNT(StatisticList.DROP),
DROP(MinecraftKey.withDefaultNamespace("dropped")),
PICKUP(MinecraftKey.withDefaultNamespace("picked_up")),
PLAY_ONE_MINUTE(StatisticList.PLAY_TIME),
TOTAL_WORLD_TIME(StatisticList.TOTAL_WORLD_TIME),
WALK_ONE_CM(StatisticList.WALK_ONE_CM),
WALK_ON_WATER_ONE_CM(StatisticList.WALK_ON_WATER_ONE_CM),
FALL_ONE_CM(StatisticList.FALL_ONE_CM),
SNEAK_TIME(StatisticList.CROUCH_TIME),
CLIMB_ONE_CM(StatisticList.CLIMB_ONE_CM),
FLY_ONE_CM(StatisticList.FLY_ONE_CM),
WALK_UNDER_WATER_ONE_CM(StatisticList.WALK_UNDER_WATER_ONE_CM),
MINECART_ONE_CM(StatisticList.MINECART_ONE_CM),
BOAT_ONE_CM(StatisticList.BOAT_ONE_CM),
PIG_ONE_CM(StatisticList.PIG_ONE_CM),
HORSE_ONE_CM(StatisticList.HORSE_ONE_CM),
SPRINT_ONE_CM(StatisticList.SPRINT_ONE_CM),
CROUCH_ONE_CM(StatisticList.CROUCH_ONE_CM),
AVIATE_ONE_CM(StatisticList.AVIATE_ONE_CM),
MINE_BLOCK(MinecraftKey.withDefaultNamespace("mined")),
USE_ITEM(MinecraftKey.withDefaultNamespace("used")),
BREAK_ITEM(MinecraftKey.withDefaultNamespace("broken")),
CRAFT_ITEM(MinecraftKey.withDefaultNamespace("crafted")),
KILL_ENTITY(MinecraftKey.withDefaultNamespace("killed")),
ENTITY_KILLED_BY(MinecraftKey.withDefaultNamespace("killed_by")),
TIME_SINCE_DEATH(StatisticList.TIME_SINCE_DEATH),
TALKED_TO_VILLAGER(StatisticList.TALKED_TO_VILLAGER),
TRADED_WITH_VILLAGER(StatisticList.TRADED_WITH_VILLAGER),
CAKE_SLICES_EATEN(StatisticList.EAT_CAKE_SLICE),
CAULDRON_FILLED(StatisticList.FILL_CAULDRON),
CAULDRON_USED(StatisticList.USE_CAULDRON),
ARMOR_CLEANED(StatisticList.CLEAN_ARMOR),
BANNER_CLEANED(StatisticList.CLEAN_BANNER),
BREWINGSTAND_INTERACTION(StatisticList.INTERACT_WITH_BREWINGSTAND),
BEACON_INTERACTION(StatisticList.INTERACT_WITH_BEACON),
DROPPER_INSPECTED(StatisticList.INSPECT_DROPPER),
HOPPER_INSPECTED(StatisticList.INSPECT_HOPPER),
DISPENSER_INSPECTED(StatisticList.INSPECT_DISPENSER),
NOTEBLOCK_PLAYED(StatisticList.PLAY_NOTEBLOCK),
NOTEBLOCK_TUNED(StatisticList.TUNE_NOTEBLOCK),
FLOWER_POTTED(StatisticList.POT_FLOWER),
TRAPPED_CHEST_TRIGGERED(StatisticList.TRIGGER_TRAPPED_CHEST),
ENDERCHEST_OPENED(StatisticList.OPEN_ENDERCHEST),
ITEM_ENCHANTED(StatisticList.ENCHANT_ITEM),
RECORD_PLAYED(StatisticList.PLAY_RECORD),
FURNACE_INTERACTION(StatisticList.INTERACT_WITH_FURNACE),
CRAFTING_TABLE_INTERACTION(StatisticList.INTERACT_WITH_CRAFTING_TABLE),
CHEST_OPENED(StatisticList.OPEN_CHEST),
SLEEP_IN_BED(StatisticList.SLEEP_IN_BED),
SHULKER_BOX_OPENED(StatisticList.OPEN_SHULKER_BOX),
TIME_SINCE_REST(StatisticList.TIME_SINCE_REST),
SWIM_ONE_CM(StatisticList.SWIM_ONE_CM),
DAMAGE_DEALT_ABSORBED(StatisticList.DAMAGE_DEALT_ABSORBED),
DAMAGE_DEALT_RESISTED(StatisticList.DAMAGE_DEALT_RESISTED),
DAMAGE_BLOCKED_BY_SHIELD(StatisticList.DAMAGE_BLOCKED_BY_SHIELD),
DAMAGE_ABSORBED(StatisticList.DAMAGE_ABSORBED),
DAMAGE_RESISTED(StatisticList.DAMAGE_RESISTED),
CLEAN_SHULKER_BOX(StatisticList.CLEAN_SHULKER_BOX),
OPEN_BARREL(StatisticList.OPEN_BARREL),
INTERACT_WITH_BLAST_FURNACE(StatisticList.INTERACT_WITH_BLAST_FURNACE),
INTERACT_WITH_SMOKER(StatisticList.INTERACT_WITH_SMOKER),
INTERACT_WITH_LECTERN(StatisticList.INTERACT_WITH_LECTERN),
INTERACT_WITH_CAMPFIRE(StatisticList.INTERACT_WITH_CAMPFIRE),
INTERACT_WITH_CARTOGRAPHY_TABLE(StatisticList.INTERACT_WITH_CARTOGRAPHY_TABLE),
INTERACT_WITH_LOOM(StatisticList.INTERACT_WITH_LOOM),
INTERACT_WITH_STONECUTTER(StatisticList.INTERACT_WITH_STONECUTTER),
BELL_RING(StatisticList.BELL_RING),
RAID_TRIGGER(StatisticList.RAID_TRIGGER),
RAID_WIN(StatisticList.RAID_WIN),
INTERACT_WITH_ANVIL(StatisticList.INTERACT_WITH_ANVIL),
INTERACT_WITH_GRINDSTONE(StatisticList.INTERACT_WITH_GRINDSTONE),
TARGET_HIT(StatisticList.TARGET_HIT),
INTERACT_WITH_SMITHING_TABLE(StatisticList.INTERACT_WITH_SMITHING_TABLE),
STRIDER_ONE_CM(StatisticList.STRIDER_ONE_CM);
private final MinecraftKey minecraftKey;
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),
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),
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),
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),
INTERACT_WITH_BLAST_FURNACE(Stats.INTERACT_WITH_BLAST_FURNACE),
INTERACT_WITH_SMOKER(Stats.INTERACT_WITH_SMOKER),
INTERACT_WITH_LECTERN(Stats.INTERACT_WITH_LECTERN),
INTERACT_WITH_CAMPFIRE(Stats.INTERACT_WITH_CAMPFIRE),
INTERACT_WITH_CARTOGRAPHY_TABLE(Stats.INTERACT_WITH_CARTOGRAPHY_TABLE),
INTERACT_WITH_LOOM(Stats.INTERACT_WITH_LOOM),
INTERACT_WITH_STONECUTTER(Stats.INTERACT_WITH_STONECUTTER),
BELL_RING(Stats.BELL_RING),
RAID_TRIGGER(Stats.RAID_TRIGGER),
RAID_WIN(Stats.RAID_WIN),
INTERACT_WITH_ANVIL(Stats.INTERACT_WITH_ANVIL),
INTERACT_WITH_GRINDSTONE(Stats.INTERACT_WITH_GRINDSTONE),
TARGET_HIT(Stats.TARGET_HIT),
INTERACT_WITH_SMITHING_TABLE(Stats.INTERACT_WITH_SMITHING_TABLE),
STRIDER_ONE_CM(Stats.STRIDER_ONE_CM);
private final ResourceLocation minecraftKey;
private final org.bukkit.Statistic bukkit;
private static final BiMap<MinecraftKey, org.bukkit.Statistic> statistics;
private static final BiMap<ResourceLocation, org.bukkit.Statistic> statistics;
static {
ImmutableBiMap.Builder<MinecraftKey, org.bukkit.Statistic> statisticBuilder = ImmutableBiMap.builder();
ImmutableBiMap.Builder<ResourceLocation, org.bukkit.Statistic> statisticBuilder = ImmutableBiMap.builder();
for (CraftStatistic statistic : CraftStatistic.values()) {
statisticBuilder.put(statistic.minecraftKey, statistic.bukkit);
}
@@ -117,53 +116,53 @@ public enum CraftStatistic {
statistics = statisticBuilder.build();
}
private CraftStatistic(MinecraftKey minecraftKey) {
private CraftStatistic(ResourceLocation minecraftKey) {
this.minecraftKey = minecraftKey;
this.bukkit = org.bukkit.Statistic.valueOf(this.name());
Preconditions.checkState(bukkit != null, "Bukkit statistic %s does not exist", this.name());
Preconditions.checkState(this.bukkit != null, "Bukkit statistic %s does not exist", this.name());
}
public static org.bukkit.Statistic getBukkitStatistic(net.minecraft.stats.Statistic<?> statistic) {
public static org.bukkit.Statistic getBukkitStatistic(net.minecraft.stats.Stat<?> statistic) {
Preconditions.checkArgument(statistic != null, "NMS Statistic cannot be null");
IRegistry statRegistry = statistic.getType().getRegistry();
MinecraftKey nmsKey = BuiltInRegistries.STAT_TYPE.getKey(statistic.getType());
Registry statRegistry = statistic.getType().getRegistry();
ResourceLocation nmsKey = BuiltInRegistries.STAT_TYPE.getKey(statistic.getType());
if (statRegistry == BuiltInRegistries.CUSTOM_STAT) {
nmsKey = (MinecraftKey) statistic.getValue();
nmsKey = (ResourceLocation) statistic.getValue();
}
return statistics.get(nmsKey);
}
public static net.minecraft.stats.Statistic getNMSStatistic(org.bukkit.Statistic bukkit) {
public static net.minecraft.stats.Stat getNMSStatistic(org.bukkit.Statistic bukkit) {
Preconditions.checkArgument(bukkit.getType() == Statistic.Type.UNTYPED, "This method only accepts untyped statistics");
net.minecraft.stats.Statistic<MinecraftKey> nms = StatisticList.CUSTOM.get(statistics.inverse().get(bukkit));
net.minecraft.stats.Stat<ResourceLocation> nms = Stats.CUSTOM.get(statistics.inverse().get(bukkit));
Preconditions.checkArgument(nms != null, "NMS Statistic %s does not exist", bukkit);
return nms;
}
public static net.minecraft.stats.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
public static net.minecraft.stats.Stat getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
try {
if (stat == Statistic.MINE_BLOCK) {
return StatisticList.BLOCK_MINED.get(CraftBlockType.bukkitToMinecraft(material));
return Stats.BLOCK_MINED.get(CraftBlockType.bukkitToMinecraft(material));
}
if (stat == Statistic.CRAFT_ITEM) {
return StatisticList.ITEM_CRAFTED.get(CraftItemType.bukkitToMinecraft(material));
return Stats.ITEM_CRAFTED.get(CraftItemType.bukkitToMinecraft(material));
}
if (stat == Statistic.USE_ITEM) {
return StatisticList.ITEM_USED.get(CraftItemType.bukkitToMinecraft(material));
return Stats.ITEM_USED.get(CraftItemType.bukkitToMinecraft(material));
}
if (stat == Statistic.BREAK_ITEM) {
return StatisticList.ITEM_BROKEN.get(CraftItemType.bukkitToMinecraft(material));
return Stats.ITEM_BROKEN.get(CraftItemType.bukkitToMinecraft(material));
}
if (stat == Statistic.PICKUP) {
return StatisticList.ITEM_PICKED_UP.get(CraftItemType.bukkitToMinecraft(material));
return Stats.ITEM_PICKED_UP.get(CraftItemType.bukkitToMinecraft(material));
}
if (stat == Statistic.DROP) {
return StatisticList.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material));
return Stats.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material));
}
} catch (ArrayIndexOutOfBoundsException e) {
return null;
@@ -171,27 +170,27 @@ public enum CraftStatistic {
return null;
}
public static net.minecraft.stats.Statistic getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {
public static net.minecraft.stats.Stat getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {
Preconditions.checkArgument(entity != null, "EntityType cannot be null");
if (entity.getName() != null) {
EntityTypes<?> nmsEntity = CraftEntityType.bukkitToMinecraft(entity);
net.minecraft.world.entity.EntityType<?> nmsEntity = CraftEntityType.bukkitToMinecraft(entity);
if (stat == org.bukkit.Statistic.KILL_ENTITY) {
return net.minecraft.stats.StatisticList.ENTITY_KILLED.get(nmsEntity);
return net.minecraft.stats.Stats.ENTITY_KILLED.get(nmsEntity);
}
if (stat == org.bukkit.Statistic.ENTITY_KILLED_BY) {
return net.minecraft.stats.StatisticList.ENTITY_KILLED_BY.get(nmsEntity);
return net.minecraft.stats.Stats.ENTITY_KILLED_BY.get(nmsEntity);
}
}
return null;
}
public static EntityType getEntityTypeFromStatistic(net.minecraft.stats.Statistic<EntityTypes<?>> statistic) {
public static EntityType getEntityTypeFromStatistic(net.minecraft.stats.Stat<net.minecraft.world.entity.EntityType<?>> statistic) {
Preconditions.checkArgument(statistic != null, "NMS Statistic cannot be null");
return CraftEntityType.minecraftToBukkit(statistic.getValue());
}
public static Material getMaterialFromStatistic(net.minecraft.stats.Statistic<?> statistic) {
public static Material getMaterialFromStatistic(net.minecraft.stats.Stat<?> statistic) {
if (statistic.getValue() instanceof Item statisticItemValue) {
return CraftItemType.minecraftToBukkit(statisticItemValue);
}
@@ -201,35 +200,35 @@ public enum CraftStatistic {
return null;
}
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityPlayer player) {
public static void incrementStatistic(ServerStatsCounter manager, Statistic statistic, ServerPlayer player) {
incrementStatistic(manager, statistic, 1, player);
}
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityPlayer player) {
public static void decrementStatistic(ServerStatsCounter manager, Statistic statistic, ServerPlayer player) {
decrementStatistic(manager, statistic, 1, player);
}
public static int getStatistic(ServerStatisticManager manager, Statistic statistic) {
public static int getStatistic(ServerStatsCounter manager, Statistic statistic) {
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
Preconditions.checkArgument(statistic.getType() == Type.UNTYPED, "Must supply additional parameter for this statistic");
return manager.getValue(CraftStatistic.getNMSStatistic(statistic));
}
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount, EntityPlayer player) {
public static void incrementStatistic(ServerStatsCounter manager, Statistic statistic, int amount, ServerPlayer player) {
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
setStatistic(manager, statistic, getStatistic(manager, statistic) + amount, player);
}
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, int amount, EntityPlayer player) {
public static void decrementStatistic(ServerStatsCounter manager, Statistic statistic, int amount, ServerPlayer player) {
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
setStatistic(manager, statistic, getStatistic(manager, statistic) - amount, player);
}
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, int newValue, EntityPlayer player) {
public static void setStatistic(ServerStatsCounter manager, Statistic statistic, int newValue, ServerPlayer player) {
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
Preconditions.checkArgument(statistic.getType() == Type.UNTYPED, "Must supply additional parameter for this statistic");
Preconditions.checkArgument(newValue >= 0, "Value must be greater than or equal to 0");
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getNMSStatistic(statistic);
net.minecraft.stats.Stat nmsStatistic = CraftStatistic.getNMSStatistic(statistic);
manager.setValue(null, nmsStatistic, newValue);
// Update scoreboards
@@ -240,39 +239,39 @@ public enum CraftStatistic {
}
}
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, EntityPlayer player) {
public static void incrementStatistic(ServerStatsCounter manager, Statistic statistic, Material material, ServerPlayer player) {
incrementStatistic(manager, statistic, material, 1, player);
}
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, EntityPlayer player) {
public static void decrementStatistic(ServerStatsCounter manager, Statistic statistic, Material material, ServerPlayer player) {
decrementStatistic(manager, statistic, material, 1, player);
}
public static int getStatistic(ServerStatisticManager manager, Statistic statistic, Material material) {
public static int getStatistic(ServerStatsCounter manager, Statistic statistic, Material material) {
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
Preconditions.checkArgument(material != null, "Material cannot be null");
Preconditions.checkArgument(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter");
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material);
net.minecraft.stats.Stat nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material);
Preconditions.checkArgument(nmsStatistic != null, "The supplied Material %s does not have a corresponding statistic", material);
return manager.getValue(nmsStatistic);
}
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount, EntityPlayer player) {
public static void incrementStatistic(ServerStatsCounter manager, Statistic statistic, Material material, int amount, ServerPlayer player) {
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) + amount, player);
}
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int amount, EntityPlayer player) {
public static void decrementStatistic(ServerStatsCounter manager, Statistic statistic, Material material, int amount, ServerPlayer player) {
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
setStatistic(manager, statistic, material, getStatistic(manager, statistic, material) - amount, player);
}
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, Material material, int newValue, EntityPlayer player) {
public static void setStatistic(ServerStatsCounter manager, Statistic statistic, Material material, int newValue, ServerPlayer player) {
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
Preconditions.checkArgument(material != null, "Material cannot be null");
Preconditions.checkArgument(newValue >= 0, "Value must be greater than or equal to 0");
Preconditions.checkArgument(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter");
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material);
net.minecraft.stats.Stat nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material);
Preconditions.checkArgument(nmsStatistic != null, "The supplied Material %s does not have a corresponding statistic", material);
manager.setValue(null, nmsStatistic, newValue);
@@ -284,39 +283,39 @@ public enum CraftStatistic {
}
}
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, EntityPlayer player) {
public static void incrementStatistic(ServerStatsCounter manager, Statistic statistic, EntityType entityType, ServerPlayer player) {
incrementStatistic(manager, statistic, entityType, 1, player);
}
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, EntityPlayer player) {
public static void decrementStatistic(ServerStatsCounter manager, Statistic statistic, EntityType entityType, ServerPlayer player) {
decrementStatistic(manager, statistic, entityType, 1, player);
}
public static int getStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType) {
public static int getStatistic(ServerStatsCounter manager, Statistic statistic, EntityType entityType) {
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
Preconditions.checkArgument(entityType != null, "EntityType cannot be null");
Preconditions.checkArgument(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter");
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType);
net.minecraft.stats.Stat nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType);
Preconditions.checkArgument(nmsStatistic != null, "The supplied EntityType %s does not have a corresponding statistic", entityType);
return manager.getValue(nmsStatistic);
}
public static void incrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount, EntityPlayer player) {
public static void incrementStatistic(ServerStatsCounter manager, Statistic statistic, EntityType entityType, int amount, ServerPlayer player) {
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) + amount, player);
}
public static void decrementStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int amount, EntityPlayer player) {
public static void decrementStatistic(ServerStatsCounter manager, Statistic statistic, EntityType entityType, int amount, ServerPlayer player) {
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
setStatistic(manager, statistic, entityType, getStatistic(manager, statistic, entityType) - amount, player);
}
public static void setStatistic(ServerStatisticManager manager, Statistic statistic, EntityType entityType, int newValue, EntityPlayer player) {
public static void setStatistic(ServerStatsCounter manager, Statistic statistic, EntityType entityType, int newValue, ServerPlayer player) {
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
Preconditions.checkArgument(entityType != null, "EntityType cannot be null");
Preconditions.checkArgument(newValue >= 0, "Value must be greater than or equal to 0");
Preconditions.checkArgument(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter");
net.minecraft.stats.Statistic nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType);
net.minecraft.stats.Stat nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType);
Preconditions.checkArgument(nmsStatistic != null, "The supplied EntityType %s does not have a corresponding statistic", entityType);
manager.setValue(null, nmsStatistic, newValue);

View File

@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import java.util.concurrent.TimeUnit;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
@@ -24,7 +24,7 @@ public class CraftWorldBorder implements WorldBorder {
@Override
public World getWorld() {
return world;
return this.world;
}
@Override
@@ -44,7 +44,7 @@ public class CraftWorldBorder implements WorldBorder {
@Override
public void setSize(double newSize, long time) {
setSize(Math.min(getMaxSize(), Math.max(1.0D, newSize)), TimeUnit.SECONDS, Math.min(9223372036854775L, Math.max(0L, time)));
this.setSize(Math.min(this.getMaxSize(), Math.max(1.0D, newSize)), TimeUnit.SECONDS, Math.min(9223372036854775L, Math.max(0L, time)));
}
@Override
@@ -125,7 +125,7 @@ public class CraftWorldBorder implements WorldBorder {
public boolean isInside(Location location) {
Preconditions.checkArgument(location != null, "location cannot be null");
return (world == null || location.getWorld().equals(this.world)) && this.handle.isWithinBounds(BlockPosition.containing(location.getX(), location.getY(), location.getZ()));
return (this.world == null || location.getWorld().equals(this.world)) && this.handle.isWithinBounds(BlockPos.containing(location.getX(), location.getY(), location.getZ()));
}
@Override
@@ -139,10 +139,10 @@ public class CraftWorldBorder implements WorldBorder {
}
public net.minecraft.world.level.border.WorldBorder getHandle() {
return handle;
return this.handle;
}
public boolean isVirtual() {
return world == null;
return this.world == null;
}
}

View File

@@ -23,117 +23,117 @@ public class Main {
// Todo: Installation script
OptionParser parser = new OptionParser() {
{
acceptsAll(asList("?", "help"), "Show the help");
this.acceptsAll(Main.asList("?", "help"), "Show the help");
acceptsAll(asList("c", "config"), "Properties file to use")
this.acceptsAll(Main.asList("c", "config"), "Properties file to use")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("server.properties"))
.describedAs("Properties file");
acceptsAll(asList("P", "plugins"), "Plugin directory to use")
this.acceptsAll(Main.asList("P", "plugins"), "Plugin directory to use")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("plugins"))
.describedAs("Plugin directory");
acceptsAll(asList("h", "host", "server-ip"), "Host to listen on")
this.acceptsAll(Main.asList("h", "host", "server-ip"), "Host to listen on")
.withRequiredArg()
.ofType(String.class)
.describedAs("Hostname or IP");
acceptsAll(asList("W", "world-dir", "universe", "world-container"), "World container")
this.acceptsAll(Main.asList("W", "world-dir", "universe", "world-container"), "World container")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("."))
.describedAs("Directory containing worlds");
acceptsAll(asList("w", "world", "level-name"), "World name")
this.acceptsAll(Main.asList("w", "world", "level-name"), "World name")
.withRequiredArg()
.ofType(String.class)
.describedAs("World name");
acceptsAll(asList("p", "port", "server-port"), "Port to listen on")
this.acceptsAll(Main.asList("p", "port", "server-port"), "Port to listen on")
.withRequiredArg()
.ofType(Integer.class)
.describedAs("Port");
accepts("serverId", "Server ID")
this.accepts("serverId", "Server ID")
.withRequiredArg();
accepts("jfrProfile", "Enable JFR profiling");
this.accepts("jfrProfile", "Enable JFR profiling");
accepts("pidFile", "pid File")
this.accepts("pidFile", "pid File")
.withRequiredArg()
.withValuesConvertedBy(new PathConverter());
acceptsAll(asList("o", "online-mode"), "Whether to use online authentication")
this.acceptsAll(Main.asList("o", "online-mode"), "Whether to use online authentication")
.withRequiredArg()
.ofType(Boolean.class)
.describedAs("Authentication");
acceptsAll(asList("s", "size", "max-players"), "Maximum amount of players")
this.acceptsAll(Main.asList("s", "size", "max-players"), "Maximum amount of players")
.withRequiredArg()
.ofType(Integer.class)
.describedAs("Server size");
acceptsAll(asList("d", "date-format"), "Format of the date to display in the console (for log entries)")
this.acceptsAll(Main.asList("d", "date-format"), "Format of the date to display in the console (for log entries)")
.withRequiredArg()
.ofType(SimpleDateFormat.class)
.describedAs("Log date format");
acceptsAll(asList("log-pattern"), "Specfies the log filename pattern")
this.acceptsAll(Main.asList("log-pattern"), "Specfies the log filename pattern")
.withRequiredArg()
.ofType(String.class)
.defaultsTo("server.log")
.describedAs("Log filename");
acceptsAll(asList("log-limit"), "Limits the maximum size of the log file (0 = unlimited)")
this.acceptsAll(Main.asList("log-limit"), "Limits the maximum size of the log file (0 = unlimited)")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(0)
.describedAs("Max log size");
acceptsAll(asList("log-count"), "Specified how many log files to cycle through")
this.acceptsAll(Main.asList("log-count"), "Specified how many log files to cycle through")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(1)
.describedAs("Log count");
acceptsAll(asList("log-append"), "Whether to append to the log file")
this.acceptsAll(Main.asList("log-append"), "Whether to append to the log file")
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(true)
.describedAs("Log append");
acceptsAll(asList("log-strip-color"), "Strips color codes from log file");
this.acceptsAll(Main.asList("log-strip-color"), "Strips color codes from log file");
acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
this.acceptsAll(Main.asList("b", "bukkit-settings"), "File for bukkit settings")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("bukkit.yml"))
.describedAs("Yml file");
acceptsAll(asList("C", "commands-settings"), "File for command settings")
this.acceptsAll(Main.asList("C", "commands-settings"), "File for command settings")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("commands.yml"))
.describedAs("Yml file");
acceptsAll(asList("forceUpgrade"), "Whether to force a world upgrade");
acceptsAll(asList("eraseCache"), "Whether to force cache erase during world upgrade");
acceptsAll(asList("recreateRegionFiles"), "Whether to recreate region files during world upgrade");
acceptsAll(asList("nogui"), "Disables the graphical console");
this.acceptsAll(Main.asList("forceUpgrade"), "Whether to force a world upgrade");
this.acceptsAll(Main.asList("eraseCache"), "Whether to force cache erase during world upgrade");
this.acceptsAll(Main.asList("recreateRegionFiles"), "Whether to recreate region files during world upgrade");
this.acceptsAll(Main.asList("nogui"), "Disables the graphical console");
acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");
this.acceptsAll(Main.asList("nojline"), "Disables jline and emulates the vanilla console");
acceptsAll(asList("noconsole"), "Disables the console");
this.acceptsAll(Main.asList("noconsole"), "Disables the console");
acceptsAll(asList("v", "version"), "Show the CraftBukkit Version");
this.acceptsAll(Main.asList("v", "version"), "Show the CraftBukkit Version");
acceptsAll(asList("demo"), "Demo mode");
this.acceptsAll(Main.asList("demo"), "Demo mode");
acceptsAll(asList("initSettings"), "Only create configuration files and then exit"); // SPIGOT-5761: Add initSettings option
this.acceptsAll(Main.asList("initSettings"), "Only create configuration files and then exit"); // SPIGOT-5761: Add initSettings option
}
};
@@ -172,14 +172,14 @@ public class Main {
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'});
useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal));
Main.useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal));
if (options.has("nojline")) {
System.setProperty("user.language", "en");
useJline = false;
Main.useJline = false;
}
if (useJline) {
if (Main.useJline) {
AnsiConsole.systemInstall();
} else {
// This ensures the terminal literal will always match the jline implementation
@@ -187,7 +187,7 @@ public class Main {
}
if (options.has("noconsole")) {
useConsole = false;
Main.useConsole = false;
}
if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {

View File

@@ -17,30 +17,30 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
}
public AdvancementHolder getHandle() {
return handle;
return this.handle;
}
@Override
public NamespacedKey getKey() {
return CraftNamespacedKey.fromMinecraft(handle.id());
return CraftNamespacedKey.fromMinecraft(this.handle.id());
}
@Override
public Collection<String> getCriteria() {
return Collections.unmodifiableCollection(handle.value().criteria().keySet());
return Collections.unmodifiableCollection(this.handle.value().criteria().keySet());
}
@Override
public AdvancementRequirements getRequirements() {
return new CraftAdvancementRequirements(handle.value().requirements());
return new CraftAdvancementRequirements(this.handle.value().requirements());
}
@Override
public AdvancementDisplay getDisplay() {
if (handle.value().display().isEmpty()) {
if (this.handle.value().display().isEmpty()) {
return null;
}
return new CraftAdvancementDisplay(handle.value().display().get());
return new CraftAdvancementDisplay(this.handle.value().display().get());
}
}

View File

@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.advancement;
import net.minecraft.advancements.AdvancementDisplay;
import net.minecraft.advancements.DisplayInfo;
import org.bukkit.advancement.AdvancementDisplayType;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftChatMessage;
@@ -8,58 +8,58 @@ import org.bukkit.inventory.ItemStack;
public class CraftAdvancementDisplay implements org.bukkit.advancement.AdvancementDisplay {
private final AdvancementDisplay handle;
private final DisplayInfo handle;
public CraftAdvancementDisplay(AdvancementDisplay handle) {
public CraftAdvancementDisplay(DisplayInfo handle) {
this.handle = handle;
}
public AdvancementDisplay getHandle() {
return handle;
public DisplayInfo getHandle() {
return this.handle;
}
@Override
public String getTitle() {
return CraftChatMessage.fromComponent(handle.getTitle());
return CraftChatMessage.fromComponent(this.handle.getTitle());
}
@Override
public String getDescription() {
return CraftChatMessage.fromComponent(handle.getDescription());
return CraftChatMessage.fromComponent(this.handle.getDescription());
}
@Override
public ItemStack getIcon() {
return CraftItemStack.asBukkitCopy(handle.getIcon());
return CraftItemStack.asBukkitCopy(this.handle.getIcon());
}
@Override
public boolean shouldShowToast() {
return handle.shouldShowToast();
return this.handle.shouldShowToast();
}
@Override
public boolean shouldAnnounceChat() {
return handle.shouldAnnounceChat();
return this.handle.shouldAnnounceChat();
}
@Override
public boolean isHidden() {
return handle.isHidden();
return this.handle.isHidden();
}
@Override
public float getX() {
return handle.getX();
return this.handle.getX();
}
@Override
public float getY() {
return handle.getY();
return this.handle.getY();
}
@Override
public AdvancementDisplayType getType() {
return AdvancementDisplayType.values()[handle.getType().ordinal()];
return AdvancementDisplayType.values()[this.handle.getType().ordinal()];
}
}

View File

@@ -5,17 +5,17 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import net.minecraft.advancements.CriterionProgress;
import net.minecraft.server.AdvancementDataPlayer;
import net.minecraft.server.PlayerAdvancements;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
public class CraftAdvancementProgress implements AdvancementProgress {
private final CraftAdvancement advancement;
private final AdvancementDataPlayer playerData;
private final PlayerAdvancements playerData;
private final net.minecraft.advancements.AdvancementProgress handle;
public CraftAdvancementProgress(CraftAdvancement advancement, AdvancementDataPlayer player, net.minecraft.advancements.AdvancementProgress handle) {
public CraftAdvancementProgress(CraftAdvancement advancement, PlayerAdvancements player, net.minecraft.advancements.AdvancementProgress handle) {
this.advancement = advancement;
this.playerData = player;
this.handle = handle;
@@ -23,37 +23,37 @@ public class CraftAdvancementProgress implements AdvancementProgress {
@Override
public Advancement getAdvancement() {
return advancement;
return this.advancement;
}
@Override
public boolean isDone() {
return handle.isDone();
return this.handle.isDone();
}
@Override
public boolean awardCriteria(String criteria) {
return playerData.award(advancement.getHandle(), criteria);
return this.playerData.award(this.advancement.getHandle(), criteria);
}
@Override
public boolean revokeCriteria(String criteria) {
return playerData.revoke(advancement.getHandle(), criteria);
return this.playerData.revoke(this.advancement.getHandle(), criteria);
}
@Override
public Date getDateAwarded(String criteria) {
CriterionProgress criterion = handle.getCriterion(criteria);
CriterionProgress criterion = this.handle.getCriterion(criteria);
return (criterion == null) ? null : Date.from(criterion.getObtained());
}
@Override
public Collection<String> getRemainingCriteria() {
return Collections.unmodifiableCollection(Lists.newArrayList(handle.getRemainingCriteria()));
return Collections.unmodifiableCollection(Lists.newArrayList(this.handle.getRemainingCriteria()));
}
@Override
public Collection<String> getAwardedCriteria() {
return Collections.unmodifiableCollection(Lists.newArrayList(handle.getCompletedCriteria()));
return Collections.unmodifiableCollection(Lists.newArrayList(this.handle.getCompletedCriteria()));
}
}

View File

@@ -16,11 +16,11 @@ public class CraftAdvancementRequirement implements AdvancementRequirement {
@NotNull
@Override
public List<String> getRequiredCriteria() {
return Collections.unmodifiableList(requirements);
return Collections.unmodifiableList(this.requirements);
}
@Override
public boolean isStrict() {
return requirements.size() == 1;
return this.requirements.size() == 1;
}
}

View File

@@ -16,6 +16,6 @@ public class CraftAdvancementRequirements implements org.bukkit.advancement.Adva
@NotNull
@Override
public List<AdvancementRequirement> getRequirements() {
return requirements.requirements().stream().map((requirement) -> (AdvancementRequirement) new CraftAdvancementRequirement(requirement)).toList();
return this.requirements.requirements().stream().map((requirement) -> (AdvancementRequirement) new CraftAdvancementRequirement(requirement)).toList();
}
}

View File

@@ -3,9 +3,7 @@ package org.bukkit.craftbukkit.attribute;
import com.google.common.base.Preconditions;
import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.ai.attributes.AttributeBase;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.attribute.Attribute;
@@ -15,16 +13,16 @@ import org.bukkit.craftbukkit.util.ApiVersion;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
public class CraftAttribute implements Attribute, Handleable<net.minecraft.world.entity.ai.attributes.Attribute> {
private static int count = 0;
public static Attribute minecraftToBukkit(AttributeBase minecraft) {
public static Attribute minecraftToBukkit(net.minecraft.world.entity.ai.attributes.Attribute minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.ATTRIBUTE, Registry.ATTRIBUTE);
}
public static Attribute minecraftHolderToBukkit(Holder<AttributeBase> minecraft) {
return minecraftToBukkit(minecraft.value());
public static Attribute minecraftHolderToBukkit(Holder<net.minecraft.world.entity.ai.attributes.Attribute> minecraft) {
return CraftAttribute.minecraftToBukkit(minecraft.value());
}
public static Attribute stringToBukkit(String string) {
@@ -40,16 +38,16 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
return CraftRegistry.get(Registry.ATTRIBUTE, key, ApiVersion.CURRENT);
}
public static AttributeBase bukkitToMinecraft(Attribute bukkit) {
public static net.minecraft.world.entity.ai.attributes.Attribute bukkitToMinecraft(Attribute bukkit) {
return CraftRegistry.bukkitToMinecraft(bukkit);
}
public static Holder<AttributeBase> bukkitToMinecraftHolder(Attribute bukkit) {
public static Holder<net.minecraft.world.entity.ai.attributes.Attribute> bukkitToMinecraftHolder(Attribute bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<AttributeBase> registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE);
net.minecraft.core.Registry<net.minecraft.world.entity.ai.attributes.Attribute> registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<AttributeBase> holder) {
if (registry.wrapAsHolder(CraftAttribute.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.entity.ai.attributes.Attribute> holder) {
return holder;
}
@@ -64,11 +62,11 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
}
private final NamespacedKey key;
private final AttributeBase attributeBase;
private final net.minecraft.world.entity.ai.attributes.Attribute attributeBase;
private final String name;
private final int ordinal;
public CraftAttribute(NamespacedKey key, AttributeBase attributeBase) {
public CraftAttribute(NamespacedKey key, net.minecraft.world.entity.ai.attributes.Attribute attributeBase) {
this.key = key;
this.attributeBase = attributeBase;
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
@@ -80,46 +78,46 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
} else {
this.name = key.toString();
}
this.ordinal = count++;
this.ordinal = CraftAttribute.count++;
}
@Override
public AttributeBase getHandle() {
return attributeBase;
public net.minecraft.world.entity.ai.attributes.Attribute getHandle() {
return this.attributeBase;
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@NotNull
@Override
public String getTranslationKey() {
return attributeBase.getDescriptionId();
return this.attributeBase.getDescriptionId();
}
@Override
public int compareTo(@NotNull Attribute attribute) {
return ordinal - attribute.ordinal();
return this.ordinal - attribute.ordinal();
}
@NotNull
@Override
public String name() {
return name;
return this.name;
}
@Override
public int ordinal() {
return ordinal;
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return name();
return this.name();
}
@Override
@@ -132,11 +130,11 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
return false;
}
return getKey().equals(otherAttribute.getKey());
return this.getKey().equals(otherAttribute.getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
}

View File

@@ -12,34 +12,34 @@ import org.bukkit.inventory.EquipmentSlot;
public class CraftAttributeInstance implements AttributeInstance {
private final net.minecraft.world.entity.ai.attributes.AttributeModifiable handle;
private final net.minecraft.world.entity.ai.attributes.AttributeInstance handle;
private final Attribute attribute;
public CraftAttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeModifiable handle, Attribute attribute) {
public CraftAttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance handle, Attribute attribute) {
this.handle = handle;
this.attribute = attribute;
}
@Override
public Attribute getAttribute() {
return attribute;
return this.attribute;
}
@Override
public double getBaseValue() {
return handle.getBaseValue();
return this.handle.getBaseValue();
}
@Override
public void setBaseValue(double d) {
handle.setBaseValue(d);
this.handle.setBaseValue(d);
}
@Override
public Collection<AttributeModifier> getModifiers() {
List<AttributeModifier> result = new ArrayList<AttributeModifier>();
for (net.minecraft.world.entity.ai.attributes.AttributeModifier nms : handle.getModifiers()) {
result.add(convert(nms));
for (net.minecraft.world.entity.ai.attributes.AttributeModifier nms : this.handle.getModifiers()) {
result.add(CraftAttributeInstance.convert(nms));
}
return result;
@@ -48,23 +48,23 @@ public class CraftAttributeInstance implements AttributeInstance {
@Override
public void addModifier(AttributeModifier modifier) {
Preconditions.checkArgument(modifier != null, "modifier");
handle.addPermanentModifier(convert(modifier));
this.handle.addPermanentModifier(CraftAttributeInstance.convert(modifier));
}
@Override
public void removeModifier(AttributeModifier modifier) {
Preconditions.checkArgument(modifier != null, "modifier");
handle.removeModifier(convert(modifier));
this.handle.removeModifier(CraftAttributeInstance.convert(modifier));
}
@Override
public double getValue() {
return handle.getValue();
return this.handle.getValue();
}
@Override
public double getDefaultValue() {
return handle.getAttribute().value().getDefaultValue();
return this.handle.getAttribute().value().getDefaultValue();
}
public static net.minecraft.world.entity.ai.attributes.AttributeModifier convert(AttributeModifier bukkit) {

View File

@@ -1,23 +1,23 @@
package org.bukkit.craftbukkit.attribute;
import com.google.common.base.Preconditions;
import net.minecraft.world.entity.ai.attributes.AttributeMapBase;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
public class CraftAttributeMap implements Attributable {
private final AttributeMapBase handle;
private final AttributeMap handle;
public CraftAttributeMap(AttributeMapBase handle) {
public CraftAttributeMap(AttributeMap handle) {
this.handle = handle;
}
@Override
public AttributeInstance getAttribute(Attribute attribute) {
Preconditions.checkArgument(attribute != null, "attribute");
net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(CraftAttribute.bukkitToMinecraftHolder(attribute));
net.minecraft.world.entity.ai.attributes.AttributeInstance nms = this.handle.getInstance(CraftAttribute.bukkitToMinecraftHolder(attribute));
return (nms == null) ? null : new CraftAttributeInstance(nms, attribute);
}

View File

@@ -4,8 +4,8 @@ import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.time.Instant;
import java.util.Date;
import net.minecraft.server.players.IpBanEntry;
import net.minecraft.server.players.IpBanList;
import net.minecraft.server.players.IpBanListEntry;
import org.bukkit.BanEntry;
public final class CraftIpBanEntry implements BanEntry<InetAddress> {
@@ -17,7 +17,7 @@ public final class CraftIpBanEntry implements BanEntry<InetAddress> {
private Date expiration;
private String reason;
public CraftIpBanEntry(String target, IpBanEntry entry, IpBanList list) {
public CraftIpBanEntry(String target, IpBanListEntry entry, IpBanList list) {
this.list = list;
this.target = target;
this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
@@ -63,7 +63,7 @@ public final class CraftIpBanEntry implements BanEntry<InetAddress> {
@Override
public void setExpiration(Date expiration) {
if (expiration != null && expiration.getTime() == minorDate.getTime()) {
if (expiration != null && expiration.getTime() == CraftIpBanEntry.minorDate.getTime()) {
expiration = null; // Forces "forever"
}
@@ -82,12 +82,12 @@ public final class CraftIpBanEntry implements BanEntry<InetAddress> {
@Override
public void save() {
IpBanEntry entry = new IpBanEntry(this.target, this.created, this.source, this.expiration, this.reason);
IpBanListEntry entry = new IpBanListEntry(this.target, this.created, this.source, this.expiration, this.reason);
this.list.add(entry);
}
@Override
public void remove() {
this.list.remove(target);
this.list.remove(this.target);
}
}

View File

@@ -8,8 +8,8 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Set;
import net.minecraft.server.players.IpBanEntry;
import net.minecraft.server.players.IpBanList;
import net.minecraft.server.players.IpBanListEntry;
import org.bukkit.BanEntry;
public class CraftIpBanList implements org.bukkit.ban.IpBanList {
@@ -23,12 +23,12 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
public BanEntry<InetAddress> getBanEntry(String target) {
Preconditions.checkArgument(target != null, "Target cannot be null");
IpBanEntry entry = this.list.get(target);
IpBanListEntry entry = this.list.get(target);
if (entry == null) {
return null;
}
return new CraftIpBanEntry(target, entry, list);
return new CraftIpBanEntry(target, entry, this.list);
}
@Override
@@ -40,13 +40,13 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
public BanEntry<InetAddress> addBan(String target, String reason, Date expires, String source) {
Preconditions.checkArgument(target != null, "Ban target cannot be null");
IpBanEntry entry = new IpBanEntry(target, new Date(),
IpBanListEntry entry = new IpBanListEntry(target, new Date(),
(source == null || source.isBlank()) ? null : source, expires,
(reason == null || reason.isBlank()) ? null : reason);
this.list.add(entry);
return new CraftIpBanEntry(target, entry, list);
return new CraftIpBanEntry(target, entry, this.list);
}
@Override
@@ -57,22 +57,22 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
@Override
public BanEntry<InetAddress> addBan(InetAddress target, String reason, Instant expires, String source) {
Date date = expires != null ? Date.from(expires) : null;
return addBan(target, reason, date, source);
return this.addBan(target, reason, date, source);
}
@Override
public BanEntry<InetAddress> addBan(InetAddress target, String reason, Duration duration, String source) {
Instant instant = duration != null ? Instant.now().plus(duration) : null;
return addBan(target, reason, instant, source);
return this.addBan(target, reason, instant, source);
}
@Override
public Set<BanEntry> getBanEntries() {
ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();
for (String target : list.getUserList()) {
IpBanEntry ipBanEntry = list.get(target);
for (String target : this.list.getUserList()) {
IpBanListEntry ipBanEntry = this.list.get(target);
if (ipBanEntry != null) {
builder.add(new CraftIpBanEntry(target, ipBanEntry, list));
builder.add(new CraftIpBanEntry(target, ipBanEntry, this.list));
}
}
return builder.build();
@@ -81,10 +81,10 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
@Override
public Set<BanEntry<InetAddress>> getEntries() {
ImmutableSet.Builder<BanEntry<InetAddress>> builder = ImmutableSet.builder();
for (String target : list.getUserList()) {
IpBanEntry ipBanEntry = list.get(target);
for (String target : this.list.getUserList()) {
IpBanListEntry ipBanEntry = this.list.get(target);
if (ipBanEntry != null) {
builder.add(new CraftIpBanEntry(target, ipBanEntry, list));
builder.add(new CraftIpBanEntry(target, ipBanEntry, this.list));
}
}
return builder.build();
@@ -98,7 +98,7 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
@Override
public boolean isBanned(InetAddress target) {
return this.isBanned(getIpFromAddress(target));
return this.isBanned(this.getIpFromAddress(target));
}
@Override
@@ -109,7 +109,7 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
@Override
public void pardon(InetAddress target) {
this.pardon(getIpFromAddress(target));
this.pardon(this.getIpFromAddress(target));
}
private String getIpFromAddress(InetAddress address) {

View File

@@ -3,22 +3,22 @@ package org.bukkit.craftbukkit.ban;
import com.mojang.authlib.GameProfile;
import java.time.Instant;
import java.util.Date;
import net.minecraft.server.players.GameProfileBanEntry;
import net.minecraft.server.players.GameProfileBanList;
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<PlayerProfile> {
private static final Date minorDate = Date.from(Instant.parse("1899-12-31T04:00:00Z"));
private final GameProfileBanList list;
private final UserBanList list;
private final GameProfile profile;
private Date created;
private String source;
private Date expiration;
private String reason;
public CraftProfileBanEntry(GameProfile profile, GameProfileBanEntry entry, GameProfileBanList list) {
public CraftProfileBanEntry(GameProfile profile, UserBanListEntry entry, UserBanList list) {
this.list = list;
this.profile = profile;
this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
@@ -64,7 +64,7 @@ public final class CraftProfileBanEntry implements BanEntry<PlayerProfile> {
@Override
public void setExpiration(Date expiration) {
if (expiration != null && expiration.getTime() == minorDate.getTime()) {
if (expiration != null && expiration.getTime() == CraftProfileBanEntry.minorDate.getTime()) {
expiration = null; // Forces "forever"
}
@@ -83,7 +83,7 @@ public final class CraftProfileBanEntry implements BanEntry<PlayerProfile> {
@Override
public void save() {
GameProfileBanEntry entry = new GameProfileBanEntry(this.profile, this.created, this.source, this.expiration, this.reason);
UserBanListEntry entry = new UserBanListEntry(this.profile, this.created, this.source, this.expiration, this.reason);
this.list.add(entry);
}

View File

@@ -9,17 +9,17 @@ import java.util.Date;
import java.util.Set;
import java.util.UUID;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.players.GameProfileBanEntry;
import net.minecraft.server.players.GameProfileBanList;
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 {
private final GameProfileBanList list;
private final UserBanList list;
public CraftProfileBanList(GameProfileBanList list) {
public CraftProfileBanList(UserBanList list) {
this.list = list;
}
@@ -27,7 +27,7 @@ public class CraftProfileBanList implements ProfileBanList {
public BanEntry<PlayerProfile> getBanEntry(String target) {
Preconditions.checkArgument(target != null, "Target cannot be null");
return this.getBanEntry(getProfile(target));
return this.getBanEntry(CraftProfileBanList.getProfile(target));
}
@Override
@@ -41,7 +41,7 @@ public class CraftProfileBanList implements ProfileBanList {
public BanEntry<PlayerProfile> addBan(String target, String reason, Date expires, String source) {
Preconditions.checkArgument(target != null, "Ban target cannot be null");
return this.addBan(getProfileByName(target), reason, expires, source);
return this.addBan(CraftProfileBanList.getProfileByName(target), reason, expires, source);
}
@Override
@@ -55,21 +55,21 @@ public class CraftProfileBanList implements ProfileBanList {
@Override
public BanEntry<PlayerProfile> addBan(PlayerProfile target, String reason, Instant expires, String source) {
Date date = expires != null ? Date.from(expires) : null;
return addBan(target, reason, date, source);
return this.addBan(target, reason, date, source);
}
@Override
public BanEntry<PlayerProfile> addBan(PlayerProfile target, String reason, Duration duration, String source) {
Instant instant = duration != null ? Instant.now().plus(duration) : null;
return addBan(target, reason, instant, source);
return this.addBan(target, reason, instant, source);
}
@Override
public Set<BanEntry> getBanEntries() {
ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();
for (GameProfileBanEntry entry : list.getEntries()) {
for (UserBanListEntry entry : this.list.getEntries()) {
GameProfile profile = entry.getUser();
builder.add(new CraftProfileBanEntry(profile, entry, list));
builder.add(new CraftProfileBanEntry(profile, entry, this.list));
}
return builder.build();
@@ -78,9 +78,9 @@ public class CraftProfileBanList implements ProfileBanList {
@Override
public Set<BanEntry<PlayerProfile>> getEntries() {
ImmutableSet.Builder<BanEntry<PlayerProfile>> builder = ImmutableSet.builder();
for (GameProfileBanEntry entry : list.getEntries()) {
for (UserBanListEntry entry : this.list.getEntries()) {
GameProfile profile = entry.getUser();
builder.add(new CraftProfileBanEntry(profile, entry, list));
builder.add(new CraftProfileBanEntry(profile, entry, this.list));
}
return builder.build();
@@ -97,7 +97,7 @@ public class CraftProfileBanList implements ProfileBanList {
public boolean isBanned(String target) {
Preconditions.checkArgument(target != null, "Target cannot be null");
return this.isBanned(getProfile(target));
return this.isBanned(CraftProfileBanList.getProfile(target));
}
@Override
@@ -111,7 +111,7 @@ public class CraftProfileBanList implements ProfileBanList {
public void pardon(String target) {
Preconditions.checkArgument(target != null, "Target cannot be null");
this.pardon(getProfile(target));
this.pardon(CraftProfileBanList.getProfile(target));
}
public BanEntry<PlayerProfile> getBanEntry(GameProfile profile) {
@@ -119,12 +119,12 @@ public class CraftProfileBanList implements ProfileBanList {
return null;
}
GameProfileBanEntry entry = list.get(profile);
UserBanListEntry entry = this.list.get(profile);
if (entry == null) {
return null;
}
return new CraftProfileBanEntry(profile, entry, list);
return new CraftProfileBanEntry(profile, entry, this.list);
}
public BanEntry<PlayerProfile> addBan(GameProfile profile, String reason, Date expires, String source) {
@@ -132,21 +132,21 @@ public class CraftProfileBanList implements ProfileBanList {
return null;
}
GameProfileBanEntry entry = new GameProfileBanEntry(profile, new Date(),
UserBanListEntry entry = new UserBanListEntry(profile, new Date(),
(source == null || source.isBlank()) ? null : source, expires,
(reason == null || reason.isBlank()) ? null : reason);
list.add(entry);
this.list.add(entry);
return new CraftProfileBanEntry(profile, entry, list);
return new CraftProfileBanEntry(profile, entry, this.list);
}
private void pardon(GameProfile profile) {
list.remove(profile);
this.list.remove(profile);
}
private boolean isBanned(GameProfile profile) {
return profile != null && list.isBanned(profile);
return profile != null && this.list.isBanned(profile);
}
static GameProfile getProfile(String target) {
@@ -157,7 +157,7 @@ public class CraftProfileBanList implements ProfileBanList {
} catch (IllegalArgumentException ignored) {
}
return (uuid != null) ? getProfileByUUID(uuid) : getProfileByName(target);
return (uuid != null) ? CraftProfileBanList.getProfileByUUID(uuid) : CraftProfileBanList.getProfileByName(target);
}
static GameProfile getProfileByUUID(UUID uuid) {

View File

@@ -1,11 +1,11 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.GeneratorAccessSeed;
import net.minecraft.world.level.World;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBeehive;
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 org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -33,7 +33,7 @@ public final class CapturedBlockState extends CraftBlockState {
// 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.
addBees();
this.addBees();
return result;
}
@@ -41,27 +41,27 @@ public final class CapturedBlockState extends CraftBlockState {
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
world.getHandle().setBlock(CraftLocation.toBlockPosition(getLocation()), getHandle(), getFlag());
this.world.getHandle().setBlock(CraftLocation.toBlockPosition(this.getLocation()), this.getHandle(), this.getFlag());
addBees();
this.addBees();
}
private void addBees() {
// SPIGOT-5537: Horrible hack to manually add bees given World.captureTreeGeneration does not support tiles
if (this.treeBlock && getType() == Material.BEE_NEST) {
GeneratorAccessSeed generatoraccessseed = this.world.getHandle();
BlockPosition blockposition1 = this.getPosition();
if (this.treeBlock && this.getType() == Material.BEE_NEST) {
WorldGenLevel generatoraccessseed = this.world.getHandle();
BlockPos blockposition1 = this.getPosition();
RandomSource random = generatoraccessseed.getRandom();
// Begin copied block from WorldGenFeatureTreeBeehive
TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition1);
BlockEntity tileentity = generatoraccessseed.getBlockEntity(blockposition1);
if (tileentity instanceof TileEntityBeehive) {
TileEntityBeehive tileentitybeehive = (TileEntityBeehive) tileentity;
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity tileentitybeehive = (BeehiveBlockEntity) tileentity;
int j = 2 + random.nextInt(2);
for (int k = 0; k < j; ++k) {
tileentitybeehive.storeBee(TileEntityBeehive.c.create(random.nextInt(599)));
tileentitybeehive.storeBee(BeehiveBlockEntity.Occupant.create(random.nextInt(599)));
}
}
// End copied block
@@ -78,11 +78,11 @@ public final class CapturedBlockState extends CraftBlockState {
return new CapturedBlockState(this, location);
}
public static CapturedBlockState getBlockState(World world, BlockPosition pos, int flag) {
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(World world, BlockPosition pos, int flag) {
public static CapturedBlockState getTreeBlockState(Level world, BlockPos pos, int flag) {
return new CapturedBlockState(world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), flag, true);
}

View File

@@ -3,10 +3,9 @@ package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.item.EnumColor;
import net.minecraft.world.level.block.BlockBannerAbstract;
import net.minecraft.world.level.block.AbstractBannerBlock;
import net.minecraft.world.level.block.entity.BannerBlockEntity;
import net.minecraft.world.level.block.entity.BannerPatternLayers;
import net.minecraft.world.level.block.entity.TileEntityBanner;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.World;
@@ -14,12 +13,12 @@ import org.bukkit.block.Banner;
import org.bukkit.block.banner.Pattern;
import org.bukkit.craftbukkit.block.banner.CraftPatternType;
public class CraftBanner extends CraftBlockEntityState<TileEntityBanner> implements Banner {
public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implements Banner {
private DyeColor base;
private List<Pattern> patterns;
public CraftBanner(World world, TileEntityBanner tileEntity) {
public CraftBanner(World world, BannerBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -30,16 +29,16 @@ public class CraftBanner extends CraftBlockEntityState<TileEntityBanner> impleme
}
@Override
public void load(TileEntityBanner banner) {
public void load(BannerBlockEntity banner) {
super.load(banner);
base = DyeColor.getByWoolData((byte) ((BlockBannerAbstract) this.data.getBlock()).getColor().getId());
patterns = new ArrayList<Pattern>();
this.base = DyeColor.getByWoolData((byte) ((AbstractBannerBlock) this.data.getBlock()).getColor().getId());
this.patterns = new ArrayList<Pattern>();
if (banner.getPatterns() != null) {
for (int i = 0; i < banner.getPatterns().layers().size(); i++) {
BannerPatternLayers.b p = banner.getPatterns().layers().get(i);
patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), CraftPatternType.minecraftHolderToBukkit(p.pattern())));
BannerPatternLayers.Layer p = banner.getPatterns().layers().get(i);
this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), CraftPatternType.minecraftHolderToBukkit(p.pattern())));
}
}
}
@@ -57,7 +56,7 @@ public class CraftBanner extends CraftBlockEntityState<TileEntityBanner> impleme
@Override
public List<Pattern> getPatterns() {
return new ArrayList<Pattern>(patterns);
return new ArrayList<Pattern>(this.patterns);
}
@Override
@@ -87,19 +86,19 @@ public class CraftBanner extends CraftBlockEntityState<TileEntityBanner> impleme
@Override
public int numberOfPatterns() {
return patterns.size();
return this.patterns.size();
}
@Override
public void applyTo(TileEntityBanner banner) {
public void applyTo(BannerBlockEntity banner) {
super.applyTo(banner);
banner.baseColor = EnumColor.byId(base.getWoolData());
banner.baseColor = net.minecraft.world.item.DyeColor.byId(this.base.getWoolData());
List<BannerPatternLayers.b> newPatterns = new ArrayList<>();
List<BannerPatternLayers.Layer> newPatterns = new ArrayList<>();
for (Pattern p : patterns) {
newPatterns.add(new net.minecraft.world.level.block.entity.BannerPatternLayers.b(CraftPatternType.bukkitToMinecraftHolder(p.getPattern()), EnumColor.byId(p.getColor().getWoolData())));
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));
}

View File

@@ -1,18 +1,18 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.sounds.SoundEffects;
import net.minecraft.world.level.block.BlockBarrel;
import net.minecraft.world.level.block.entity.TileEntityBarrel;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.BarrelBlock;
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Barrel;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
public class CraftBarrel extends CraftLootable<TileEntityBarrel> implements Barrel {
public class CraftBarrel extends CraftLootable<BarrelBlockEntity> implements Barrel {
public CraftBarrel(World world, TileEntityBarrel tileEntity) {
public CraftBarrel(World world, BarrelBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -36,32 +36,32 @@ public class CraftBarrel extends CraftLootable<TileEntityBarrel> implements Barr
@Override
public void open() {
requirePlaced();
if (!getTileEntity().openersCounter.opened) {
IBlockData blockData = getTileEntity().getBlockState();
boolean open = blockData.getValue(BlockBarrel.OPEN);
this.requirePlaced();
if (!this.getTileEntity().openersCounter.opened) {
BlockState blockData = this.getTileEntity().getBlockState();
boolean open = blockData.getValue(BarrelBlock.OPEN);
if (!open) {
getTileEntity().updateBlockState(blockData, true);
if (getWorldHandle() instanceof net.minecraft.world.level.World) {
getTileEntity().playSound(blockData, SoundEffects.BARREL_OPEN);
this.getTileEntity().updateBlockState(blockData, true);
if (this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
this.getTileEntity().playSound(blockData, SoundEvents.BARREL_OPEN);
}
}
}
getTileEntity().openersCounter.opened = true;
this.getTileEntity().openersCounter.opened = true;
}
@Override
public void close() {
requirePlaced();
if (getTileEntity().openersCounter.opened) {
IBlockData blockData = getTileEntity().getBlockState();
getTileEntity().updateBlockState(blockData, false);
if (getWorldHandle() instanceof net.minecraft.world.level.World) {
getTileEntity().playSound(blockData, SoundEffects.BARREL_CLOSE);
this.requirePlaced();
if (this.getTileEntity().openersCounter.opened) {
BlockState blockData = this.getTileEntity().getBlockState();
this.getTileEntity().updateBlockState(blockData, false);
if (this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
this.getTileEntity().playSound(blockData, SoundEvents.BARREL_CLOSE);
}
}
getTileEntity().openersCounter.opened = false;
this.getTileEntity().openersCounter.opened = false;
}
@Override

View File

@@ -4,15 +4,15 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import net.minecraft.advancements.critereon.CriterionConditionItem;
import net.minecraft.advancements.critereon.CriterionConditionValue;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.component.DataComponentPredicate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.world.ChestLock;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBeacon;
import net.minecraft.network.chat.Component;
import net.minecraft.world.LockCode;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Beacon;
@@ -24,9 +24,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> implements Beacon {
public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implements Beacon {
public CraftBeacon(World world, TileEntityBeacon tileEntity) {
public CraftBeacon(World world, BeaconBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -36,16 +36,16 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
@Override
public Collection<LivingEntity> getEntitiesInRange() {
ensureNoWorldGeneration();
this.ensureNoWorldGeneration();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof TileEntityBeacon) {
TileEntityBeacon beacon = (TileEntityBeacon) tileEntity;
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof BeaconBlockEntity) {
BeaconBlockEntity beacon = (BeaconBlockEntity) tileEntity;
Collection<EntityHuman> nms = TileEntityBeacon.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels);
Collection<Player> nms = BeaconBlockEntity.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels);
Collection<LivingEntity> bukkit = new ArrayList<LivingEntity>(nms.size());
for (EntityHuman human : nms) {
for (Player human : nms) {
bukkit.add(human.getBukkitEntity());
}
@@ -83,7 +83,7 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
@Override
public String getCustomName() {
TileEntityBeacon beacon = this.getSnapshot();
BeaconBlockEntity beacon = this.getSnapshot();
return beacon.name != null ? CraftChatMessage.fromComponent(beacon.name) : null;
}
@@ -94,12 +94,12 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
@Override
public boolean isLocked() {
return this.getSnapshot().lockKey != ChestLock.NO_LOCK;
return this.getSnapshot().lockKey != LockCode.NO_LOCK;
}
@Override
public String getLock() {
Optional<? extends IChatBaseComponent> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
Optional<? extends Component> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : "";
}
@@ -107,19 +107,19 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
@Override
public void setLock(String key) {
if (key == null) {
this.getSnapshot().lockKey = ChestLock.NO_LOCK;
this.getSnapshot().lockKey = LockCode.NO_LOCK;
} else {
DataComponentPredicate predicate = DataComponentPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build();
this.getSnapshot().lockKey = new ChestLock(new CriterionConditionItem(Optional.empty(), CriterionConditionValue.IntegerRange.ANY, predicate, Collections.emptyMap()));
this.getSnapshot().lockKey = new LockCode(new ItemPredicate(Optional.empty(), MinMaxBounds.Ints.ANY, predicate, Collections.emptyMap()));
}
}
@Override
public void setLockItem(ItemStack key) {
if (key == null) {
this.getSnapshot().lockKey = ChestLock.NO_LOCK;
this.getSnapshot().lockKey = LockCode.NO_LOCK;
} else {
this.getSnapshot().lockKey = new ChestLock(CraftItemStack.asCriterionConditionItem(key));
this.getSnapshot().lockKey = new LockCode(CraftItemStack.asCriterionConditionItem(key));
}
}

View File

@@ -1,14 +1,14 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityBed;
import net.minecraft.world.level.block.entity.BedBlockEntity;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Bed;
public class CraftBed extends CraftBlockEntityState<TileEntityBed> implements Bed {
public class CraftBed extends CraftBlockEntityState<BedBlockEntity> implements Bed {
public CraftBed(World world, TileEntityBed tileEntity) {
public CraftBed(World world, BedBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -18,7 +18,7 @@ public class CraftBed extends CraftBlockEntityState<TileEntityBed> implements Be
@Override
public DyeColor getColor() {
switch (getType()) {
switch (this.getType()) {
case BLACK_BED:
return DyeColor.BLACK;
case BLUE_BED:
@@ -52,7 +52,7 @@ public class CraftBed extends CraftBlockEntityState<TileEntityBed> implements Be
case YELLOW_BED:
return DyeColor.YELLOW;
default:
throw new IllegalArgumentException("Unknown DyeColor for " + getType());
throw new IllegalArgumentException("Unknown DyeColor for " + this.getType());
}
}

View File

@@ -3,10 +3,10 @@ package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.entity.TileEntityBeehive;
import net.minecraft.world.level.block.entity.TileEntityBeehive.ReleaseStatus;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity.BeeReleaseStatus;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Beehive;
@@ -14,9 +14,9 @@ import org.bukkit.craftbukkit.entity.CraftBee;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Bee;
public class CraftBeehive extends CraftBlockEntityState<TileEntityBeehive> implements Beehive {
public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> implements Beehive {
public CraftBeehive(World world, TileEntityBeehive tileEntity) {
public CraftBeehive(World world, BeehiveBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -26,52 +26,52 @@ public class CraftBeehive extends CraftBlockEntityState<TileEntityBeehive> imple
@Override
public Location getFlower() {
BlockPosition flower = getSnapshot().savedFlowerPos;
return (flower == null) ? null : CraftLocation.toBukkit(flower, getWorld());
BlockPos flower = this.getSnapshot().savedFlowerPos;
return (flower == null) ? null : CraftLocation.toBukkit(flower, this.getWorld());
}
@Override
public void setFlower(Location location) {
Preconditions.checkArgument(location == null || this.getWorld().equals(location.getWorld()), "Flower must be in same world");
getSnapshot().savedFlowerPos = (location == null) ? null : CraftLocation.toBlockPosition(location);
this.getSnapshot().savedFlowerPos = (location == null) ? null : CraftLocation.toBlockPosition(location);
}
@Override
public boolean isFull() {
return getSnapshot().isFull();
return this.getSnapshot().isFull();
}
@Override
public boolean isSedated() {
return isPlaced() && getTileEntity().isSedated();
return this.isPlaced() && this.getTileEntity().isSedated();
}
@Override
public int getEntityCount() {
return getSnapshot().getOccupantCount();
return this.getSnapshot().getOccupantCount();
}
@Override
public int getMaxEntities() {
return getSnapshot().maxBees;
return this.getSnapshot().maxBees;
}
@Override
public void setMaxEntities(int max) {
Preconditions.checkArgument(max > 0, "Max bees must be more than 0");
getSnapshot().maxBees = max;
this.getSnapshot().maxBees = max;
}
@Override
public List<Bee> releaseEntities() {
ensureNoWorldGeneration();
this.ensureNoWorldGeneration();
List<Bee> bees = new ArrayList<>();
if (isPlaced()) {
TileEntityBeehive beehive = ((TileEntityBeehive) this.getTileEntityFromWorld());
for (Entity bee : beehive.releaseBees(this.getHandle(), ReleaseStatus.BEE_RELEASED, true)) {
if (this.isPlaced()) {
BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getTileEntityFromWorld());
for (Entity bee : beehive.releaseBees(this.getHandle(), BeeReleaseStatus.BEE_RELEASED, true)) {
bees.add((Bee) bee.getBukkitEntity());
}
}
@@ -83,7 +83,7 @@ public class CraftBeehive extends CraftBlockEntityState<TileEntityBeehive> imple
public void addEntity(Bee entity) {
Preconditions.checkArgument(entity != null, "Entity must not be null");
getSnapshot().addOccupant(((CraftBee) entity).getHandle());
this.getSnapshot().addOccupant(((CraftBee) entity).getHandle());
}
@Override

View File

@@ -1,11 +1,11 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.core.EnumDirection;
import net.minecraft.world.level.block.BlockBell;
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.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBell;
import net.minecraft.world.level.block.entity.BellBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Bell;
@@ -13,9 +13,9 @@ import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Entity;
public class CraftBell extends CraftBlockEntityState<TileEntityBell> implements Bell {
public class CraftBell extends CraftBlockEntityState<BellBlockEntity> implements Bell {
public CraftBell(World world, TileEntityBell tileEntity) {
public CraftBell(World world, BellBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -27,50 +27,50 @@ public class CraftBell extends CraftBlockEntityState<TileEntityBell> implements
public boolean ring(Entity entity, BlockFace direction) {
Preconditions.checkArgument(direction == null || direction.isCartesian(), "direction must be cartesian, given %s", direction);
TileEntity tileEntity = getTileEntityFromWorld();
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity == null) {
return false;
}
net.minecraft.world.entity.Entity nmsEntity = (entity != null) ? ((CraftEntity) entity).getHandle() : null;
EnumDirection enumDirection = CraftBlock.blockFaceToNotch(direction);
Direction enumDirection = CraftBlock.blockFaceToNotch(direction);
return ((BlockBell) Blocks.BELL).attemptToRing(nmsEntity, world.getHandle(), getPosition(), enumDirection);
return ((BellBlock) Blocks.BELL).attemptToRing(nmsEntity, this.world.getHandle(), this.getPosition(), enumDirection);
}
@Override
public boolean ring(Entity entity) {
return ring(entity, null);
return this.ring(entity, null);
}
@Override
public boolean ring(BlockFace direction) {
return ring(null, direction);
return this.ring(null, direction);
}
@Override
public boolean ring() {
return ring(null, null);
return this.ring(null, null);
}
@Override
public boolean isShaking() {
return getSnapshot().shaking;
return this.getSnapshot().shaking;
}
@Override
public int getShakingTicks() {
return getSnapshot().ticks;
return this.getSnapshot().ticks;
}
@Override
public boolean isResonating() {
return getSnapshot().resonating;
return this.getSnapshot().resonating;
}
@Override
public int getResonatingTicks() {
return isResonating() ? getSnapshot().ticks : 0;
return this.isResonating() ? this.getSnapshot().ticks : 0;
}
@Override

View File

@@ -2,9 +2,7 @@ package org.bukkit.craftbukkit.block;
import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.biome.BiomeBase;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.block.Biome;
@@ -12,19 +10,19 @@ import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftBiome implements Biome, Handleable<BiomeBase> {
public class CraftBiome implements Biome, Handleable<net.minecraft.world.level.biome.Biome> {
private static int count = 0;
public static Biome minecraftToBukkit(BiomeBase minecraft) {
public static Biome minecraftToBukkit(net.minecraft.world.level.biome.Biome minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.BIOME, Registry.BIOME);
}
public static Biome minecraftHolderToBukkit(Holder<BiomeBase> minecraft) {
return minecraftToBukkit(minecraft.value());
public static Biome minecraftHolderToBukkit(Holder<net.minecraft.world.level.biome.Biome> minecraft) {
return CraftBiome.minecraftToBukkit(minecraft.value());
}
public static BiomeBase bukkitToMinecraft(Biome bukkit) {
public static net.minecraft.world.level.biome.Biome bukkitToMinecraft(Biome bukkit) {
if (bukkit == Biome.CUSTOM) {
return null;
}
@@ -32,14 +30,14 @@ public class CraftBiome implements Biome, Handleable<BiomeBase> {
return CraftRegistry.bukkitToMinecraft(bukkit);
}
public static Holder<BiomeBase> bukkitToMinecraftHolder(Biome bukkit) {
public static Holder<net.minecraft.world.level.biome.Biome> bukkitToMinecraftHolder(Biome bukkit) {
if (bukkit == Biome.CUSTOM) {
return null;
}
IRegistry<BiomeBase> registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME);
net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<BiomeBase> holder) {
if (registry.wrapAsHolder(CraftBiome.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.level.biome.Biome> holder) {
return holder;
}
@@ -48,11 +46,11 @@ public class CraftBiome implements Biome, Handleable<BiomeBase> {
}
private final NamespacedKey key;
private final BiomeBase biomeBase;
private final net.minecraft.world.level.biome.Biome biomeBase;
private final String name;
private final int ordinal;
public CraftBiome(NamespacedKey key, BiomeBase biomeBase) {
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,
@@ -64,40 +62,40 @@ public class CraftBiome implements Biome, Handleable<BiomeBase> {
} else {
this.name = key.toString();
}
this.ordinal = count++;
this.ordinal = CraftBiome.count++;
}
@Override
public BiomeBase getHandle() {
return biomeBase;
public net.minecraft.world.level.biome.Biome getHandle() {
return this.biomeBase;
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
public int compareTo(@NotNull Biome biome) {
return ordinal - biome.ordinal();
return this.ordinal - biome.ordinal();
}
@NotNull
@Override
public String name() {
return name;
return this.name;
}
@Override
public int ordinal() {
return ordinal;
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return name();
return this.name();
}
@Override
@@ -110,11 +108,11 @@ public class CraftBiome implements Biome, Handleable<BiomeBase> {
return false;
}
return getKey().equals(otherBiome.getKey());
return this.getKey().equals(otherBiome.getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
}

View File

@@ -1,13 +1,13 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityBlastFurnace;
import net.minecraft.world.level.block.entity.BlastFurnaceBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlastFurnace;
public class CraftBlastFurnace extends CraftFurnace<TileEntityBlastFurnace> implements BlastFurnace {
public class CraftBlastFurnace extends CraftFurnace<BlastFurnaceBlockEntity> implements BlastFurnace {
public CraftBlastFurnace(World world, TileEntityBlastFurnace tileEntity) {
public CraftBlastFurnace(World world, BlastFurnaceBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -6,27 +6,26 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.EnumDirection;
import net.minecraft.server.level.WorldServer;
import net.minecraft.world.EnumHand;
import net.minecraft.world.EnumInteractionResult;
import net.minecraft.world.item.ItemBoneMeal;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BoneMealItem;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.ItemActionContext;
import net.minecraft.world.level.EnumSkyBlock;
import net.minecraft.world.level.GeneratorAccess;
import net.minecraft.world.level.RayTrace;
import net.minecraft.world.level.block.BlockRedstoneWire;
import net.minecraft.world.level.block.BlockSapling;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.phys.AxisAlignedBB;
import net.minecraft.world.phys.MovingObjectPosition;
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FluidCollisionMode;
@@ -63,51 +62,51 @@ import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;
public class CraftBlock implements Block {
private final net.minecraft.world.level.GeneratorAccess world;
private final BlockPosition position;
private final net.minecraft.world.level.LevelAccessor world;
private final BlockPos position;
public CraftBlock(GeneratorAccess world, BlockPosition position) {
public CraftBlock(LevelAccessor world, BlockPos position) {
this.world = world;
this.position = position.immutable();
}
public static CraftBlock at(GeneratorAccess world, BlockPosition position) {
public static CraftBlock at(LevelAccessor world, BlockPos position) {
return new CraftBlock(world, position);
}
public net.minecraft.world.level.block.state.IBlockData getNMS() {
return world.getBlockState(position);
public net.minecraft.world.level.block.state.BlockState getNMS() {
return this.world.getBlockState(this.position);
}
public BlockPosition getPosition() {
return position;
public BlockPos getPosition() {
return this.position;
}
public GeneratorAccess getHandle() {
return world;
public LevelAccessor getHandle() {
return this.world;
}
@Override
public World getWorld() {
return world.getMinecraftWorld().getWorld();
return this.world.getMinecraftWorld().getWorld();
}
public CraftWorld getCraftWorld() {
return (CraftWorld) getWorld();
return (CraftWorld) this.getWorld();
}
@Override
public Location getLocation() {
return CraftLocation.toBukkit(position, getWorld());
return CraftLocation.toBukkit(this.position, this.getWorld());
}
@Override
public Location getLocation(Location loc) {
if (loc != null) {
loc.setWorld(getWorld());
loc.setX(position.getX());
loc.setY(position.getY());
loc.setZ(position.getZ());
loc.setWorld(this.getWorld());
loc.setX(this.position.getX());
loc.setY(this.position.getY());
loc.setZ(this.position.getZ());
loc.setYaw(0);
loc.setPitch(0);
}
@@ -116,88 +115,88 @@ public class CraftBlock implements Block {
}
public BlockVector getVector() {
return new BlockVector(getX(), getY(), getZ());
return new BlockVector(this.getX(), this.getY(), this.getZ());
}
@Override
public int getX() {
return position.getX();
return this.position.getX();
}
@Override
public int getY() {
return position.getY();
return this.position.getY();
}
@Override
public int getZ() {
return position.getZ();
return this.position.getZ();
}
@Override
public Chunk getChunk() {
return getWorld().getChunkAt(this);
return this.getWorld().getChunkAt(this);
}
public void setData(final byte data) {
setData(data, 3);
this.setData(data, 3);
}
public void setData(final byte data, boolean applyPhysics) {
if (applyPhysics) {
setData(data, 3);
this.setData(data, 3);
} else {
setData(data, 2);
this.setData(data, 2);
}
}
private void setData(final byte data, int flag) {
world.setBlock(position, CraftMagicNumbers.getBlock(getType(), data), flag);
this.world.setBlock(this.position, CraftMagicNumbers.getBlock(this.getType(), data), flag);
}
@Override
public byte getData() {
IBlockData blockData = world.getBlockState(position);
net.minecraft.world.level.block.state.BlockState blockData = this.world.getBlockState(this.position);
return CraftMagicNumbers.toLegacyData(blockData);
}
@Override
public BlockData getBlockData() {
return CraftBlockData.fromData(getNMS());
return CraftBlockData.fromData(this.getNMS());
}
@Override
public void setType(final Material type) {
setType(type, true);
this.setType(type, true);
}
@Override
public void setType(Material type, boolean applyPhysics) {
Preconditions.checkArgument(type != null, "Material cannot be null");
setBlockData(type.createBlockData(), applyPhysics);
this.setBlockData(type.createBlockData(), applyPhysics);
}
@Override
public void setBlockData(BlockData data) {
setBlockData(data, true);
this.setBlockData(data, true);
}
@Override
public void setBlockData(BlockData data, boolean applyPhysics) {
Preconditions.checkArgument(data != null, "BlockData cannot be null");
setTypeAndData(((CraftBlockData) data).getState(), applyPhysics);
this.setTypeAndData(((CraftBlockData) data).getState(), applyPhysics);
}
boolean setTypeAndData(final IBlockData blockData, final boolean applyPhysics) {
return setTypeAndData(world, position, getNMS(), blockData, 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);
}
public static boolean setTypeAndData(GeneratorAccess world, BlockPosition position, IBlockData old, IBlockData blockData, boolean 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
// SPIGOT-4612: faster - just clear tile
if (world instanceof net.minecraft.world.level.World) {
((net.minecraft.world.level.World) world).removeBlockEntity(position);
if (world instanceof net.minecraft.world.level.Level) {
((net.minecraft.world.level.Level) world).removeBlockEntity(position);
} else {
world.setBlock(position, Blocks.AIR.defaultBlockState(), 0);
}
@@ -207,7 +206,7 @@ public class CraftBlock implements Block {
return world.setBlock(position, blockData, 3);
} else {
boolean success = world.setBlock(position, blockData, 2 | 16 | 1024); // NOTIFY | NO_OBSERVER | NO_PLACE (custom)
if (success && world instanceof net.minecraft.world.level.World) {
if (success && world instanceof net.minecraft.world.level.Level) {
world.getMinecraftWorld().sendBlockUpdated(
position,
old,
@@ -221,45 +220,45 @@ public class CraftBlock implements Block {
@Override
public Material getType() {
return CraftBlockType.minecraftToBukkit(world.getBlockState(position).getBlock());
return CraftBlockType.minecraftToBukkit(this.world.getBlockState(this.position).getBlock());
}
@Override
public byte getLightLevel() {
return (byte) world.getMinecraftWorld().getMaxLocalRawBrightness(position);
return (byte) this.world.getMinecraftWorld().getMaxLocalRawBrightness(this.position);
}
@Override
public byte getLightFromSky() {
return (byte) world.getBrightness(EnumSkyBlock.SKY, position);
return (byte) this.world.getBrightness(LightLayer.SKY, this.position);
}
@Override
public byte getLightFromBlocks() {
return (byte) world.getBrightness(EnumSkyBlock.BLOCK, position);
return (byte) this.world.getBrightness(LightLayer.BLOCK, this.position);
}
public Block getFace(final BlockFace face) {
return getRelative(face, 1);
return this.getRelative(face, 1);
}
public Block getFace(final BlockFace face, final int distance) {
return getRelative(face, distance);
return this.getRelative(face, distance);
}
@Override
public Block getRelative(final int modX, final int modY, final int modZ) {
return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ);
return this.getWorld().getBlockAt(this.getX() + modX, this.getY() + modY, this.getZ() + modZ);
}
@Override
public Block getRelative(BlockFace face) {
return getRelative(face, 1);
return this.getRelative(face, 1);
}
@Override
public Block getRelative(BlockFace face, int distance) {
return getRelative(face.getModX() * distance, face.getModY() * distance, face.getModZ() * distance);
return this.getRelative(face.getModX() * distance, face.getModY() * distance, face.getModZ() * distance);
}
@Override
@@ -277,10 +276,10 @@ public class CraftBlock implements Block {
@Override
public String toString() {
return "CraftBlock{pos=" + position + ",type=" + getType() + ",data=" + getNMS() + ",fluid=" + world.getFluidState(position) + '}';
return "CraftBlock{pos=" + this.position + ",type=" + this.getType() + ",data=" + this.getNMS() + ",fluid=" + this.world.getFluidState(this.position) + '}';
}
public static BlockFace notchToBlockFace(EnumDirection notch) {
public static BlockFace notchToBlockFace(Direction notch) {
if (notch == null) {
return BlockFace.SELF;
}
@@ -302,23 +301,23 @@ public class CraftBlock implements Block {
}
}
public static EnumDirection blockFaceToNotch(BlockFace face) {
public static Direction blockFaceToNotch(BlockFace face) {
if (face == null) {
return null;
}
switch (face) {
case DOWN:
return EnumDirection.DOWN;
return Direction.DOWN;
case UP:
return EnumDirection.UP;
return Direction.UP;
case NORTH:
return EnumDirection.NORTH;
return Direction.NORTH;
case SOUTH:
return EnumDirection.SOUTH;
return Direction.SOUTH;
case WEST:
return EnumDirection.WEST;
return Direction.WEST;
case EAST:
return EnumDirection.EAST;
return Direction.EAST;
default:
return null;
}
@@ -331,32 +330,32 @@ public class CraftBlock implements Block {
@Override
public Biome getBiome() {
return getWorld().getBiome(getX(), getY(), getZ());
return this.getWorld().getBiome(this.getX(), this.getY(), this.getZ());
}
@Override
public void setBiome(Biome bio) {
getWorld().setBiome(getX(), getY(), getZ(), bio);
this.getWorld().setBiome(this.getX(), this.getY(), this.getZ(), bio);
}
@Override
public double getTemperature() {
return world.getBiome(position).value().getTemperature(position, world.getSeaLevel());
return this.world.getBiome(this.position).value().getTemperature(this.position, this.world.getSeaLevel());
}
@Override
public double getHumidity() {
return getWorld().getHumidity(getX(), getY(), getZ());
return this.getWorld().getHumidity(this.getX(), this.getY(), this.getZ());
}
@Override
public boolean isBlockPowered() {
return world.getMinecraftWorld().getDirectSignalTo(position) > 0;
return this.world.getMinecraftWorld().getDirectSignalTo(this.position) > 0;
}
@Override
public boolean isBlockIndirectlyPowered() {
return world.getMinecraftWorld().hasNeighborSignal(position);
return this.world.getMinecraftWorld().hasNeighborSignal(this.position);
}
@Override
@@ -378,14 +377,14 @@ public class CraftBlock implements Block {
@Override
public boolean isBlockFacePowered(BlockFace face) {
return world.getMinecraftWorld().hasSignal(position, blockFaceToNotch(face));
return this.world.getMinecraftWorld().hasSignal(this.position, CraftBlock.blockFaceToNotch(face));
}
@Override
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
int power = world.getMinecraftWorld().getSignal(position, blockFaceToNotch(face));
int power = this.world.getMinecraftWorld().getSignal(this.position, CraftBlock.blockFaceToNotch(face));
Block relative = getRelative(face);
Block relative = this.getRelative(face);
if (relative.getType() == Material.REDSTONE_WIRE) {
return Math.max(power, relative.getData()) > 0;
}
@@ -396,24 +395,24 @@ public class CraftBlock implements Block {
@Override
public int getBlockPower(BlockFace face) {
int power = 0;
net.minecraft.world.level.World world = this.world.getMinecraftWorld();
int x = getX();
int y = getY();
int z = getZ();
if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.hasSignal(new BlockPosition(x, y - 1, z), EnumDirection.DOWN)) power = getPower(power, world.getBlockState(new BlockPosition(x, y - 1, z)));
if ((face == BlockFace.UP || face == BlockFace.SELF) && world.hasSignal(new BlockPosition(x, y + 1, z), EnumDirection.UP)) power = getPower(power, world.getBlockState(new BlockPosition(x, y + 1, z)));
if ((face == BlockFace.EAST || face == BlockFace.SELF) && world.hasSignal(new BlockPosition(x + 1, y, z), EnumDirection.EAST)) power = getPower(power, world.getBlockState(new BlockPosition(x + 1, y, z)));
if ((face == BlockFace.WEST || face == BlockFace.SELF) && world.hasSignal(new BlockPosition(x - 1, y, z), EnumDirection.WEST)) power = getPower(power, world.getBlockState(new BlockPosition(x - 1, y, z)));
if ((face == BlockFace.NORTH || face == BlockFace.SELF) && world.hasSignal(new BlockPosition(x, y, z - 1), EnumDirection.NORTH)) power = getPower(power, world.getBlockState(new BlockPosition(x, y, z - 1)));
if ((face == BlockFace.SOUTH || face == BlockFace.SELF) && world.hasSignal(new BlockPosition(x, y, z + 1), EnumDirection.SOUTH)) power = getPower(power, world.getBlockState(new BlockPosition(x, y, z + 1)));
return power > 0 ? power : (face == BlockFace.SELF ? isBlockIndirectlyPowered() : isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
net.minecraft.world.level.Level world = this.world.getMinecraftWorld();
int x = this.getX();
int y = this.getY();
int z = this.getZ();
if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.hasSignal(new BlockPos(x, y - 1, z), Direction.DOWN)) power = CraftBlock.getPower(power, world.getBlockState(new BlockPos(x, y - 1, z)));
if ((face == BlockFace.UP || face == BlockFace.SELF) && world.hasSignal(new BlockPos(x, y + 1, z), Direction.UP)) power = CraftBlock.getPower(power, world.getBlockState(new BlockPos(x, y + 1, z)));
if ((face == BlockFace.EAST || face == BlockFace.SELF) && world.hasSignal(new BlockPos(x + 1, y, z), Direction.EAST)) power = CraftBlock.getPower(power, world.getBlockState(new BlockPos(x + 1, y, z)));
if ((face == BlockFace.WEST || face == BlockFace.SELF) && world.hasSignal(new BlockPos(x - 1, y, z), Direction.WEST)) power = CraftBlock.getPower(power, world.getBlockState(new BlockPos(x - 1, y, z)));
if ((face == BlockFace.NORTH || face == BlockFace.SELF) && world.hasSignal(new BlockPos(x, y, z - 1), Direction.NORTH)) power = CraftBlock.getPower(power, world.getBlockState(new BlockPos(x, y, z - 1)));
if ((face == BlockFace.SOUTH || face == BlockFace.SELF) && world.hasSignal(new BlockPos(x, y, z + 1), Direction.SOUTH)) power = CraftBlock.getPower(power, world.getBlockState(new BlockPos(x, y, z + 1)));
return power > 0 ? power : (face == BlockFace.SELF ? this.isBlockIndirectlyPowered() : this.isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
}
private static int getPower(int i, IBlockData iblockdata) {
private static int getPower(int i, net.minecraft.world.level.block.state.BlockState iblockdata) {
if (!iblockdata.is(Blocks.REDSTONE_WIRE)) {
return i;
} else {
int j = iblockdata.getValue(BlockRedstoneWire.POWER);
int j = iblockdata.getValue(RedStoneWireBlock.POWER);
return j > i ? j : i;
}
@@ -421,72 +420,72 @@ public class CraftBlock implements Block {
@Override
public int getBlockPower() {
return getBlockPower(BlockFace.SELF);
return this.getBlockPower(BlockFace.SELF);
}
@Override
public boolean isEmpty() {
return getNMS().isAir();
return this.getNMS().isAir();
}
@Override
public boolean isLiquid() {
return getNMS().liquid();
return this.getNMS().liquid();
}
@Override
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(getNMS().getPistonPushReaction().ordinal());
return PistonMoveReaction.getById(this.getNMS().getPistonPushReaction().ordinal());
}
@Override
public boolean breakNaturally() {
return breakNaturally(null);
return this.breakNaturally(null);
}
@Override
public boolean breakNaturally(ItemStack item) {
// Order matters here, need to drop before setting to air so skulls can get their data
net.minecraft.world.level.block.state.IBlockData iblockdata = this.getNMS();
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
net.minecraft.world.level.block.Block block = iblockdata.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, world.getMinecraftWorld(), position, world.getBlockEntity(position), null, nmsItem);
net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem);
result = true;
}
// SPIGOT-6778: Directly call setBlock instead of setTypeAndData, so that the tile entiy is not removed and custom remove logic is run.
return world.setBlock(position, Blocks.AIR.defaultBlockState(), 3) && result;
return this.world.setBlock(this.position, Blocks.AIR.defaultBlockState(), 3) && result;
}
@Override
public boolean applyBoneMeal(BlockFace face) {
EnumDirection direction = blockFaceToNotch(face);
Direction direction = CraftBlock.blockFaceToNotch(face);
BlockFertilizeEvent event = null;
WorldServer world = getCraftWorld().getHandle();
ItemActionContext context = new ItemActionContext(world, null, EnumHand.MAIN_HAND, Items.BONE_MEAL.getDefaultInstance(), new MovingObjectPositionBlock(Vec3D.ZERO, direction, getPosition(), false));
ServerLevel world = this.getCraftWorld().getHandle();
UseOnContext context = new UseOnContext(world, null, InteractionHand.MAIN_HAND, Items.BONE_MEAL.getDefaultInstance(), new BlockHitResult(Vec3.ZERO, direction, this.getPosition(), false));
// SPIGOT-6895: Call StructureGrowEvent and BlockFertilizeEvent
world.captureTreeGeneration = true;
EnumInteractionResult result = ItemBoneMeal.applyBonemeal(context);
InteractionResult result = BoneMealItem.applyBonemeal(context);
world.captureTreeGeneration = false;
if (world.capturedBlockStates.size() > 0) {
TreeType treeType = BlockSapling.treeType;
BlockSapling.treeType = null;
TreeType treeType = SaplingBlock.treeType;
SaplingBlock.treeType = null;
List<BlockState> blocks = new ArrayList<>(world.capturedBlockStates.values());
world.capturedBlockStates.clear();
StructureGrowEvent structureEvent = null;
if (treeType != null) {
structureEvent = new StructureGrowEvent(getLocation(), treeType, true, null, blocks);
structureEvent = new StructureGrowEvent(this.getLocation(), treeType, true, null, blocks);
Bukkit.getPluginManager().callEvent(structureEvent);
}
event = new BlockFertilizeEvent(CraftBlock.at(world, getPosition()), null, blocks);
event = new BlockFertilizeEvent(CraftBlock.at(world, this.getPosition()), null, blocks);
event.setCancelled(structureEvent != null && structureEvent.isCancelled());
Bukkit.getPluginManager().callEvent(event);
@@ -497,27 +496,27 @@ public class CraftBlock implements Block {
}
}
return result == EnumInteractionResult.SUCCESS && (event == null || !event.isCancelled());
return result == InteractionResult.SUCCESS && (event == null || !event.isCancelled());
}
@Override
public Collection<ItemStack> getDrops() {
return getDrops(null);
return this.getDrops(null);
}
@Override
public Collection<ItemStack> getDrops(ItemStack item) {
return getDrops(item, null);
return this.getDrops(item, null);
}
@Override
public Collection<ItemStack> getDrops(ItemStack item, Entity entity) {
IBlockData iblockdata = getNMS();
net.minecraft.world.level.block.state.BlockState iblockdata = 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, (WorldServer) world.getMinecraftWorld(), position, world.getBlockEntity(position), entity == null ? null : ((CraftEntity) entity).getHandle(), 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)
.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList());
} else {
return Collections.emptyList();
@@ -526,7 +525,7 @@ public class CraftBlock implements Block {
@Override
public boolean isPreferredTool(ItemStack item) {
IBlockData iblockdata = getNMS();
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(item);
return CraftBlockData.isPreferredTool(iblockdata, nms);
}
@@ -534,32 +533,32 @@ public class CraftBlock implements Block {
@Override
public float getBreakSpeed(Player player) {
Preconditions.checkArgument(player != null, "player cannot be null");
return getNMS().getDestroyProgress(((CraftPlayer) player).getHandle(), world, position);
return this.getNMS().getDestroyProgress(((CraftPlayer) player).getHandle(), this.world, this.position);
}
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
this.getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
return getCraftWorld().getBlockMetadata().getMetadata(this, metadataKey);
return this.getCraftWorld().getBlockMetadata().getMetadata(this, metadataKey);
}
@Override
public boolean hasMetadata(String metadataKey) {
return getCraftWorld().getBlockMetadata().hasMetadata(this, metadataKey);
return this.getCraftWorld().getBlockMetadata().hasMetadata(this, metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
getCraftWorld().getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin);
this.getCraftWorld().getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin);
}
@Override
public boolean isPassable() {
return this.getNMS().getCollisionShape(world, position).isEmpty();
return this.getNMS().getCollisionShape(this.world, this.position).isEmpty();
}
@Override
@@ -578,42 +577,42 @@ public class CraftBlock implements Block {
}
Vector dir = direction.clone().normalize().multiply(maxDistance);
Vec3D startPos = CraftLocation.toVec3D(start);
Vec3D endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
Vec3 startPos = CraftLocation.toVec3D(start);
Vec3 endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
MovingObjectPosition nmsHitResult = world.clip(new RayTrace(startPos, endPos, RayTrace.BlockCollisionOption.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), VoxelShapeCollision.empty()), position);
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);
}
@Override
public BoundingBox getBoundingBox() {
VoxelShape shape = getNMS().getShape(world, position);
VoxelShape shape = this.getNMS().getShape(this.world, this.position);
if (shape.isEmpty()) {
return new BoundingBox(); // Return an empty bounding box if the block has no dimension
}
AxisAlignedBB aabb = shape.bounds();
return new BoundingBox(getX() + aabb.minX, getY() + aabb.minY, getZ() + aabb.minZ, getX() + aabb.maxX, getY() + aabb.maxY, getZ() + aabb.maxZ);
AABB aabb = shape.bounds();
return new BoundingBox(this.getX() + aabb.minX, this.getY() + aabb.minY, this.getZ() + aabb.minZ, this.getX() + aabb.maxX, this.getY() + aabb.maxY, this.getZ() + aabb.maxZ);
}
@Override
public org.bukkit.util.VoxelShape getCollisionShape() {
VoxelShape shape = getNMS().getCollisionShape(world, position);
VoxelShape shape = this.getNMS().getCollisionShape(this.world, this.position);
return new CraftVoxelShape(shape);
}
@Override
public boolean canPlace(BlockData data) {
Preconditions.checkArgument(data != null, "BlockData cannot be null");
net.minecraft.world.level.block.state.IBlockData iblockdata = ((CraftBlockData) data).getState();
net.minecraft.world.level.World world = this.world.getMinecraftWorld();
net.minecraft.world.level.block.state.BlockState iblockdata = ((CraftBlockData) data).getState();
net.minecraft.world.level.Level world = this.world.getMinecraftWorld();
return iblockdata.canSurvive(world, this.position);
}
@Override
public String getTranslationKey() {
return getNMS().getBlock().getDescriptionId();
return this.getNMS().getBlock().getDescriptionId();
}
}

View File

@@ -1,17 +1,17 @@
package org.bukkit.craftbukkit.block;
import java.util.Set;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.PacketListenerPlayOut;
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.GeneratorAccess;
import net.minecraft.world.level.block.entity.TileEntity;
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;
@@ -20,7 +20,7 @@ import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState implements TileState {
public class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockState implements TileState {
private final T tileEntity;
private final T snapshot;
@@ -32,22 +32,22 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
// copy tile entity data:
this.snapshot = this.createSnapshot(tileEntity);
this.load(snapshot);
this.load(this.snapshot);
}
protected CraftBlockEntityState(CraftBlockEntityState<T> state, Location location) {
super(state, location);
this.tileEntity = createSnapshot(state.snapshot);
this.snapshot = tileEntity;
loadData(state.getSnapshotNBT());
this.tileEntity = this.createSnapshot(state.snapshot);
this.snapshot = this.tileEntity;
this.loadData(state.getSnapshotNBT());
}
public void refreshSnapshot() {
this.load(tileEntity);
this.load(this.tileEntity);
}
private IRegistryCustom getRegistryAccess() {
GeneratorAccess worldHandle = getWorldHandle();
private RegistryAccess getRegistryAccess() {
LevelAccessor worldHandle = this.getWorldHandle();
return (worldHandle != null) ? worldHandle.registryAccess() : MinecraftServer.getDefaultRegistryAccess();
}
@@ -56,96 +56,96 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
return null;
}
NBTTagCompound nbtTagCompound = tileEntity.saveWithFullMetadata(getRegistryAccess());
T snapshot = (T) TileEntity.loadStatic(getPosition(), getHandle(), nbtTagCompound, getRegistryAccess());
CompoundTag nbtTagCompound = tileEntity.saveWithFullMetadata(this.getRegistryAccess());
T snapshot = (T) BlockEntity.loadStatic(this.getPosition(), this.getHandle(), nbtTagCompound, this.getRegistryAccess());
return snapshot;
}
public Set<DataComponentType<?>> applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) {
Set<DataComponentType<?>> result = snapshot.applyComponentsSet(datacomponentmap, datacomponentpatch);
load(snapshot);
Set<DataComponentType<?>> result = this.snapshot.applyComponentsSet(datacomponentmap, datacomponentpatch);
this.load(this.snapshot);
return result;
}
public DataComponentMap collectComponents() {
return snapshot.collectComponents();
return this.snapshot.collectComponents();
}
// Loads the specified data into the snapshot TileEntity.
public void loadData(NBTTagCompound nbtTagCompound) {
snapshot.loadWithComponents(nbtTagCompound, getRegistryAccess());
load(snapshot);
public void loadData(CompoundTag nbtTagCompound) {
this.snapshot.loadWithComponents(nbtTagCompound, this.getRegistryAccess());
this.load(this.snapshot);
}
// copies the TileEntity-specific data, retains the position
private void copyData(T from, T to) {
NBTTagCompound nbtTagCompound = from.saveWithFullMetadata(getRegistryAccess());
to.loadWithComponents(nbtTagCompound, getRegistryAccess());
CompoundTag nbtTagCompound = from.saveWithFullMetadata(this.getRegistryAccess());
to.loadWithComponents(nbtTagCompound, this.getRegistryAccess());
}
// gets the wrapped TileEntity
protected T getTileEntity() {
return tileEntity;
public T getTileEntity() {
return this.tileEntity;
}
// gets the cloned TileEntity which is used to store the captured data
protected T getSnapshot() {
return snapshot;
return this.snapshot;
}
// gets the current TileEntity from the world at this position
protected TileEntity getTileEntityFromWorld() {
requirePlaced();
protected BlockEntity getTileEntityFromWorld() {
this.requirePlaced();
return getWorldHandle().getBlockEntity(this.getPosition());
return this.getWorldHandle().getBlockEntity(this.getPosition());
}
// gets the NBT data of the TileEntity represented by this block state
public NBTTagCompound getSnapshotNBT() {
public CompoundTag getSnapshotNBT() {
// update snapshot
applyTo(snapshot);
this.applyTo(this.snapshot);
return snapshot.saveWithFullMetadata(getRegistryAccess());
return this.snapshot.saveWithFullMetadata(this.getRegistryAccess());
}
public NBTTagCompound getItemNBT() {
public CompoundTag getItemNBT() {
// update snapshot
applyTo(snapshot);
this.applyTo(this.snapshot);
// See TileEntity#saveToItem
NBTTagCompound nbt = snapshot.saveCustomOnly(getRegistryAccess());
snapshot.removeComponentsFromTag(nbt);
CompoundTag nbt = this.snapshot.saveCustomOnly(this.getRegistryAccess());
this.snapshot.removeComponentsFromTag(nbt);
return nbt;
}
public void addEntityType(NBTTagCompound nbt) {
TileEntity.addEntityType(nbt, snapshot.getType());
public void addEntityType(CompoundTag nbt) {
BlockEntity.addEntityType(nbt, this.snapshot.getType());
}
// gets the packet data of the TileEntity represented by this block state
public NBTTagCompound getUpdateNBT() {
public CompoundTag getUpdateNBT() {
// update snapshot
applyTo(snapshot);
this.applyTo(this.snapshot);
return snapshot.getUpdateTag(getRegistryAccess());
return this.snapshot.getUpdateTag(this.getRegistryAccess());
}
// copies the data of the given tile entity to this block state
protected void load(T tileEntity) {
if (tileEntity != null && tileEntity != snapshot) {
copyData(tileEntity, snapshot);
if (tileEntity != null && tileEntity != this.snapshot) {
this.copyData(tileEntity, this.snapshot);
}
}
// applies the TileEntity data of this block state to the given TileEntity
protected void applyTo(T tileEntity) {
if (tileEntity != null && tileEntity != snapshot) {
copyData(snapshot, tileEntity);
if (tileEntity != null && tileEntity != this.snapshot) {
this.copyData(this.snapshot, tileEntity);
}
}
protected boolean isApplicable(TileEntity tileEntity) {
protected boolean isApplicable(BlockEntity tileEntity) {
return tileEntity != null && this.tileEntity.getClass() == tileEntity.getClass();
}
@@ -154,10 +154,10 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced()) {
TileEntity tile = getTileEntityFromWorld();
BlockEntity tile = this.getTileEntityFromWorld();
if (isApplicable(tile)) {
applyTo((T) tile);
if (this.isApplicable(tile)) {
this.applyTo((T) tile);
tile.setChanged();
}
}
@@ -171,8 +171,8 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
}
@Nullable
public Packet<PacketListenerPlayOut> getUpdatePacket(@NotNull Location location) {
return new PacketPlayOutTileEntityData(CraftLocation.toBlockPosition(location), snapshot.getType(), getUpdateNBT());
public Packet<ClientGamePacketListener> getUpdatePacket(@NotNull Location location) {
return new ClientboundBlockEntityDataPacket(CraftLocation.toBlockPosition(location), this.snapshot.getType(), this.getUpdateNBT());
}
@Override

View File

@@ -4,9 +4,8 @@ import com.google.common.base.Preconditions;
import java.lang.ref.WeakReference;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPosition;
import net.minecraft.world.level.GeneratorAccess;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -26,16 +25,16 @@ import org.bukkit.plugin.Plugin;
public class CraftBlockState implements BlockState {
protected final CraftWorld world;
private final BlockPosition position;
protected IBlockData data;
private final BlockPos position;
protected net.minecraft.world.level.block.state.BlockState data;
protected int flag;
private WeakReference<GeneratorAccess> weakWorld;
private WeakReference<LevelAccessor> weakWorld;
protected CraftBlockState(final Block block) {
this(block.getWorld(), ((CraftBlock) block).getPosition(), ((CraftBlock) block).getNMS());
this.flag = 3;
setWorldHandle(((CraftBlock) block).getHandle());
this.setWorldHandle(((CraftBlock) block).getHandle());
}
protected CraftBlockState(final Block block, int flag) {
@@ -44,10 +43,10 @@ public class CraftBlockState implements BlockState {
}
// world can be null for non-placed BlockStates.
protected CraftBlockState(@Nullable World world, BlockPosition blockPosition, IBlockData blockData) {
protected CraftBlockState(@Nullable World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData) {
this.world = (CraftWorld) world;
position = blockPosition;
data = blockData;
this.position = blockPosition;
this.data = blockData;
}
// Creates an unplaced copy of the given CraftBlockState at the given location
@@ -61,11 +60,11 @@ public class CraftBlockState implements BlockState {
}
this.data = state.data;
this.flag = state.flag;
setWorldHandle(state.getWorldHandle());
this.setWorldHandle(state.getWorldHandle());
}
public void setWorldHandle(GeneratorAccess generatorAccess) {
if (generatorAccess instanceof net.minecraft.world.level.World) {
public void setWorldHandle(LevelAccessor generatorAccess) {
if (generatorAccess instanceof net.minecraft.world.level.Level) {
this.weakWorld = null;
} else {
this.weakWorld = new WeakReference<>(generatorAccess);
@@ -74,71 +73,71 @@ public class CraftBlockState implements BlockState {
// Returns null if weakWorld is not available and the BlockState is not placed.
// If this returns a World instead of only a GeneratorAccess, this implies that this BlockState is placed.
public GeneratorAccess getWorldHandle() {
if (weakWorld == null) {
return this.isPlaced() ? world.getHandle() : null;
public LevelAccessor getWorldHandle() {
if (this.weakWorld == null) {
return this.isPlaced() ? this.world.getHandle() : null;
}
GeneratorAccess access = weakWorld.get();
LevelAccessor access = this.weakWorld.get();
if (access == null) {
weakWorld = null;
return this.isPlaced() ? world.getHandle() : null;
this.weakWorld = null;
return this.isPlaced() ? this.world.getHandle() : null;
}
return access;
}
protected final boolean isWorldGeneration() {
GeneratorAccess generatorAccess = this.getWorldHandle();
return generatorAccess != null && !(generatorAccess instanceof net.minecraft.world.level.World);
LevelAccessor generatorAccess = this.getWorldHandle();
return generatorAccess != null && !(generatorAccess instanceof net.minecraft.world.level.Level);
}
protected final void ensureNoWorldGeneration() {
Preconditions.checkState(!isWorldGeneration(), "This operation is not supported during world generation!");
Preconditions.checkState(!this.isWorldGeneration(), "This operation is not supported during world generation!");
}
@Override
public World getWorld() {
requirePlaced();
return world;
this.requirePlaced();
return this.world;
}
@Override
public int getX() {
return position.getX();
return this.position.getX();
}
@Override
public int getY() {
return position.getY();
return this.position.getY();
}
@Override
public int getZ() {
return position.getZ();
return this.position.getZ();
}
@Override
public Chunk getChunk() {
requirePlaced();
return world.getChunkAt(getX() >> 4, getZ() >> 4);
this.requirePlaced();
return this.world.getChunkAt(this.getX() >> 4, this.getZ() >> 4);
}
public void setData(IBlockData data) {
public void setData(net.minecraft.world.level.block.state.BlockState data) {
this.data = data;
}
public BlockPosition getPosition() {
public BlockPos getPosition() {
return this.position;
}
public IBlockData getHandle() {
public net.minecraft.world.level.block.state.BlockState getHandle() {
return this.data;
}
@Override
public BlockData getBlockData() {
return CraftBlockData.fromData(data);
return CraftBlockData.fromData(this.data);
}
@Override
@@ -161,7 +160,7 @@ public class CraftBlockState implements BlockState {
@Override
public MaterialData getData() {
return CraftMagicNumbers.getMaterial(data);
return CraftMagicNumbers.getMaterial(this.data);
}
@Override
@@ -176,7 +175,7 @@ public class CraftBlockState implements BlockState {
@Override
public Material getType() {
return CraftBlockType.minecraftToBukkit(data.getBlock());
return CraftBlockType.minecraftToBukkit(this.data.getBlock());
}
public void setFlag(int flag) {
@@ -184,49 +183,49 @@ public class CraftBlockState implements BlockState {
}
public int getFlag() {
return flag;
return this.flag;
}
@Override
public byte getLightLevel() {
return getBlock().getLightLevel();
return this.getBlock().getLightLevel();
}
@Override
public CraftBlock getBlock() {
requirePlaced();
return CraftBlock.at(getWorldHandle(), position);
this.requirePlaced();
return CraftBlock.at(this.getWorldHandle(), this.position);
}
@Override
public boolean update() {
return update(false);
return this.update(false);
}
@Override
public boolean update(boolean force) {
return update(force, true);
return this.update(force, true);
}
@Override
public boolean update(boolean force, boolean applyPhysics) {
if (!isPlaced()) {
if (!this.isPlaced()) {
return true;
}
GeneratorAccess access = getWorldHandle();
CraftBlock block = getBlock();
LevelAccessor access = this.getWorldHandle();
CraftBlock block = this.getBlock();
if (block.getType() != getType()) {
if (block.getType() != this.getType()) {
if (!force) {
return false;
}
}
IBlockData newBlock = this.data;
net.minecraft.world.level.block.state.BlockState newBlock = this.data;
block.setTypeAndData(newBlock, applyPhysics);
if (access instanceof net.minecraft.world.level.World) {
world.getHandle().sendBlockUpdated(
position,
if (access instanceof net.minecraft.world.level.Level) {
this.world.getHandle().sendBlockUpdated(
this.position,
block.getNMS(),
newBlock,
3
@@ -234,8 +233,8 @@ public class CraftBlockState implements BlockState {
}
// Update levers etc
if (false && applyPhysics && getData() instanceof Attachable) { // Call does not map to new API
world.getHandle().updateNeighborsAt(position.relative(CraftBlock.blockFaceToNotch(((Attachable) getData()).getAttachedFace())), newBlock.getBlock());
if (false && applyPhysics && this.getData() instanceof Attachable) { // Call does not map to new API
this.world.getHandle().updateNeighborsAt(this.position.relative(CraftBlock.blockFaceToNotch(((Attachable) this.getData()).getAttachedFace())), newBlock.getBlock());
}
return true;
@@ -243,7 +242,7 @@ public class CraftBlockState implements BlockState {
@Override
public byte getRawData() {
return CraftMagicNumbers.toLegacyData(data);
return CraftMagicNumbers.toLegacyData(this.data);
}
@Override
@@ -254,10 +253,10 @@ public class CraftBlockState implements BlockState {
@Override
public Location getLocation(Location loc) {
if (loc != null) {
loc.setWorld(world);
loc.setX(getX());
loc.setY(getY());
loc.setZ(getZ());
loc.setWorld(this.world);
loc.setX(this.getX());
loc.setY(this.getY());
loc.setZ(this.getZ());
loc.setYaw(0);
loc.setPitch(0);
}
@@ -267,7 +266,7 @@ public class CraftBlockState implements BlockState {
@Override
public void setRawData(byte data) {
this.data = CraftMagicNumbers.getBlock(getType(), data);
this.data = CraftMagicNumbers.getBlock(this.getType(), data);
}
@Override
@@ -275,7 +274,7 @@ public class CraftBlockState implements BlockState {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (this.getClass() != obj.getClass()) {
return false;
}
final CraftBlockState other = (CraftBlockState) obj;
@@ -302,35 +301,35 @@ public class CraftBlockState implements BlockState {
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
requirePlaced();
world.getBlockMetadata().setMetadata(getBlock(), metadataKey, newMetadataValue);
this.requirePlaced();
this.world.getBlockMetadata().setMetadata(this.getBlock(), metadataKey, newMetadataValue);
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
requirePlaced();
return world.getBlockMetadata().getMetadata(getBlock(), metadataKey);
this.requirePlaced();
return this.world.getBlockMetadata().getMetadata(this.getBlock(), metadataKey);
}
@Override
public boolean hasMetadata(String metadataKey) {
requirePlaced();
return world.getBlockMetadata().hasMetadata(getBlock(), metadataKey);
this.requirePlaced();
return this.world.getBlockMetadata().hasMetadata(this.getBlock(), metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
requirePlaced();
world.getBlockMetadata().removeMetadata(getBlock(), metadataKey, owningPlugin);
this.requirePlaced();
this.world.getBlockMetadata().removeMetadata(this.getBlock(), metadataKey, owningPlugin);
}
@Override
public boolean isPlaced() {
return world != null;
return this.world != null;
}
protected void requirePlaced() {
Preconditions.checkState(isPlaced(), "The blockState must be placed to call this method");
Preconditions.checkState(this.isPlaced(), "The blockState must be placed to call this method");
}
@Override

View File

@@ -8,59 +8,58 @@ import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.nbt.NBTTagCompound;
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.GeneratorAccess;
import net.minecraft.world.level.IWorldReader;
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.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.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBanner;
import net.minecraft.world.level.block.entity.TileEntityBarrel;
import net.minecraft.world.level.block.entity.TileEntityBeacon;
import net.minecraft.world.level.block.entity.TileEntityBed;
import net.minecraft.world.level.block.entity.TileEntityBeehive;
import net.minecraft.world.level.block.entity.TileEntityBell;
import net.minecraft.world.level.block.entity.TileEntityBlastFurnace;
import net.minecraft.world.level.block.entity.TileEntityBrewingStand;
import net.minecraft.world.level.block.entity.TileEntityCampfire;
import net.minecraft.world.level.block.entity.TileEntityChest;
import net.minecraft.world.level.block.entity.TileEntityChestTrapped;
import net.minecraft.world.level.block.entity.TileEntityCommand;
import net.minecraft.world.level.block.entity.TileEntityComparator;
import net.minecraft.world.level.block.entity.TileEntityConduit;
import net.minecraft.world.level.block.entity.TileEntityDispenser;
import net.minecraft.world.level.block.entity.TileEntityDropper;
import net.minecraft.world.level.block.entity.TileEntityEnchantTable;
import net.minecraft.world.level.block.entity.TileEntityEndGateway;
import net.minecraft.world.level.block.entity.TileEntityEnderChest;
import net.minecraft.world.level.block.entity.TileEntityEnderPortal;
import net.minecraft.world.level.block.entity.TileEntityFurnaceFurnace;
import net.minecraft.world.level.block.entity.TileEntityHopper;
import net.minecraft.world.level.block.entity.TileEntityJigsaw;
import net.minecraft.world.level.block.entity.TileEntityJukeBox;
import net.minecraft.world.level.block.entity.TileEntityLectern;
import net.minecraft.world.level.block.entity.TileEntityLightDetector;
import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
import net.minecraft.world.level.block.entity.TileEntityShulkerBox;
import net.minecraft.world.level.block.entity.TileEntitySign;
import net.minecraft.world.level.block.entity.TileEntitySkull;
import net.minecraft.world.level.block.entity.TileEntitySmoker;
import net.minecraft.world.level.block.entity.TileEntityStructure;
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.TileEntityPiston;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
@@ -83,22 +82,22 @@ public final class CraftBlockStates {
// 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, BlockPosition blockPosition, IBlockData blockData, TileEntity tileEntity);
public abstract B createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity);
}
private static class BlockEntityStateFactory<T extends TileEntity, B extends CraftBlockEntityState<T>> extends BlockStateFactory<B> {
private static class BlockEntityStateFactory<T extends BlockEntity, B extends CraftBlockEntityState<T>> extends BlockStateFactory<B> {
private final BiFunction<World, T, B> blockStateConstructor;
private final BiFunction<BlockPosition, IBlockData, T> tileEntityConstructor;
private final BiFunction<BlockPos, net.minecraft.world.level.block.state.BlockState, T> tileEntityConstructor;
protected BlockEntityStateFactory(Class<B> blockStateType, BiFunction<World, T, B> blockStateConstructor, BiFunction<BlockPosition, IBlockData, T> tileEntityConstructor) {
protected BlockEntityStateFactory(Class<B> blockStateType, BiFunction<World, T, B> blockStateConstructor, BiFunction<BlockPos, net.minecraft.world.level.block.state.BlockState, T> tileEntityConstructor) {
super(blockStateType);
this.blockStateConstructor = blockStateConstructor;
this.tileEntityConstructor = tileEntityConstructor;
}
@Override
public final B createBlockState(World world, BlockPosition blockPosition, IBlockData blockData, TileEntity tileEntity) {
public final B createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
if (world != null) {
Preconditions.checkState(tileEntity != null, "Tile is null, asynchronous access? %s", CraftBlock.at(((CraftWorld) world).getHandle(), blockPosition));
} else if (tileEntity == null) {
@@ -107,19 +106,19 @@ public final class CraftBlockStates {
return this.createBlockState(world, (T) tileEntity);
}
private T createTileEntity(BlockPosition blockPosition, IBlockData blockData) {
return tileEntityConstructor.apply(blockPosition, blockData);
private T createTileEntity(BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData) {
return this.tileEntityConstructor.apply(blockPosition, blockData);
}
private B createBlockState(World world, T tileEntity) {
return blockStateConstructor.apply(world, tileEntity);
return this.blockStateConstructor.apply(world, tileEntity);
}
}
private static final Map<Material, BlockStateFactory<?>> FACTORIES = new HashMap<>();
private static final BlockStateFactory<?> DEFAULT_FACTORY = new BlockStateFactory<CraftBlockState>(CraftBlockState.class) {
@Override
public CraftBlockState createBlockState(World world, BlockPosition blockPosition, IBlockData blockData, TileEntity tileEntity) {
public CraftBlockState createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
// SPIGOT-6754, SPIGOT-6817: Restore previous behaviour for tile entities with removed blocks (loot generation post-destroy)
if (tileEntity != null) {
// block with unhandled TileEntity:
@@ -157,7 +156,7 @@ public final class CraftBlockStates {
Material.SPRUCE_WALL_SIGN,
Material.WARPED_SIGN,
Material.WARPED_WALL_SIGN
), CraftSign.class, CraftSign::new, TileEntitySign::new
), CraftSign.class, CraftSign::new, SignBlockEntity::new
);
register(
@@ -205,7 +204,7 @@ public final class CraftBlockStates {
Material.WITHER_SKELETON_WALL_SKULL,
Material.ZOMBIE_HEAD,
Material.ZOMBIE_WALL_HEAD
), CraftSkull.class, CraftSkull::new, TileEntitySkull::new
), CraftSkull.class, CraftSkull::new, SkullBlockEntity::new
);
register(
@@ -213,7 +212,7 @@ public final class CraftBlockStates {
Material.COMMAND_BLOCK,
Material.REPEATING_COMMAND_BLOCK,
Material.CHAIN_COMMAND_BLOCK
), CraftCommandBlock.class, CraftCommandBlock::new, TileEntityCommand::new
), CraftCommandBlock.class, CraftCommandBlock::new, CommandBlockEntity::new
);
register(
@@ -250,7 +249,7 @@ public final class CraftBlockStates {
Material.WHITE_WALL_BANNER,
Material.YELLOW_BANNER,
Material.YELLOW_WALL_BANNER
), CraftBanner.class, CraftBanner::new, TileEntityBanner::new
), CraftBanner.class, CraftBanner::new, BannerBlockEntity::new
);
register(
@@ -272,7 +271,7 @@ public final class CraftBlockStates {
Material.GREEN_SHULKER_BOX,
Material.RED_SHULKER_BOX,
Material.BLACK_SHULKER_BOX
), CraftShulkerBox.class, CraftShulkerBox::new, TileEntityShulkerBox::new
), CraftShulkerBox.class, CraftShulkerBox::new, ShulkerBoxBlockEntity::new
);
register(
@@ -293,101 +292,101 @@ public final class CraftBlockStates {
Material.RED_BED,
Material.WHITE_BED,
Material.YELLOW_BED
), CraftBed.class, CraftBed::new, TileEntityBed::new
), CraftBed.class, CraftBed::new, BedBlockEntity::new
);
register(
Arrays.asList(
Material.BEEHIVE,
Material.BEE_NEST
), CraftBeehive.class, CraftBeehive::new, TileEntityBeehive::new
), CraftBeehive.class, CraftBeehive::new, BeehiveBlockEntity::new
);
register(
Arrays.asList(
Material.CAMPFIRE,
Material.SOUL_CAMPFIRE
), CraftCampfire.class, CraftCampfire::new, TileEntityCampfire::new
), CraftCampfire.class, CraftCampfire::new, CampfireBlockEntity::new
);
register(Material.BARREL, CraftBarrel.class, CraftBarrel::new, TileEntityBarrel::new);
register(Material.BEACON, CraftBeacon.class, CraftBeacon::new, TileEntityBeacon::new);
register(Material.BELL, CraftBell.class, CraftBell::new, TileEntityBell::new);
register(Material.BLAST_FURNACE, CraftBlastFurnace.class, CraftBlastFurnace::new, TileEntityBlastFurnace::new);
register(Material.BREWING_STAND, CraftBrewingStand.class, CraftBrewingStand::new, TileEntityBrewingStand::new);
register(Material.CHEST, CraftChest.class, CraftChest::new, TileEntityChest::new);
register(Material.BARREL, CraftBarrel.class, CraftBarrel::new, BarrelBlockEntity::new);
register(Material.BEACON, CraftBeacon.class, CraftBeacon::new, BeaconBlockEntity::new);
register(Material.BELL, CraftBell.class, CraftBell::new, BellBlockEntity::new);
register(Material.BLAST_FURNACE, CraftBlastFurnace.class, CraftBlastFurnace::new, BlastFurnaceBlockEntity::new);
register(Material.BREWING_STAND, CraftBrewingStand.class, CraftBrewingStand::new, BrewingStandBlockEntity::new);
register(Material.CHEST, CraftChest.class, CraftChest::new, ChestBlockEntity::new);
register(Material.CHISELED_BOOKSHELF, CraftChiseledBookshelf.class, CraftChiseledBookshelf::new, ChiseledBookShelfBlockEntity::new);
register(Material.COMPARATOR, CraftComparator.class, CraftComparator::new, TileEntityComparator::new);
register(Material.CONDUIT, CraftConduit.class, CraftConduit::new, TileEntityConduit::new);
register(Material.COMPARATOR, CraftComparator.class, CraftComparator::new, ComparatorBlockEntity::new);
register(Material.CONDUIT, CraftConduit.class, CraftConduit::new, ConduitBlockEntity::new);
register(Material.CREAKING_HEART, CraftCreakingHeart.class, CraftCreakingHeart::new, CreakingHeartBlockEntity::new);
register(Material.DAYLIGHT_DETECTOR, CraftDaylightDetector.class, CraftDaylightDetector::new, TileEntityLightDetector::new);
register(Material.DAYLIGHT_DETECTOR, CraftDaylightDetector.class, CraftDaylightDetector::new, DaylightDetectorBlockEntity::new);
register(Material.DECORATED_POT, CraftDecoratedPot.class, CraftDecoratedPot::new, DecoratedPotBlockEntity::new);
register(Material.DISPENSER, CraftDispenser.class, CraftDispenser::new, TileEntityDispenser::new);
register(Material.DROPPER, CraftDropper.class, CraftDropper::new, TileEntityDropper::new);
register(Material.ENCHANTING_TABLE, CraftEnchantingTable.class, CraftEnchantingTable::new, TileEntityEnchantTable::new);
register(Material.ENDER_CHEST, CraftEnderChest.class, CraftEnderChest::new, TileEntityEnderChest::new);
register(Material.END_GATEWAY, CraftEndGateway.class, CraftEndGateway::new, TileEntityEndGateway::new);
register(Material.END_PORTAL, CraftEndPortal.class, CraftEndPortal::new, TileEntityEnderPortal::new);
register(Material.FURNACE, CraftFurnaceFurnace.class, CraftFurnaceFurnace::new, TileEntityFurnaceFurnace::new);
register(Material.HOPPER, CraftHopper.class, CraftHopper::new, TileEntityHopper::new);
register(Material.JIGSAW, CraftJigsaw.class, CraftJigsaw::new, TileEntityJigsaw::new);
register(Material.JUKEBOX, CraftJukebox.class, CraftJukebox::new, TileEntityJukeBox::new);
register(Material.LECTERN, CraftLectern.class, CraftLectern::new, TileEntityLectern::new);
register(Material.MOVING_PISTON, CraftMovingPiston.class, CraftMovingPiston::new, TileEntityPiston::new);
register(Material.DISPENSER, CraftDispenser.class, CraftDispenser::new, DispenserBlockEntity::new);
register(Material.DROPPER, CraftDropper.class, CraftDropper::new, DropperBlockEntity::new);
register(Material.ENCHANTING_TABLE, CraftEnchantingTable.class, CraftEnchantingTable::new, EnchantingTableBlockEntity::new);
register(Material.ENDER_CHEST, CraftEnderChest.class, CraftEnderChest::new, EnderChestBlockEntity::new);
register(Material.END_GATEWAY, CraftEndGateway.class, CraftEndGateway::new, TheEndGatewayBlockEntity::new);
register(Material.END_PORTAL, CraftEndPortal.class, CraftEndPortal::new, TheEndPortalBlockEntity::new);
register(Material.FURNACE, CraftFurnaceFurnace.class, CraftFurnaceFurnace::new, FurnaceBlockEntity::new);
register(Material.HOPPER, CraftHopper.class, CraftHopper::new, HopperBlockEntity::new);
register(Material.JIGSAW, CraftJigsaw.class, CraftJigsaw::new, JigsawBlockEntity::new);
register(Material.JUKEBOX, CraftJukebox.class, CraftJukebox::new, JukeboxBlockEntity::new);
register(Material.LECTERN, CraftLectern.class, CraftLectern::new, LecternBlockEntity::new);
register(Material.MOVING_PISTON, CraftMovingPiston.class, CraftMovingPiston::new, PistonMovingBlockEntity::new);
register(Material.SCULK_CATALYST, CraftSculkCatalyst.class, CraftSculkCatalyst::new, SculkCatalystBlockEntity::new);
register(Material.CALIBRATED_SCULK_SENSOR, CraftCalibratedSculkSensor.class, CraftCalibratedSculkSensor::new, CalibratedSculkSensorBlockEntity::new);
register(Material.SCULK_SENSOR, CraftSculkSensor.class, CraftSculkSensor::new, SculkSensorBlockEntity::new);
register(Material.SCULK_SHRIEKER, CraftSculkShrieker.class, CraftSculkShrieker::new, SculkShriekerBlockEntity::new);
register(Material.SMOKER, CraftSmoker.class, CraftSmoker::new, TileEntitySmoker::new);
register(Material.SPAWNER, CraftCreatureSpawner.class, CraftCreatureSpawner::new, TileEntityMobSpawner::new);
register(Material.STRUCTURE_BLOCK, CraftStructureBlock.class, CraftStructureBlock::new, TileEntityStructure::new);
register(Material.SMOKER, CraftSmoker.class, CraftSmoker::new, SmokerBlockEntity::new);
register(Material.SPAWNER, CraftCreatureSpawner.class, CraftCreatureSpawner::new, SpawnerBlockEntity::new);
register(Material.STRUCTURE_BLOCK, CraftStructureBlock.class, CraftStructureBlock::new, StructureBlockEntity::new);
register(Material.SUSPICIOUS_SAND, CraftSuspiciousSand.class, CraftSuspiciousSand::new, BrushableBlockEntity::new);
register(Material.SUSPICIOUS_GRAVEL, CraftBrushableBlock.class, CraftBrushableBlock::new, BrushableBlockEntity::new);
register(Material.TRAPPED_CHEST, CraftChest.class, CraftChest::new, TileEntityChestTrapped::new);
register(Material.TRAPPED_CHEST, CraftChest.class, CraftChest::new, TrappedChestBlockEntity::new);
register(Material.CRAFTER, CraftCrafter.class, CraftCrafter::new, CrafterBlockEntity::new);
register(Material.TRIAL_SPAWNER, CraftTrialSpawner.class, CraftTrialSpawner::new, TrialSpawnerBlockEntity::new);
register(Material.VAULT, CraftVault.class, CraftVault::new, VaultBlockEntity::new);
}
private static void register(Material blockType, BlockStateFactory<?> factory) {
FACTORIES.put(blockType, factory);
CraftBlockStates.FACTORIES.put(blockType, factory);
}
private static <T extends TileEntity, B extends CraftBlockEntityState<T>> void register(
private static <T extends BlockEntity, B extends CraftBlockEntityState<T>> void register(
Material blockType,
Class<B> blockStateType,
BiFunction<World, T, B> blockStateConstructor,
BiFunction<BlockPosition, IBlockData, T> tileEntityConstructor
BiFunction<BlockPos, net.minecraft.world.level.block.state.BlockState, T> tileEntityConstructor
) {
register(Collections.singletonList(blockType), blockStateType, blockStateConstructor, tileEntityConstructor);
CraftBlockStates.register(Collections.singletonList(blockType), blockStateType, blockStateConstructor, tileEntityConstructor);
}
private static <T extends TileEntity, B extends CraftBlockEntityState<T>> void register(
private static <T extends BlockEntity, B extends CraftBlockEntityState<T>> void register(
List<Material> blockTypes,
Class<B> blockStateType,
BiFunction<World, T, B> blockStateConstructor,
BiFunction<BlockPosition, IBlockData, T> tileEntityConstructor
BiFunction<BlockPos, net.minecraft.world.level.block.state.BlockState, T> tileEntityConstructor
) {
BlockStateFactory<B> factory = new BlockEntityStateFactory<>(blockStateType, blockStateConstructor, tileEntityConstructor);
for (Material blockType : blockTypes) {
register(blockType, factory);
CraftBlockStates.register(blockType, factory);
}
}
private static BlockStateFactory<?> getFactory(Material material) {
return FACTORIES.getOrDefault(material, DEFAULT_FACTORY);
return CraftBlockStates.FACTORIES.getOrDefault(material, CraftBlockStates.DEFAULT_FACTORY);
}
public static Class<? extends CraftBlockState> getBlockStateType(Material material) {
Preconditions.checkNotNull(material, "material is null");
return getFactory(material).blockStateType;
return CraftBlockStates.getFactory(material).blockStateType;
}
public static TileEntity createNewTileEntity(Material material) {
BlockStateFactory<?> factory = getFactory(material);
public static BlockEntity createNewTileEntity(Material material) {
BlockStateFactory<?> factory = CraftBlockStates.getFactory(material);
if (factory instanceof BlockEntityStateFactory) {
return ((BlockEntityStateFactory<?, ?>) factory).createTileEntity(BlockPosition.ZERO, CraftBlockType.bukkitToMinecraft(material).defaultBlockState());
return ((BlockEntityStateFactory<?, ?>) factory).createTileEntity(BlockPos.ZERO, CraftBlockType.bukkitToMinecraft(material).defaultBlockState());
}
return null;
@@ -397,55 +396,55 @@ public final class CraftBlockStates {
Preconditions.checkNotNull(block, "block is null");
CraftBlock craftBlock = (CraftBlock) block;
CraftWorld world = (CraftWorld) block.getWorld();
BlockPosition blockPosition = craftBlock.getPosition();
IBlockData blockData = craftBlock.getNMS();
TileEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition);
CraftBlockState blockState = getBlockState(world, blockPosition, blockData, tileEntity);
BlockPos blockPosition = craftBlock.getPosition();
net.minecraft.world.level.block.state.BlockState blockData = craftBlock.getNMS();
BlockEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition);
CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
return blockState;
}
@Deprecated
public static BlockState getBlockState(BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) {
return getBlockState(MinecraftServer.getDefaultRegistryAccess(), blockPosition, material, blockEntityTag);
public static BlockState getBlockState(BlockPos blockPosition, Material material, @Nullable CompoundTag blockEntityTag) {
return CraftBlockStates.getBlockState(MinecraftServer.getDefaultRegistryAccess(), blockPosition, material, blockEntityTag);
}
public static BlockState getBlockState(IWorldReader world, BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) {
return getBlockState(world.registryAccess(), blockPosition, 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(IRegistryCustom registry, BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) {
public static BlockState getBlockState(RegistryAccess registry, BlockPos blockPosition, Material material, @Nullable CompoundTag blockEntityTag) {
Preconditions.checkNotNull(material, "material is null");
IBlockData blockData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState();
return getBlockState(registry, blockPosition, blockData, blockEntityTag);
net.minecraft.world.level.block.state.BlockState blockData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState();
return CraftBlockStates.getBlockState(registry, blockPosition, blockData, blockEntityTag);
}
@Deprecated
public static BlockState getBlockState(IBlockData blockData, @Nullable NBTTagCompound blockEntityTag) {
return getBlockState(MinecraftServer.getDefaultRegistryAccess(), BlockPosition.ZERO, blockData, blockEntityTag);
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(IWorldReader world, BlockPosition blockPosition, IBlockData blockData, @Nullable NBTTagCompound blockEntityTag) {
return getBlockState(world.registryAccess(), blockPosition, blockData, 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(IRegistryCustom registry, BlockPosition blockPosition, IBlockData blockData, @Nullable NBTTagCompound 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");
TileEntity tileEntity = (blockEntityTag == null) ? null : TileEntity.loadStatic(blockPosition, blockData, blockEntityTag, registry);
return getBlockState(null, blockPosition, blockData, tileEntity);
BlockEntity tileEntity = (blockEntityTag == null) ? null : BlockEntity.loadStatic(blockPosition, blockData, blockEntityTag, registry);
return CraftBlockStates.getBlockState(null, blockPosition, blockData, tileEntity);
}
// See BlockStateFactory#createBlockState(World, BlockPosition, IBlockData, TileEntity)
private static CraftBlockState getBlockState(World world, BlockPosition blockPosition, IBlockData blockData, TileEntity 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());
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 && isTileEntityOptional(material)) {
factory = DEFAULT_FACTORY;
if (world != null && tileEntity == null && CraftBlockStates.isTileEntityOptional(material)) {
factory = CraftBlockStates.DEFAULT_FACTORY;
} else {
factory = getFactory(material);
factory = CraftBlockStates.getFactory(material);
}
return factory.createBlockState(world, blockPosition, blockData, tileEntity);
}
@@ -455,12 +454,12 @@ public final class CraftBlockStates {
}
// This ignores tile entity data.
public static CraftBlockState getBlockState(GeneratorAccess world, BlockPosition pos) {
public static CraftBlockState getBlockState(LevelAccessor world, BlockPos pos) {
return new CraftBlockState(CraftBlock.at(world, pos));
}
// This ignores tile entity data.
public static CraftBlockState getBlockState(GeneratorAccess world, BlockPosition pos, int flag) {
public static CraftBlockState getBlockState(LevelAccessor world, BlockPos pos, int flag) {
return new CraftBlockState(CraftBlock.at(world, pos), flag);
}

View File

@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.EnumBlockSupport;
import net.minecraft.world.level.block.SupportType;
import org.bukkit.block.BlockSupport;
public final class CraftBlockSupport {
@@ -8,7 +8,7 @@ public final class CraftBlockSupport {
private CraftBlockSupport() {
}
public static BlockSupport toBukkit(EnumBlockSupport support) {
public static BlockSupport toBukkit(SupportType support) {
return switch (support) {
case FULL -> BlockSupport.FULL;
case CENTER -> BlockSupport.CENTER;
@@ -17,11 +17,11 @@ public final class CraftBlockSupport {
};
}
public static EnumBlockSupport toNMS(BlockSupport support) {
public static SupportType toNMS(BlockSupport support) {
return switch (support) {
case FULL -> EnumBlockSupport.FULL;
case CENTER -> EnumBlockSupport.CENTER;
case RIGID -> EnumBlockSupport.RIGID;
case FULL -> SupportType.FULL;
case CENTER -> SupportType.CENTER;
case RIGID -> SupportType.RIGID;
default -> throw new IllegalArgumentException("Unsupported BlockSupport type: " + support + ". This is a bug.");
};
}

View File

@@ -4,20 +4,20 @@ import com.google.common.base.Preconditions;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.function.Consumer;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.EnumHand;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockAccessAir;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BlockFire;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Fallable;
import net.minecraft.world.level.block.state.BlockBase;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.level.block.FireBlock;
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;
@@ -70,21 +70,21 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
}
private static final Class<?>[] USE_WITHOUT_ITEM_ARGS = new Class[]{
IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, MovingObjectPositionBlock.class
BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, BlockHitResult.class
};
private static final Class<?>[] USE_ITEM_ON_ARGS = new Class[]{
net.minecraft.world.item.ItemStack.class, IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class
net.minecraft.world.item.ItemStack.class, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, InteractionHand.class, BlockHitResult.class
};
private static boolean isInteractable(Block block) {
Class<?> clazz = block.getClass();
boolean hasMethod = hasMethod(clazz, USE_WITHOUT_ITEM_ARGS) || hasMethod(clazz, USE_ITEM_ON_ARGS);
boolean hasMethod = CraftBlockType.hasMethod(clazz, CraftBlockType.USE_WITHOUT_ITEM_ARGS) || CraftBlockType.hasMethod(clazz, CraftBlockType.USE_ITEM_ON_ARGS);
if (!hasMethod && clazz.getSuperclass() != BlockBase.class) {
if (!hasMethod && clazz.getSuperclass() != BlockBehaviour.class) {
clazz = clazz.getSuperclass();
hasMethod = hasMethod(clazz, USE_WITHOUT_ITEM_ARGS) || hasMethod(clazz, USE_ITEM_ON_ARGS);
hasMethod = CraftBlockType.hasMethod(clazz, CraftBlockType.USE_WITHOUT_ITEM_ARGS) || CraftBlockType.hasMethod(clazz, CraftBlockType.USE_ITEM_ON_ARGS);
}
return hasMethod;
@@ -94,12 +94,12 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
this.key = key;
this.block = block;
this.blockDataClass = (Class<B>) CraftBlockData.fromData(block.defaultBlockState()).getClass().getInterfaces()[0];
this.interactable = isInteractable(block);
this.interactable = CraftBlockType.isInteractable(block);
}
@Override
public Block getHandle() {
return block;
return this.block;
}
@NotNull
@@ -122,7 +122,7 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
return true;
}
return block.asItem() != Items.AIR;
return this.block.asItem() != Items.AIR;
}
@NotNull
@@ -132,24 +132,24 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
return ItemType.AIR;
}
Item item = block.asItem();
Preconditions.checkArgument(item != Items.AIR, "The block type %s has no corresponding item type", getKey());
Item item = this.block.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 blockDataClass;
return this.blockDataClass;
}
@Override
public B createBlockData() {
return createBlockData((String) null);
return this.createBlockData((String) null);
}
@Override
public B createBlockData(Consumer<? super B> consumer) {
B data = createBlockData();
B data = this.createBlockData();
if (consumer != null) {
consumer.accept(data);
@@ -165,69 +165,69 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
@Override
public boolean isSolid() {
return block.defaultBlockState().blocksMotion();
return this.block.defaultBlockState().blocksMotion();
}
@Override
public boolean isAir() {
return block.defaultBlockState().isAir();
return this.block.defaultBlockState().isAir();
}
@Override
public boolean isEnabledByFeature(@NotNull World world) {
Preconditions.checkNotNull(world, "World cannot be null");
return getHandle().isEnabled(((CraftWorld) world).getHandle().enabledFeatures());
return this.getHandle().isEnabled(((CraftWorld) world).getHandle().enabledFeatures());
}
@Override
public boolean isFlammable() {
return block.defaultBlockState().ignitedByLava();
return this.block.defaultBlockState().ignitedByLava();
}
@Override
public boolean isBurnable() {
return ((BlockFire) Blocks.FIRE).igniteOdds.getOrDefault(block, 0) > 0;
return ((FireBlock) Blocks.FIRE).igniteOdds.getOrDefault(this.block, 0) > 0;
}
@Override
public boolean isOccluding() {
return block.defaultBlockState().isRedstoneConductor(BlockAccessAir.INSTANCE, BlockPosition.ZERO);
return this.block.defaultBlockState().isRedstoneConductor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
}
@Override
public boolean hasGravity() {
return block instanceof Fallable;
return this.block instanceof Fallable;
}
@Override
public boolean isInteractable() {
return interactable;
return this.interactable;
}
@Override
public float getHardness() {
return block.defaultBlockState().destroySpeed;
return this.block.defaultBlockState().destroySpeed;
}
@Override
public float getBlastResistance() {
return block.getExplosionResistance();
return this.block.getExplosionResistance();
}
@Override
public float getSlipperiness() {
return block.getFriction();
return this.block.getFriction();
}
@NotNull
@Override
public String getTranslationKey() {
return block.getDescriptionId();
return this.block.getDescriptionId();
}
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override

View File

@@ -1,15 +1,15 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityBrewingStand;
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BrewingStand;
import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer;
import org.bukkit.inventory.BrewerInventory;
public class CraftBrewingStand extends CraftContainer<TileEntityBrewingStand> implements BrewingStand {
public class CraftBrewingStand extends CraftContainer<BrewingStandBlockEntity> implements BrewingStand {
public CraftBrewingStand(World world, TileEntityBrewingStand tileEntity) {
public CraftBrewingStand(World world, BrewingStandBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -21,12 +21,12 @@ public class CraftBrushableBlock extends CraftBlockEntityState<BrushableBlockEnt
@Override
public ItemStack getItem() {
return CraftItemStack.asBukkitCopy(getSnapshot().getItem());
return CraftItemStack.asBukkitCopy(this.getSnapshot().getItem());
}
@Override
public void setItem(ItemStack item) {
getSnapshot().item = CraftItemStack.asNMSCopy(item);
this.getSnapshot().item = CraftItemStack.asNMSCopy(item);
}
@Override
@@ -40,26 +40,26 @@ public class CraftBrushableBlock extends CraftBlockEntityState<BrushableBlockEnt
@Override
public LootTable getLootTable() {
return CraftLootTable.minecraftToBukkit(getSnapshot().lootTable);
return CraftLootTable.minecraftToBukkit(this.getSnapshot().lootTable);
}
@Override
public void setLootTable(LootTable table) {
setLootTable(table, getSeed());
this.setLootTable(table, this.getSeed());
}
@Override
public long getSeed() {
return getSnapshot().lootTableSeed;
return this.getSnapshot().lootTableSeed;
}
@Override
public void setSeed(long seed) {
setLootTable(getLootTable(), seed);
this.setLootTable(this.getLootTable(), seed);
}
private void setLootTable(LootTable table, long seed) {
getSnapshot().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed);
this.getSnapshot().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed);
}
@Override

View File

@@ -1,15 +1,15 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityCampfire;
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Campfire;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class CraftCampfire extends CraftBlockEntityState<TileEntityCampfire> implements Campfire {
public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> implements Campfire {
public CraftCampfire(World world, TileEntityCampfire tileEntity) {
public CraftCampfire(World world, CampfireBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -19,38 +19,38 @@ public class CraftCampfire extends CraftBlockEntityState<TileEntityCampfire> imp
@Override
public int getSize() {
return getSnapshot().getItems().size();
return this.getSnapshot().getItems().size();
}
@Override
public ItemStack getItem(int index) {
net.minecraft.world.item.ItemStack item = getSnapshot().getItems().get(index);
net.minecraft.world.item.ItemStack item = this.getSnapshot().getItems().get(index);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
}
@Override
public void setItem(int index, ItemStack item) {
getSnapshot().getItems().set(index, CraftItemStack.asNMSCopy(item));
this.getSnapshot().getItems().set(index, CraftItemStack.asNMSCopy(item));
}
@Override
public int getCookTime(int index) {
return getSnapshot().cookingProgress[index];
return this.getSnapshot().cookingProgress[index];
}
@Override
public void setCookTime(int index, int cookTime) {
getSnapshot().cookingProgress[index] = cookTime;
this.getSnapshot().cookingProgress[index] = cookTime;
}
@Override
public int getCookTimeTotal(int index) {
return getSnapshot().cookingTime[index];
return this.getSnapshot().cookingTime[index];
}
@Override
public void setCookTimeTotal(int index, int cookTimeTotal) {
getSnapshot().cookingTime[index] = cookTimeTotal;
this.getSnapshot().cookingTime[index] = cookTimeTotal;
}
@Override

View File

@@ -1,10 +1,10 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.ITileInventory;
import net.minecraft.world.level.block.BlockChest;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntityChest;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -14,9 +14,9 @@ import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest;
import org.bukkit.inventory.Inventory;
public class CraftChest extends CraftLootable<TileEntityChest> implements Chest {
public class CraftChest extends CraftLootable<ChestBlockEntity> implements Chest {
public CraftChest(World world, TileEntityChest tileEntity) {
public CraftChest(World world, ChestBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -41,46 +41,46 @@ public class CraftChest extends CraftLootable<TileEntityChest> implements Chest
@Override
public Inventory getInventory() {
CraftInventory inventory = (CraftInventory) this.getBlockInventory();
if (!isPlaced() || isWorldGeneration()) {
if (!this.isPlaced() || this.isWorldGeneration()) {
return inventory;
}
// The logic here is basically identical to the logic in BlockChest.interact
CraftWorld world = (CraftWorld) this.getWorld();
BlockChest blockChest = (BlockChest) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
ITileInventory nms = blockChest.getMenuProvider(data, world.getHandle(), this.getPosition(), true);
ChestBlock blockChest = (ChestBlock) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
MenuProvider nms = blockChest.getMenuProvider(this.data, world.getHandle(), this.getPosition(), true);
if (nms instanceof BlockChest.DoubleInventory) {
inventory = new CraftInventoryDoubleChest((BlockChest.DoubleInventory) nms);
if (nms instanceof ChestBlock.DoubleInventory) {
inventory = new CraftInventoryDoubleChest((ChestBlock.DoubleInventory) nms);
}
return inventory;
}
@Override
public void open() {
requirePlaced();
if (!getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) {
IBlockData block = getTileEntity().getBlockState();
int openCount = getTileEntity().openersCounter.getOpenerCount();
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();
getTileEntity().openersCounter.onAPIOpen((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block);
getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, openCount + 1);
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);
}
getTileEntity().openersCounter.opened = true;
this.getTileEntity().openersCounter.opened = true;
}
@Override
public void close() {
requirePlaced();
if (getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) {
IBlockData block = getTileEntity().getBlockState();
int openCount = getTileEntity().openersCounter.getOpenerCount();
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();
getTileEntity().openersCounter.onAPIClose((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block);
getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, 0);
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);
}
getTileEntity().openersCounter.opened = false;
this.getTileEntity().openersCounter.opened = false;
}
@Override

View File

@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.ChiseledBookShelfBlock;
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec2;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
@@ -24,12 +24,12 @@ public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookSh
@Override
public int getLastInteractedSlot() {
return getSnapshot().getLastInteractedSlot();
return this.getSnapshot().getLastInteractedSlot();
}
@Override
public void setLastInteractedSlot(int lastInteractedSlot) {
getSnapshot().lastInteractedSlot = lastInteractedSlot;
this.getSnapshot().lastInteractedSlot = lastInteractedSlot;
}
@Override
@@ -50,19 +50,19 @@ public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookSh
public int getSlot(Vector clickVector) {
BlockFace facing = ((Directional) this.getBlockData()).getFacing();
Vec2F faceVector;
Vec2 faceVector;
switch (facing) {
case NORTH:
faceVector = new Vec2F((float) (1.0f - clickVector.getX()), (float) clickVector.getY());
faceVector = new Vec2((float) (1.0f - clickVector.getX()), (float) clickVector.getY());
break;
case SOUTH:
faceVector = new Vec2F((float) clickVector.getX(), (float) clickVector.getY());
faceVector = new Vec2((float) clickVector.getX(), (float) clickVector.getY());
break;
case WEST:
faceVector = new Vec2F((float) clickVector.getZ(), (float) clickVector.getY());
faceVector = new Vec2((float) clickVector.getZ(), (float) clickVector.getY());
break;
case EAST:
faceVector = new Vec2F((float) (1f - clickVector.getZ()), (float) clickVector.getY());
faceVector = new Vec2((float) (1f - clickVector.getZ()), (float) clickVector.getY());
break;
case DOWN:
case UP:
@@ -70,10 +70,10 @@ public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookSh
return -1;
}
return getHitSlot(faceVector);
return CraftChiseledBookshelf.getHitSlot(faceVector);
}
private static int getHitSlot(Vec2F vec2f) {
private static int getHitSlot(Vec2 vec2f) {
int i = vec2f.y >= 0.5F ? 0 : 1;
int j = ChiseledBookShelfBlock.getSection(vec2f.x);

View File

@@ -1,14 +1,14 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityCommand;
import net.minecraft.world.level.block.entity.CommandBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CommandBlock;
import org.bukkit.craftbukkit.util.CraftChatMessage;
public class CraftCommandBlock extends CraftBlockEntityState<TileEntityCommand> implements CommandBlock {
public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity> implements CommandBlock {
public CraftCommandBlock(World world, TileEntityCommand tileEntity) {
public CraftCommandBlock(World world, CommandBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -18,22 +18,22 @@ public class CraftCommandBlock extends CraftBlockEntityState<TileEntityCommand>
@Override
public String getCommand() {
return getSnapshot().getCommandBlock().getCommand();
return this.getSnapshot().getCommandBlock().getCommand();
}
@Override
public void setCommand(String command) {
getSnapshot().getCommandBlock().setCommand(command != null ? command : "");
this.getSnapshot().getCommandBlock().setCommand(command != null ? command : "");
}
@Override
public String getName() {
return CraftChatMessage.fromComponent(getSnapshot().getCommandBlock().getName());
return CraftChatMessage.fromComponent(this.getSnapshot().getCommandBlock().getName());
}
@Override
public void setName(String name) {
getSnapshot().getCommandBlock().setCustomName(CraftChatMessage.fromStringOrNull(name != null ? name : "@"));
this.getSnapshot().getCommandBlock().setCustomName(CraftChatMessage.fromStringOrNull(name != null ? name : "@"));
}
@Override

View File

@@ -1,13 +1,13 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityComparator;
import net.minecraft.world.level.block.entity.ComparatorBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Comparator;
public class CraftComparator extends CraftBlockEntityState<TileEntityComparator> implements Comparator {
public class CraftComparator extends CraftBlockEntityState<ComparatorBlockEntity> implements Comparator {
public CraftComparator(World world, TileEntityComparator tileEntity) {
public CraftComparator(World world, ComparatorBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -2,10 +2,9 @@ package org.bukkit.craftbukkit.block;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.core.BlockPosition;
import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.level.block.entity.TileEntityConduit;
import net.minecraft.world.phys.AxisAlignedBB;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.ConduitBlockEntity;
import net.minecraft.world.phys.AABB;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
@@ -14,9 +13,9 @@ import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.BoundingBox;
public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> implements Conduit {
public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> implements Conduit {
public CraftConduit(World world, TileEntityConduit tileEntity) {
public CraftConduit(World world, ConduitBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -36,27 +35,27 @@ public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> imple
@Override
public boolean isActive() {
ensureNoWorldGeneration();
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
return conduit != null && conduit.isActive();
}
@Override
public boolean isHunting() {
ensureNoWorldGeneration();
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
return conduit != null && conduit.isHunting();
}
@Override
public Collection<Block> getFrameBlocks() {
ensureNoWorldGeneration();
this.ensureNoWorldGeneration();
Collection<Block> blocks = new ArrayList<>();
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
if (conduit != null) {
for (BlockPosition position : conduit.effectBlocks) {
blocks.add(CraftBlock.at(getWorldHandle(), position));
for (BlockPos position : conduit.effectBlocks) {
blocks.add(CraftBlock.at(this.getWorldHandle(), position));
}
}
@@ -65,26 +64,26 @@ public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> imple
@Override
public int getFrameBlockCount() {
ensureNoWorldGeneration();
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
return (conduit != null) ? conduit.effectBlocks.size() : 0;
}
@Override
public int getRange() {
ensureNoWorldGeneration();
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
return (conduit != null) ? TileEntityConduit.getRange(conduit.effectBlocks) : 0;
this.ensureNoWorldGeneration();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
return (conduit != null) ? ConduitBlockEntity.getRange(conduit.effectBlocks) : 0;
}
@Override
public boolean setTarget(LivingEntity target) {
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
if (conduit == null) {
return false;
}
EntityLiving currentTarget = conduit.destroyTarget;
net.minecraft.world.entity.LivingEntity currentTarget = conduit.destroyTarget;
if (target == null) {
if (currentTarget == null) {
@@ -102,30 +101,30 @@ public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> imple
conduit.destroyTargetUUID = target.getUniqueId();
}
TileEntityConduit.updateDestroyTarget(conduit.getLevel(), getPosition(), data, conduit.effectBlocks, conduit, false);
ConduitBlockEntity.updateDestroyTarget(conduit.getLevel(), this.getPosition(), this.data, conduit.effectBlocks, conduit, false);
return true;
}
@Override
public LivingEntity getTarget() {
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
if (conduit == null) {
return null;
}
EntityLiving nmsEntity = conduit.destroyTarget;
net.minecraft.world.entity.LivingEntity nmsEntity = conduit.destroyTarget;
return (nmsEntity != null) ? (LivingEntity) nmsEntity.getBukkitEntity() : null;
}
@Override
public boolean hasTarget() {
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
return conduit != null && conduit.destroyTarget != null && conduit.destroyTarget.isAlive();
}
@Override
public BoundingBox getHuntingArea() {
AxisAlignedBB bounds = TileEntityConduit.getDestroyRangeAABB(getPosition());
AABB bounds = ConduitBlockEntity.getDestroyRangeAABB(this.getPosition());
return new BoundingBox(bounds.minX, bounds.minY, bounds.minZ, bounds.maxX, bounds.maxY, bounds.maxZ);
}
}

View File

@@ -2,13 +2,13 @@ package org.bukkit.craftbukkit.block;
import java.util.Collections;
import java.util.Optional;
import net.minecraft.advancements.critereon.CriterionConditionItem;
import net.minecraft.advancements.critereon.CriterionConditionValue;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.component.DataComponentPredicate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.world.ChestLock;
import net.minecraft.world.level.block.entity.TileEntityContainer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.LockCode;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Container;
@@ -16,7 +16,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.inventory.ItemStack;
public abstract class CraftContainer<T extends TileEntityContainer> extends CraftBlockEntityState<T> implements Container {
public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends CraftBlockEntityState<T> implements Container {
public CraftContainer(World world, T tileEntity) {
super(world, tileEntity);
@@ -28,12 +28,12 @@ public abstract class CraftContainer<T extends TileEntityContainer> extends Craf
@Override
public boolean isLocked() {
return this.getSnapshot().lockKey != ChestLock.NO_LOCK;
return this.getSnapshot().lockKey != LockCode.NO_LOCK;
}
@Override
public String getLock() {
Optional<? extends IChatBaseComponent> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
Optional<? extends Component> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : "";
}
@@ -41,19 +41,19 @@ public abstract class CraftContainer<T extends TileEntityContainer> extends Craf
@Override
public void setLock(String key) {
if (key == null) {
this.getSnapshot().lockKey = ChestLock.NO_LOCK;
this.getSnapshot().lockKey = LockCode.NO_LOCK;
} else {
DataComponentPredicate predicate = DataComponentPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build();
this.getSnapshot().lockKey = new ChestLock(new CriterionConditionItem(Optional.empty(), CriterionConditionValue.IntegerRange.ANY, predicate, Collections.emptyMap()));
this.getSnapshot().lockKey = new LockCode(new ItemPredicate(Optional.empty(), MinMaxBounds.Ints.ANY, predicate, Collections.emptyMap()));
}
}
@Override
public void setLockItem(ItemStack key) {
if (key == null) {
this.getSnapshot().lockKey = ChestLock.NO_LOCK;
this.getSnapshot().lockKey = LockCode.NO_LOCK;
} else {
this.getSnapshot().lockKey = new ChestLock(CraftItemStack.asCriterionConditionItem(key));
this.getSnapshot().lockKey = new LockCode(CraftItemStack.asCriterionConditionItem(key));
}
}

View File

@@ -44,35 +44,35 @@ public class CraftCrafter extends CraftLootable<CrafterBlockEntity> implements C
@Override
public int getCraftingTicks() {
return getSnapshot().craftingTicksRemaining;
return this.getSnapshot().craftingTicksRemaining;
}
@Override
public void setCraftingTicks(int ticks) {
getSnapshot().setCraftingTicksRemaining(ticks);
this.getSnapshot().setCraftingTicksRemaining(ticks);
}
@Override
public boolean isSlotDisabled(int slot) {
Preconditions.checkArgument(slot >= 0 && slot < 9, "Invalid slot index %s for Crafter", slot);
return getSnapshot().isSlotDisabled(slot);
return this.getSnapshot().isSlotDisabled(slot);
}
@Override
public void setSlotDisabled(int slot, boolean disabled) {
Preconditions.checkArgument(slot >= 0 && slot < 9, "Invalid slot index %s for Crafter", slot);
getSnapshot().setSlotState(slot, disabled);
this.getSnapshot().setSlotState(slot, disabled);
}
@Override
public boolean isTriggered() {
return getSnapshot().isTriggered();
return this.getSnapshot().isTriggered();
}
@Override
public void setTriggered(boolean triggered) {
getSnapshot().setTriggered(triggered);
this.getSnapshot().setTriggered(triggered);
}
}

View File

@@ -8,16 +8,15 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import net.minecraft.nbt.NBTTagCompound;
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.b;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.util.random.WeightedEntry.Wrapper;
import net.minecraft.world.entity.EquipmentTable;
import net.minecraft.world.level.MobSpawnerAbstract;
import net.minecraft.world.level.MobSpawnerData;
import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
@@ -30,9 +29,9 @@ import org.bukkit.craftbukkit.entity.CraftEntityType;
import org.bukkit.entity.EntitySnapshot;
import org.bukkit.entity.EntityType;
public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpawner> implements CreatureSpawner {
public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEntity> implements CreatureSpawner {
public CraftCreatureSpawner(World world, TileEntityMobSpawner tileEntity) {
public CraftCreatureSpawner(World world, SpawnerBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -42,12 +41,12 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override
public EntityType getSpawnedType() {
MobSpawnerData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
SpawnData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
if (spawnData == null) {
return null;
}
Optional<EntityTypes<?>> type = EntityTypes.by(spawnData.getEntityToSpawn());
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(spawnData.getEntityToSpawn());
return type.map(CraftEntityType::minecraftToBukkit).orElse(null);
}
@@ -55,7 +54,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
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().nextSpawnData = new MobSpawnerData();
this.getSnapshot().getSpawner().nextSpawnData = new SpawnData();
return;
}
Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "Can't spawn EntityType %s from mob spawners!", entityType);
@@ -66,7 +65,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override
public EntitySnapshot getSpawnedEntity() {
MobSpawnerData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
SpawnData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
if (spawnData == null) {
return null;
}
@@ -76,41 +75,41 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override
public void setSpawnedEntity(EntitySnapshot snapshot) {
setSpawnedEntity(this.getSnapshot().getSpawner(), snapshot, null, null);
CraftCreatureSpawner.setSpawnedEntity(this.getSnapshot().getSpawner(), snapshot, null, null);
}
@Override
public void setSpawnedEntity(SpawnerEntry spawnerEntry) {
Preconditions.checkArgument(spawnerEntry != null, "Entry cannot be null");
setSpawnedEntity(this.getSnapshot().getSpawner(), spawnerEntry.getSnapshot(), spawnerEntry.getSpawnRule(), spawnerEntry.getEquipment());
CraftCreatureSpawner.setSpawnedEntity(this.getSnapshot().getSpawner(), spawnerEntry.getSnapshot(), spawnerEntry.getSpawnRule(), spawnerEntry.getEquipment());
}
public static void setSpawnedEntity(MobSpawnerAbstract spawner, EntitySnapshot snapshot, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
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
if (snapshot == null) {
spawner.nextSpawnData = new MobSpawnerData();
spawner.nextSpawnData = new SpawnData();
return;
}
NBTTagCompound compoundTag = ((CraftEntitySnapshot) snapshot).getData();
CompoundTag compoundTag = ((CraftEntitySnapshot) snapshot).getData();
spawner.nextSpawnData = new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnRule)), getEquipment(equipment));
spawner.nextSpawnData = new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment));
}
@Override
public void addPotentialSpawn(EntitySnapshot snapshot, int weight, SpawnRule spawnRule) {
addPotentialSpawn(this.getSnapshot().getSpawner(), snapshot, weight, spawnRule, null);
CraftCreatureSpawner.addPotentialSpawn(this.getSnapshot().getSpawner(), snapshot, weight, spawnRule, null);
}
public static void addPotentialSpawn(MobSpawnerAbstract spawner, EntitySnapshot snapshot, int weight, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
public static void addPotentialSpawn(BaseSpawner spawner, EntitySnapshot snapshot, int weight, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
Preconditions.checkArgument(snapshot != null, "Snapshot cannot be null");
NBTTagCompound compoundTag = ((CraftEntitySnapshot) snapshot).getData();
CompoundTag compoundTag = ((CraftEntitySnapshot) snapshot).getData();
SimpleWeightedRandomList.a<MobSpawnerData> builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder
spawner.spawnPotentials.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnRule)), getEquipment(equipment)), weight);
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment)), weight);
spawner.spawnPotentials = builder.build();
}
@@ -118,52 +117,52 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
public void addPotentialSpawn(SpawnerEntry spawnerEntry) {
Preconditions.checkArgument(spawnerEntry != null, "Entry cannot be null");
addPotentialSpawn(spawnerEntry.getSnapshot(), spawnerEntry.getSpawnWeight(), spawnerEntry.getSpawnRule());
this.addPotentialSpawn(spawnerEntry.getSnapshot(), spawnerEntry.getSpawnWeight(), spawnerEntry.getSpawnRule());
}
@Override
public void setPotentialSpawns(Collection<SpawnerEntry> entries) {
setPotentialSpawns(this.getSnapshot().getSpawner(), entries);
CraftCreatureSpawner.setPotentialSpawns(this.getSnapshot().getSpawner(), entries);
}
public static void setPotentialSpawns(MobSpawnerAbstract spawner, Collection<SpawnerEntry> entries) {
public static void setPotentialSpawns(BaseSpawner spawner, Collection<SpawnerEntry> entries) {
Preconditions.checkArgument(entries != null, "Entries cannot be null");
SimpleWeightedRandomList.a<MobSpawnerData> builder = SimpleWeightedRandomList.builder();
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder();
for (SpawnerEntry spawnerEntry : entries) {
NBTTagCompound compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData();
builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnerEntry.getSpawnRule())), getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight());
CompoundTag compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData();
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnerEntry.getSpawnRule())), CraftCreatureSpawner.getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight());
}
spawner.spawnPotentials = builder.build();
}
@Override
public List<SpawnerEntry> getPotentialSpawns() {
return getPotentialSpawns(this.getSnapshot().getSpawner());
return CraftCreatureSpawner.getPotentialSpawns(this.getSnapshot().getSpawner());
}
public static List<SpawnerEntry> getPotentialSpawns(MobSpawnerAbstract spawner) {
public static List<SpawnerEntry> getPotentialSpawns(BaseSpawner spawner) {
List<SpawnerEntry> entries = new ArrayList<>();
for (b<MobSpawnerData> entry : spawner.spawnPotentials.unwrap()) { // PAIL rename Wrapper
for (Wrapper<SpawnData> entry : spawner.spawnPotentials.unwrap()) { // PAIL rename Wrapper
CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.data().getEntityToSpawn());
if (snapshot != null) {
SpawnRule rule = entry.data().customSpawnRules().map(CraftCreatureSpawner::fromMinecraftRule).orElse(null);
entries.add(new SpawnerEntry(snapshot, entry.getWeight().asInt(), rule, getEquipment(entry.data().equipment())));
entries.add(new SpawnerEntry(snapshot, entry.getWeight().asInt(), rule, CraftCreatureSpawner.getEquipment(entry.data().equipment())));
}
}
return entries;
}
public static MobSpawnerData.a toMinecraftRule(SpawnRule rule) { // PAIL rename CustomSpawnRules
public static SpawnData.CustomSpawnRules toMinecraftRule(SpawnRule rule) { // PAIL rename CustomSpawnRules
if (rule == null) {
return null;
}
return new MobSpawnerData.a(new InclusiveRange<>(rule.getMinBlockLight(), rule.getMaxBlockLight()), new InclusiveRange<>(rule.getMinSkyLight(), rule.getMaxSkyLight()));
return new SpawnData.CustomSpawnRules(new InclusiveRange<>(rule.getMinBlockLight(), rule.getMaxBlockLight()), new InclusiveRange<>(rule.getMinSkyLight(), rule.getMaxSkyLight()));
}
public static SpawnRule fromMinecraftRule(MobSpawnerData.a rule) {
public static SpawnRule fromMinecraftRule(SpawnData.CustomSpawnRules rule) {
InclusiveRange<Integer> blockLight = rule.blockLightLimit();
InclusiveRange<Integer> skyLight = rule.skyLightLimit();
@@ -172,12 +171,12 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override
public String getCreatureTypeName() {
MobSpawnerData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
SpawnData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
if (spawnData == null) {
return null;
}
Optional<EntityTypes<?>> type = EntityTypes.by(spawnData.getEntityToSpawn());
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(spawnData.getEntityToSpawn());
return type.map(CraftEntityType::minecraftToBukkit).map(CraftEntityType::bukkitToString).orElse(null);
}
@@ -186,10 +185,10 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
// Verify input
EntityType type = CraftEntityType.stringToBukkit(creatureType);
if (type == null) {
setSpawnedType(null);
this.setSpawnedType(null);
return;
}
setSpawnedType(type);
this.setSpawnedType(type);
}
@Override
@@ -209,7 +208,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override
public void setMinSpawnDelay(int spawnDelay) {
Preconditions.checkArgument(spawnDelay <= getMaxSpawnDelay(), "Minimum Spawn Delay must be less than or equal to Maximum Spawn Delay");
Preconditions.checkArgument(spawnDelay <= this.getMaxSpawnDelay(), "Minimum Spawn Delay must be less than or equal to Maximum Spawn Delay");
this.getSnapshot().getSpawner().minSpawnDelay = spawnDelay;
}
@@ -221,7 +220,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override
public void setMaxSpawnDelay(int spawnDelay) {
Preconditions.checkArgument(spawnDelay > 0, "Maximum Spawn Delay must be greater than 0.");
Preconditions.checkArgument(spawnDelay >= getMinSpawnDelay(), "Maximum Spawn Delay must be greater than or equal to Minimum Spawn Delay");
Preconditions.checkArgument(spawnDelay >= this.getMinSpawnDelay(), "Maximum Spawn Delay must be greater than or equal to Minimum Spawn Delay");
this.getSnapshot().getSpawner().maxSpawnDelay = spawnDelay;
}

View File

@@ -1,13 +1,13 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityLightDetector;
import net.minecraft.world.level.block.entity.DaylightDetectorBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.DaylightDetector;
public class CraftDaylightDetector extends CraftBlockEntityState<TileEntityLightDetector> implements DaylightDetector {
public class CraftDaylightDetector extends CraftBlockEntityState<DaylightDetectorBlockEntity> implements DaylightDetector {
public CraftDaylightDetector(World world, TileEntityLightDetector tileEntity) {
public CraftDaylightDetector(World world, DaylightDetectorBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -49,13 +49,13 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
Preconditions.checkArgument(sherd == null || sherd == Material.BRICK || Tag.ITEMS_DECORATED_POT_SHERDS.isTagged(sherd), "sherd is not a valid sherd material: %s", sherd);
Optional<Item> sherdItem = (sherd != null) ? Optional.of(CraftItemType.bukkitToMinecraft(sherd)) : Optional.of(Items.BRICK);
PotDecorations decorations = getSnapshot().getDecorations();
PotDecorations decorations = this.getSnapshot().getDecorations();
switch (face) {
case BACK -> getSnapshot().decorations = new PotDecorations(sherdItem, decorations.left(), decorations.right(), decorations.front());
case LEFT -> getSnapshot().decorations = new PotDecorations(decorations.back(), sherdItem, decorations.right(), decorations.front());
case RIGHT -> getSnapshot().decorations = new PotDecorations(decorations.back(), decorations.left(), sherdItem, decorations.front());
case FRONT -> getSnapshot().decorations = new PotDecorations(decorations.back(), decorations.left(), decorations.right(), sherdItem);
case BACK -> this.getSnapshot().decorations = new PotDecorations(sherdItem, decorations.left(), decorations.right(), decorations.front());
case LEFT -> this.getSnapshot().decorations = new PotDecorations(decorations.back(), sherdItem, decorations.right(), decorations.front());
case RIGHT -> this.getSnapshot().decorations = new PotDecorations(decorations.back(), decorations.left(), sherdItem, decorations.front());
case FRONT -> this.getSnapshot().decorations = new PotDecorations(decorations.back(), decorations.left(), decorations.right(), sherdItem);
default -> throw new IllegalArgumentException("Unexpected value: " + face);
}
}
@@ -64,7 +64,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
public Material getSherd(Side face) {
Preconditions.checkArgument(face != null, "face must not be null");
PotDecorations decorations = getSnapshot().getDecorations();
PotDecorations decorations = this.getSnapshot().getDecorations();
Optional<Item> sherdItem = switch (face) {
case BACK -> decorations.back();
case LEFT -> decorations.left();
@@ -78,7 +78,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
@Override
public Map<Side, Material> getSherds() {
PotDecorations decorations = getSnapshot().getDecorations();
PotDecorations decorations = this.getSnapshot().getDecorations();
Map<Side, Material> sherds = new EnumMap<>(Side.class);
sherds.put(Side.BACK, CraftItemType.minecraftToBukkit(decorations.back().orElse(Items.BRICK)));
@@ -90,7 +90,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
@Override
public List<Material> getShards() {
return getSnapshot().getDecorations().ordered().stream().map(CraftItemType::minecraftToBukkit).collect(Collectors.toUnmodifiableList());
return this.getSnapshot().getDecorations().ordered().stream().map(CraftItemType::minecraftToBukkit).collect(Collectors.toUnmodifiableList());
}
@Override

View File

@@ -1,8 +1,8 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.BlockDispenser;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntityDispenser;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.block.entity.DispenserBlockEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -14,9 +14,9 @@ import org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource;
import org.bukkit.inventory.Inventory;
import org.bukkit.projectiles.BlockProjectileSource;
public class CraftDispenser extends CraftLootable<TileEntityDispenser> implements Dispenser {
public class CraftDispenser extends CraftLootable<DispenserBlockEntity> implements Dispenser {
public CraftDispenser(World world, TileEntityDispenser tileEntity) {
public CraftDispenser(World world, DispenserBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -40,22 +40,22 @@ public class CraftDispenser extends CraftLootable<TileEntityDispenser> implement
@Override
public BlockProjectileSource getBlockProjectileSource() {
Block block = getBlock();
Block block = this.getBlock();
if (block.getType() != Material.DISPENSER) {
return null;
}
return new CraftBlockProjectileSource((TileEntityDispenser) this.getTileEntityFromWorld());
return new CraftBlockProjectileSource((DispenserBlockEntity) this.getTileEntityFromWorld());
}
@Override
public boolean dispense() {
ensureNoWorldGeneration();
Block block = getBlock();
this.ensureNoWorldGeneration();
Block block = this.getBlock();
if (block.getType() == Material.DISPENSER) {
CraftWorld world = (CraftWorld) this.getWorld();
BlockDispenser dispense = (BlockDispenser) Blocks.DISPENSER;
DispenserBlock dispense = (DispenserBlock) Blocks.DISPENSER;
dispense.dispenseFrom(world.getHandle(), this.getHandle(), this.getPosition());
return true;

View File

@@ -1,8 +1,8 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.BlockDropper;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntityDropper;
import net.minecraft.world.level.block.DropperBlock;
import net.minecraft.world.level.block.entity.DropperBlockEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -12,9 +12,9 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
public class CraftDropper extends CraftLootable<TileEntityDropper> implements Dropper {
public class CraftDropper extends CraftLootable<DropperBlockEntity> implements Dropper {
public CraftDropper(World world, TileEntityDropper tileEntity) {
public CraftDropper(World world, DropperBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -38,11 +38,11 @@ public class CraftDropper extends CraftLootable<TileEntityDropper> implements Dr
@Override
public void drop() {
ensureNoWorldGeneration();
Block block = getBlock();
this.ensureNoWorldGeneration();
Block block = this.getBlock();
if (block.getType() == Material.DROPPER) {
CraftWorld world = (CraftWorld) this.getWorld();
BlockDropper drop = (BlockDropper) Blocks.DROPPER;
DropperBlock drop = (DropperBlock) Blocks.DROPPER;
drop.dispenseFrom(world.getHandle(), this.getHandle(), this.getPosition());
}

View File

@@ -1,14 +1,14 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityEnchantTable;
import net.minecraft.world.level.block.entity.EnchantingTableBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.EnchantingTable;
import org.bukkit.craftbukkit.util.CraftChatMessage;
public class CraftEnchantingTable extends CraftBlockEntityState<TileEntityEnchantTable> implements EnchantingTable {
public class CraftEnchantingTable extends CraftBlockEntityState<EnchantingTableBlockEntity> implements EnchantingTable {
public CraftEnchantingTable(World world, TileEntityEnchantTable tileEntity) {
public CraftEnchantingTable(World world, EnchantingTableBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -18,7 +18,7 @@ public class CraftEnchantingTable extends CraftBlockEntityState<TileEntityEnchan
@Override
public String getCustomName() {
TileEntityEnchantTable enchant = this.getSnapshot();
EnchantingTableBlockEntity enchant = this.getSnapshot();
return enchant.hasCustomName() ? CraftChatMessage.fromComponent(enchant.getCustomName()) : null;
}
@@ -28,7 +28,7 @@ public class CraftEnchantingTable extends CraftBlockEntityState<TileEntityEnchan
}
@Override
public void applyTo(TileEntityEnchantTable enchantingTable) {
public void applyTo(EnchantingTableBlockEntity enchantingTable) {
super.applyTo(enchantingTable);
if (!this.getSnapshot().hasCustomName()) {

View File

@@ -1,16 +1,16 @@
package org.bukkit.craftbukkit.block;
import java.util.Objects;
import net.minecraft.core.BlockPosition;
import net.minecraft.world.level.block.entity.TileEntityEndGateway;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.EndGateway;
import org.bukkit.craftbukkit.util.CraftLocation;
public class CraftEndGateway extends CraftBlockEntityState<TileEntityEndGateway> implements EndGateway {
public class CraftEndGateway extends CraftBlockEntityState<TheEndGatewayBlockEntity> implements EndGateway {
public CraftEndGateway(World world, TileEntityEndGateway tileEntity) {
public CraftEndGateway(World world, TheEndGatewayBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -20,7 +20,7 @@ public class CraftEndGateway extends CraftBlockEntityState<TileEntityEndGateway>
@Override
public Location getExitLocation() {
BlockPosition pos = this.getSnapshot().exitPortal;
BlockPos pos = this.getSnapshot().exitPortal;
return pos == null ? null : CraftLocation.toBukkit(pos, this.isPlaced() ? this.getWorld() : null);
}
@@ -56,7 +56,7 @@ public class CraftEndGateway extends CraftBlockEntityState<TileEntityEndGateway>
}
@Override
public void applyTo(TileEntityEndGateway endGateway) {
public void applyTo(TheEndGatewayBlockEntity endGateway) {
super.applyTo(endGateway);
if (this.getSnapshot().exitPortal == null) {

View File

@@ -1,12 +1,12 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityEnderPortal;
import net.minecraft.world.level.block.entity.TheEndPortalBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
public class CraftEndPortal extends CraftBlockEntityState<TileEntityEnderPortal> {
public class CraftEndPortal extends CraftBlockEntityState<TheEndPortalBlockEntity> {
public CraftEndPortal(World world, TileEntityEnderPortal tileEntity) {
public CraftEndPortal(World world, TheEndPortalBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -1,14 +1,14 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityEnderChest;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.EnderChest;
public class CraftEnderChest extends CraftBlockEntityState<TileEntityEnderChest> implements EnderChest {
public class CraftEnderChest extends CraftBlockEntityState<EnderChestBlockEntity> implements EnderChest {
public CraftEnderChest(World world, TileEntityEnderChest tileEntity) {
public CraftEnderChest(World world, EnderChestBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -18,28 +18,28 @@ public class CraftEnderChest extends CraftBlockEntityState<TileEntityEnderChest>
@Override
public void open() {
requirePlaced();
if (!getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) {
IBlockData block = getTileEntity().getBlockState();
int openCount = getTileEntity().openersCounter.getOpenerCount();
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();
getTileEntity().openersCounter.onAPIOpen((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block);
getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, openCount + 1);
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);
}
getTileEntity().openersCounter.opened = true;
this.getTileEntity().openersCounter.opened = true;
}
@Override
public void close() {
requirePlaced();
if (getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) {
IBlockData block = getTileEntity().getBlockState();
int openCount = getTileEntity().openersCounter.getOpenerCount();
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();
getTileEntity().openersCounter.onAPIClose((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block);
getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, 0);
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);
}
getTileEntity().openersCounter.opened = false;
this.getTileEntity().openersCounter.opened = false;
}
@Override

View File

@@ -2,8 +2,8 @@ package org.bukkit.craftbukkit.block;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import net.minecraft.world.level.block.BlockFurnace;
import net.minecraft.world.level.block.entity.TileEntityFurnace;
import net.minecraft.world.level.block.AbstractFurnaceBlock;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -14,7 +14,7 @@ import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Recipe;
public abstract class CraftFurnace<T extends TileEntityFurnace> extends CraftContainer<T> implements Furnace {
public abstract class CraftFurnace<T extends AbstractFurnaceBlockEntity> extends CraftContainer<T> implements Furnace {
public CraftFurnace(World world, T tileEntity) {
super(world, tileEntity);
@@ -47,7 +47,7 @@ public abstract class CraftFurnace<T extends TileEntityFurnace> extends CraftCon
public void setBurnTime(short burnTime) {
this.getSnapshot().litTimeRemaining = burnTime;
// SPIGOT-844: Allow lighting and relighting using this API
this.data = this.data.setValue(BlockFurnace.LIT, burnTime > 0);
this.data = this.data.setValue(AbstractFurnaceBlock.LIT, burnTime > 0);
}
@Override

View File

@@ -1,12 +1,12 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityFurnaceFurnace;
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
public class CraftFurnaceFurnace extends CraftFurnace<TileEntityFurnaceFurnace> {
public class CraftFurnaceFurnace extends CraftFurnace<FurnaceBlockEntity> {
public CraftFurnaceFurnace(World world, TileEntityFurnaceFurnace tileEntity) {
public CraftFurnaceFurnace(World world, FurnaceBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -1,15 +1,15 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityHopper;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Hopper;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
public class CraftHopper extends CraftLootable<TileEntityHopper> implements Hopper {
public class CraftHopper extends CraftLootable<HopperBlockEntity> implements Hopper {
public CraftHopper(World world, TileEntityHopper tileEntity) {
public CraftHopper(World world, HopperBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -1,13 +1,13 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityJigsaw;
import net.minecraft.world.level.block.entity.JigsawBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Jigsaw;
public class CraftJigsaw extends CraftBlockEntityState<TileEntityJigsaw> implements Jigsaw {
public class CraftJigsaw extends CraftBlockEntityState<JigsawBlockEntity> implements Jigsaw {
public CraftJigsaw(World world, TileEntityJigsaw tileEntity) {
public CraftJigsaw(World world, JigsawBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -1,9 +1,9 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.BlockJukeBox;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityJukeBox;
import net.minecraft.world.level.block.JukeboxBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -13,9 +13,9 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.inventory.JukeboxInventory;
public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> implements Jukebox {
public class CraftJukebox extends CraftBlockEntityState<JukeboxBlockEntity> implements Jukebox {
public CraftJukebox(World world, TileEntityJukeBox tileEntity) {
public CraftJukebox(World world, JukeboxBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -42,10 +42,10 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
getWorldHandle().setBlock(this.getPosition(), data, 3);
this.getWorldHandle().setBlock(this.getPosition(), this.data, 3);
TileEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof TileEntityJukeBox jukebox) {
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof JukeboxBlockEntity jukebox) {
jukebox.setTheItem(jukebox.getTheItem());
}
}
@@ -55,7 +55,7 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
@Override
public Material getPlaying() {
return getRecord().getType();
return this.getRecord().getType();
}
@Override
@@ -64,12 +64,12 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
record = Material.AIR;
}
setRecord(new org.bukkit.inventory.ItemStack(record));
this.setRecord(new org.bukkit.inventory.ItemStack(record));
}
@Override
public boolean hasRecord() {
return getHandle().getValue(BlockJukeBox.HAS_RECORD) && !getPlaying().isAir();
return this.getHandle().getValue(JukeboxBlock.HAS_RECORD) && !this.getPlaying().isAir();
}
@Override
@@ -82,31 +82,31 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
public void setRecord(org.bukkit.inventory.ItemStack record) {
ItemStack nms = CraftItemStack.asNMSCopy(record);
TileEntityJukeBox snapshot = this.getSnapshot();
JukeboxBlockEntity snapshot = this.getSnapshot();
snapshot.setSongItemWithoutPlaying(nms, snapshot.getSongPlayer().getTicksSinceSongStarted());
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, !nms.isEmpty());
this.data = this.data.setValue(JukeboxBlock.HAS_RECORD, !nms.isEmpty());
}
@Override
public boolean isPlaying() {
requirePlaced();
this.requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
return tileEntity instanceof TileEntityJukeBox jukebox && jukebox.getSongPlayer().isPlaying();
BlockEntity tileEntity = this.getTileEntityFromWorld();
return tileEntity instanceof JukeboxBlockEntity jukebox && jukebox.getSongPlayer().isPlaying();
}
@Override
public boolean startPlaying() {
requirePlaced();
this.requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityJukeBox jukebox)) {
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof JukeboxBlockEntity jukebox)) {
return false;
}
ItemStack record = jukebox.getTheItem();
if (record.isEmpty() || isPlaying()) {
if (record.isEmpty() || this.isPlaying()) {
return false;
}
@@ -116,10 +116,10 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
@Override
public void stopPlaying() {
requirePlaced();
this.requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityJukeBox jukebox)) {
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof JukeboxBlockEntity jukebox)) {
return;
}
@@ -128,12 +128,12 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
@Override
public boolean eject() {
ensureNoWorldGeneration();
this.ensureNoWorldGeneration();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityJukeBox)) return false;
BlockEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof JukeboxBlockEntity)) return false;
TileEntityJukeBox jukebox = (TileEntityJukeBox) tileEntity;
JukeboxBlockEntity jukebox = (JukeboxBlockEntity) tileEntity;
boolean result = !jukebox.getTheItem().isEmpty();
jukebox.popOutTheItem();
return result;

View File

@@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.BlockLectern;
import net.minecraft.world.level.block.entity.TileEntityLectern;
import net.minecraft.world.level.block.LecternBlock;
import net.minecraft.world.level.block.entity.LecternBlockEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -9,9 +9,9 @@ import org.bukkit.block.Lectern;
import org.bukkit.craftbukkit.inventory.CraftInventoryLectern;
import org.bukkit.inventory.Inventory;
public class CraftLectern extends CraftBlockEntityState<TileEntityLectern> implements Lectern {
public class CraftLectern extends CraftBlockEntityState<LecternBlockEntity> implements Lectern {
public CraftLectern(World world, TileEntityLectern tileEntity) {
public CraftLectern(World world, LecternBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -21,12 +21,12 @@ public class CraftLectern extends CraftBlockEntityState<TileEntityLectern> imple
@Override
public int getPage() {
return getSnapshot().getPage();
return this.getSnapshot().getPage();
}
@Override
public void setPage(int page) {
getSnapshot().setPage(page);
this.getSnapshot().setPage(page);
}
@Override
@@ -47,8 +47,8 @@ public class CraftLectern extends CraftBlockEntityState<TileEntityLectern> imple
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result && this.getType() == Material.LECTERN && getWorldHandle() instanceof net.minecraft.world.level.World) {
BlockLectern.signalPageChange(this.world.getHandle(), this.getPosition(), this.getHandle());
if (result && this.getType() == Material.LECTERN && this.getWorldHandle() instanceof net.minecraft.world.level.Level) {
LecternBlock.signalPageChange(this.world.getHandle(), this.getPosition(), this.getHandle());
}
return result;

View File

@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntityLootable;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import org.bukkit.Location;
import org.bukkit.Nameable;
import org.bukkit.World;
@@ -8,7 +8,7 @@ import org.bukkit.craftbukkit.CraftLootTable;
import org.bukkit.loot.LootTable;
import org.bukkit.loot.Lootable;
public abstract class CraftLootable<T extends TileEntityLootable> extends CraftContainer<T> implements Nameable, Lootable {
public abstract class CraftLootable<T extends RandomizableContainerBlockEntity> extends CraftContainer<T> implements Nameable, Lootable {
public CraftLootable(World world, T tileEntity) {
super(world, tileEntity);
@@ -29,26 +29,26 @@ public abstract class CraftLootable<T extends TileEntityLootable> extends CraftC
@Override
public LootTable getLootTable() {
return CraftLootTable.minecraftToBukkit(getSnapshot().lootTable);
return CraftLootTable.minecraftToBukkit(this.getSnapshot().lootTable);
}
@Override
public void setLootTable(LootTable table) {
setLootTable(table, getSeed());
this.setLootTable(table, this.getSeed());
}
@Override
public long getSeed() {
return getSnapshot().lootTableSeed;
return this.getSnapshot().lootTableSeed;
}
@Override
public void setSeed(long seed) {
setLootTable(getLootTable(), seed);
this.setLootTable(this.getLootTable(), seed);
}
private void setLootTable(LootTable table, long seed) {
getSnapshot().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed);
public void setLootTable(LootTable table, long seed) {
this.getSnapshot().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed);
}
@Override

View File

@@ -1,12 +1,12 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.piston.TileEntityPiston;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
public class CraftMovingPiston extends CraftBlockEntityState<TileEntityPiston> {
public class CraftMovingPiston extends CraftBlockEntityState<PistonMovingBlockEntity> {
public CraftMovingPiston(World world, TileEntityPiston tileEntity) {
public CraftMovingPiston(World world, PistonMovingBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.SculkCatalystBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
@@ -22,11 +22,11 @@ public class CraftSculkCatalyst extends CraftBlockEntityState<SculkCatalystBlock
public void bloom(Block block, int charge) {
Preconditions.checkArgument(block != null, "block cannot be null");
Preconditions.checkArgument(charge > 0, "charge must be positive");
requirePlaced();
this.requirePlaced();
// bloom() is for visual blooming effect, cursors are what changes the blocks.
getTileEntity().getListener().bloom(world.getHandle(), getPosition(), getHandle(), world.getHandle().getRandom());
getTileEntity().getListener().getSculkSpreader().addCursors(new BlockPosition(block.getX(), block.getY(), block.getZ()), charge);
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);
}
@Override

View File

@@ -18,13 +18,13 @@ public class CraftSculkSensor<T extends SculkSensorBlockEntity> extends CraftBlo
@Override
public int getLastVibrationFrequency() {
return getSnapshot().getLastVibrationFrequency();
return this.getSnapshot().getLastVibrationFrequency();
}
@Override
public void setLastVibrationFrequency(int lastVibrationFrequency) {
Preconditions.checkArgument(0 <= lastVibrationFrequency && lastVibrationFrequency <= 15, "Vibration frequency must be between 0-15");
getSnapshot().lastVibrationFrequency = lastVibrationFrequency;
this.getSnapshot().lastVibrationFrequency = lastVibrationFrequency;
}
@Override

View File

@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.entity.SculkShriekerBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
@@ -20,20 +20,20 @@ public class CraftSculkShrieker extends CraftBlockEntityState<SculkShriekerBlock
@Override
public int getWarningLevel() {
return getSnapshot().warningLevel;
return this.getSnapshot().warningLevel;
}
@Override
public void setWarningLevel(int level) {
getSnapshot().warningLevel = level;
this.getSnapshot().warningLevel = level;
}
@Override
public void tryShriek(Player player) {
requirePlaced();
this.requirePlaced();
EntityPlayer entityPlayer = (player == null) ? null : ((CraftPlayer) player).getHandle();
getTileEntity().tryShriek(world.getHandle(), entityPlayer);
ServerPlayer entityPlayer = (player == null) ? null : ((CraftPlayer) player).getHandle();
this.getTileEntity().tryShriek(this.world.getHandle(), entityPlayer);
}
@Override

View File

@@ -1,10 +1,9 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.sounds.SoundCategory;
import net.minecraft.sounds.SoundEffects;
import net.minecraft.world.item.EnumColor;
import net.minecraft.world.level.block.BlockShulkerBox;
import net.minecraft.world.level.block.entity.TileEntityShulkerBox;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.World;
@@ -12,9 +11,9 @@ import org.bukkit.block.ShulkerBox;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
public class CraftShulkerBox extends CraftLootable<TileEntityShulkerBox> implements ShulkerBox {
public class CraftShulkerBox extends CraftLootable<ShulkerBoxBlockEntity> implements ShulkerBox {
public CraftShulkerBox(World world, TileEntityShulkerBox tileEntity) {
public CraftShulkerBox(World world, ShulkerBoxBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -38,31 +37,31 @@ public class CraftShulkerBox extends CraftLootable<TileEntityShulkerBox> impleme
@Override
public DyeColor getColor() {
EnumColor color = ((BlockShulkerBox) CraftBlockType.bukkitToMinecraft(this.getType())).color;
net.minecraft.world.item.DyeColor color = ((ShulkerBoxBlock) CraftBlockType.bukkitToMinecraft(this.getType())).color;
return (color == null) ? null : DyeColor.getByWoolData((byte) color.getId());
}
@Override
public void open() {
requirePlaced();
if (!getTileEntity().opened && getWorldHandle() instanceof net.minecraft.world.level.World) {
net.minecraft.world.level.World world = getTileEntity().getLevel();
world.blockEvent(getPosition(), getTileEntity().getBlockState().getBlock(), 1, 1);
world.playSound(null, getPosition(), SoundEffects.SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
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);
world.playSound(null, this.getPosition(), SoundEvents.SHULKER_BOX_OPEN, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
}
getTileEntity().opened = true;
this.getTileEntity().opened = true;
}
@Override
public void close() {
requirePlaced();
if (getTileEntity().opened && getWorldHandle() instanceof net.minecraft.world.level.World) {
net.minecraft.world.level.World world = getTileEntity().getLevel();
world.blockEvent(getPosition(), getTileEntity().getBlockState().getBlock(), 1, 0);
world.playSound(null, getPosition(), SoundEffects.SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
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);
world.playSound(null, this.getPosition(), SoundEvents.SHULKER_BOX_OPEN, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
}
getTileEntity().opened = false;
this.getTileEntity().opened = false;
}
@Override

View File

@@ -2,8 +2,8 @@ package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import java.util.UUID;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.world.level.block.entity.TileEntitySign;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
@@ -19,7 +19,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerSignOpenEvent;
import org.jetbrains.annotations.NotNull;
public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T> implements Sign {
public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<T> implements Sign {
private final CraftSignSide front;
private final CraftSignSide back;
@@ -38,22 +38,22 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
@Override
public String[] getLines() {
return front.getLines();
return this.front.getLines();
}
@Override
public String getLine(int index) throws IndexOutOfBoundsException {
return front.getLine(index);
return this.front.getLine(index);
}
@Override
public void setLine(int index, String line) throws IndexOutOfBoundsException {
front.setLine(index, line);
this.front.setLine(index, line);
}
@Override
public boolean isEditable() {
return !isWaxed();
return !this.isWaxed();
}
@Override
@@ -63,22 +63,22 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
@Override
public boolean isWaxed() {
return getSnapshot().isWaxed();
return this.getSnapshot().isWaxed();
}
@Override
public void setWaxed(boolean waxed) {
getSnapshot().setWaxed(waxed);
this.getSnapshot().setWaxed(waxed);
}
@Override
public boolean isGlowingText() {
return front.isGlowingText();
return this.front.isGlowingText();
}
@Override
public void setGlowingText(boolean glowing) {
front.setGlowingText(glowing);
this.front.setGlowingText(glowing);
}
@NotNull
@@ -88,9 +88,9 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
switch (side) {
case FRONT:
return front;
return this.front;
case BACK:
return back;
return this.back;
default:
throw new IllegalArgumentException();
}
@@ -98,39 +98,39 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
@Override
public SignSide getTargetSide(Player player) {
ensureNoWorldGeneration();
this.ensureNoWorldGeneration();
Preconditions.checkArgument(player != null, "player cannot be null");
if (getSnapshot().isFacingFrontText(((CraftPlayer) player).getHandle())) {
return front;
if (this.getSnapshot().isFacingFrontText(((CraftPlayer) player).getHandle())) {
return this.front;
}
return back;
return this.back;
}
@Override
public Player getAllowedEditor() {
ensureNoWorldGeneration();
this.ensureNoWorldGeneration();
// getPlayerWhoMayEdit is always null for the snapshot, so we use the wrapped TileEntity
UUID id = getTileEntity().getPlayerWhoMayEdit();
UUID id = this.getTileEntity().getPlayerWhoMayEdit();
return (id == null) ? null : Bukkit.getPlayer(id);
}
@Override
public DyeColor getColor() {
return front.getColor();
return this.front.getColor();
}
@Override
public void setColor(DyeColor color) {
front.setColor(color);
this.front.setColor(color);
}
@Override
public void applyTo(T sign) {
getSnapshot().setText(front.applyLegacyStringToSignSide(), true);
getSnapshot().setText(back.applyLegacyStringToSignSide(), false);
this.getSnapshot().setText(this.front.applyLegacyStringToSignSide(), true);
this.getSnapshot().setText(this.back.applyLegacyStringToSignSide(), false);
super.applyTo(sign);
}
@@ -155,35 +155,35 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
return;
}
TileEntitySign handle = ((CraftSign<?>) sign).getTileEntity();
SignBlockEntity handle = ((CraftSign<?>) sign).getTileEntity();
handle.setAllowedPlayerEditor(player.getUniqueId());
((CraftPlayer) player).getHandle().openTextEdit(handle, Side.FRONT == side);
}
public static IChatBaseComponent[] sanitizeLines(String[] lines) {
IChatBaseComponent[] components = new IChatBaseComponent[4];
public static Component[] sanitizeLines(String[] lines) {
Component[] components = new Component[4];
for (int i = 0; i < 4; i++) {
if (i < lines.length && lines[i] != null) {
components[i] = CraftChatMessage.fromString(lines[i])[0];
} else {
components[i] = IChatBaseComponent.empty();
components[i] = Component.empty();
}
}
return components;
}
public static String[] revertComponents(IChatBaseComponent[] components) {
public static String[] revertComponents(Component[] components) {
String[] lines = new String[components.length];
for (int i = 0; i < lines.length; i++) {
lines[i] = revertComponent(components[i]);
lines[i] = CraftSign.revertComponent(components[i]);
}
return lines;
}
private static String revertComponent(IChatBaseComponent component) {
private static String revertComponent(Component component) {
return CraftChatMessage.fromComponent(component);
}
}

View File

@@ -2,11 +2,11 @@ package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import net.minecraft.SystemUtils;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.Util;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.component.ResolvableProfile;
import net.minecraft.world.level.block.entity.TileEntitySkull;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
@@ -24,12 +24,12 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.profile.PlayerProfile;
import org.jetbrains.annotations.Nullable;
public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implements Skull {
public class CraftSkull extends CraftBlockEntityState<SkullBlockEntity> implements Skull {
private static final int MAX_OWNER_LENGTH = 16;
private ResolvableProfile profile;
public CraftSkull(World world, TileEntitySkull tileEntity) {
public CraftSkull(World world, SkullBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -38,28 +38,28 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
}
@Override
public void load(TileEntitySkull skull) {
public void load(SkullBlockEntity skull) {
super.load(skull);
ResolvableProfile owner = skull.getOwnerProfile();
if (owner != null) {
profile = owner;
this.profile = owner;
}
}
@Override
public boolean hasOwner() {
return profile != null;
return this.profile != null;
}
@Override
public String getOwner() {
return hasOwner() ? profile.name().orElse(null) : null;
return this.hasOwner() ? this.profile.name().orElse(null) : null;
}
@Override
public boolean setOwner(String name) {
if (name == null || name.length() > MAX_OWNER_LENGTH) {
if (name == null || name.length() > CraftSkull.MAX_OWNER_LENGTH) {
return false;
}
@@ -74,13 +74,13 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
@Override
public OfflinePlayer getOwningPlayer() {
if (hasOwner()) {
if (profile.id().filter(u -> !u.equals(SystemUtils.NIL_UUID)).isPresent()) {
return Bukkit.getOfflinePlayer(profile.id().get());
if (this.hasOwner()) {
if (this.profile.id().filter(u -> !u.equals(Util.NIL_UUID)).isPresent()) {
return Bukkit.getOfflinePlayer(this.profile.id().get());
}
if (profile.name().filter(s -> !s.isEmpty()).isPresent()) {
return Bukkit.getOfflinePlayer(profile.name().get());
if (this.profile.name().filter(s -> !s.isEmpty()).isPresent()) {
return Bukkit.getOfflinePlayer(this.profile.name().get());
}
}
@@ -100,11 +100,11 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
@Override
public PlayerProfile getOwnerProfile() {
if (!hasOwner()) {
if (!this.hasOwner()) {
return null;
}
return new CraftPlayerProfile(profile);
return new CraftPlayerProfile(this.profile);
}
@Override
@@ -118,7 +118,7 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
@Override
public NamespacedKey getNoteBlockSound() {
MinecraftKey key = getSnapshot().getNoteBlockSound();
ResourceLocation key = this.getSnapshot().getNoteBlockSound();
return (key != null) ? CraftNamespacedKey.fromMinecraft(key) : null;
}
@@ -133,24 +133,24 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
@Override
public BlockFace getRotation() {
BlockData blockData = getBlockData();
BlockData blockData = this.getBlockData();
return (blockData instanceof Rotatable rotatable) ? rotatable.getRotation() : ((Directional) blockData).getFacing();
}
@Override
public void setRotation(BlockFace rotation) {
BlockData blockData = getBlockData();
BlockData blockData = this.getBlockData();
if (blockData instanceof Rotatable) {
((Rotatable) blockData).setRotation(rotation);
} else {
((Directional) blockData).setFacing(rotation);
}
setBlockData(blockData);
this.setBlockData(blockData);
}
@Override
public SkullType getSkullType() {
switch (getType()) {
switch (this.getType()) {
case SKELETON_SKULL:
case SKELETON_WALL_SKULL:
return SkullType.SKELETON;
@@ -173,7 +173,7 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
case DRAGON_WALL_HEAD:
return SkullType.DRAGON;
default:
throw new IllegalArgumentException("Unknown SkullType for " + getType());
throw new IllegalArgumentException("Unknown SkullType for " + this.getType());
}
}
@@ -183,11 +183,11 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
}
@Override
public void applyTo(TileEntitySkull skull) {
public void applyTo(SkullBlockEntity skull) {
super.applyTo(skull);
if (getSkullType() == SkullType.PLAYER) {
skull.setOwner(hasOwner() ? profile : null);
if (this.getSkullType() == SkullType.PLAYER) {
skull.setOwner(this.hasOwner() ? this.profile : null);
}
}

View File

@@ -1,13 +1,13 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.world.level.block.entity.TileEntitySmoker;
import net.minecraft.world.level.block.entity.SmokerBlockEntity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Smoker;
public class CraftSmoker extends CraftFurnace<TileEntitySmoker> implements Smoker {
public class CraftSmoker extends CraftFurnace<SmokerBlockEntity> implements Smoker {
public CraftSmoker(World world, TileEntitySmoker tileEntity) {
public CraftSmoker(World world, SmokerBlockEntity tileEntity) {
super(world, tileEntity);
}

View File

@@ -1,10 +1,9 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.world.level.block.EnumBlockMirror;
import net.minecraft.world.level.block.EnumBlockRotation;
import net.minecraft.world.level.block.entity.TileEntityStructure;
import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.StructureBlockEntity;
import net.minecraft.world.level.block.state.properties.StructureMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Structure;
@@ -16,11 +15,11 @@ import org.bukkit.craftbukkit.util.CraftBlockVector;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.BlockVector;
public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructure> implements Structure {
public class CraftStructureBlock extends CraftBlockEntityState<StructureBlockEntity> implements Structure {
private static final int MAX_SIZE = 48;
public CraftStructureBlock(World world, TileEntityStructure tileEntity) {
public CraftStructureBlock(World world, StructureBlockEntity tileEntity) {
super(world, tileEntity);
}
@@ -30,170 +29,170 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
@Override
public String getStructureName() {
return getSnapshot().getStructureName();
return this.getSnapshot().getStructureName();
}
@Override
public void setStructureName(String name) {
Preconditions.checkArgument(name != null, "Structure name cannot be null");
getSnapshot().setStructureName(name);
this.getSnapshot().setStructureName(name);
}
@Override
public String getAuthor() {
return getSnapshot().author;
return this.getSnapshot().author;
}
@Override
public void setAuthor(String author) {
Preconditions.checkArgument(author != null, "Author name cannot be null");
Preconditions.checkArgument(!author.isEmpty(), "Author name cannot be empty");
getSnapshot().author = author;
this.getSnapshot().author = author;
}
@Override
public void setAuthor(LivingEntity entity) {
Preconditions.checkArgument(entity != null, "Structure Block author entity cannot be null");
getSnapshot().createdBy(((CraftLivingEntity) entity).getHandle());
this.getSnapshot().createdBy(((CraftLivingEntity) entity).getHandle());
}
@Override
public BlockVector getRelativePosition() {
return CraftBlockVector.toBukkit(getSnapshot().structurePos);
return CraftBlockVector.toBukkit(this.getSnapshot().structurePos);
}
@Override
public void setRelativePosition(BlockVector vector) {
Preconditions.checkArgument(isBetween(vector.getBlockX(), -MAX_SIZE, MAX_SIZE), "Structure Size (X) must be between -%s and %s but got %s", MAX_SIZE, MAX_SIZE, vector.getBlockX());
Preconditions.checkArgument(isBetween(vector.getBlockY(), -MAX_SIZE, MAX_SIZE), "Structure Size (Y) must be between -%s and %s but got %s", MAX_SIZE, MAX_SIZE, vector.getBlockY());
Preconditions.checkArgument(isBetween(vector.getBlockZ(), -MAX_SIZE, MAX_SIZE), "Structure Size (Z) must be between -%s and %s but got %s", MAX_SIZE, MAX_SIZE, vector.getBlockZ());
getSnapshot().structurePos = CraftBlockVector.toBlockPosition(vector);
Preconditions.checkArgument(CraftStructureBlock.isBetween(vector.getBlockX(), -CraftStructureBlock.MAX_SIZE, CraftStructureBlock.MAX_SIZE), "Structure Size (X) must be between -%s and %s but got %s", CraftStructureBlock.MAX_SIZE, CraftStructureBlock.MAX_SIZE, vector.getBlockX());
Preconditions.checkArgument(CraftStructureBlock.isBetween(vector.getBlockY(), -CraftStructureBlock.MAX_SIZE, CraftStructureBlock.MAX_SIZE), "Structure Size (Y) must be between -%s and %s but got %s", CraftStructureBlock.MAX_SIZE, CraftStructureBlock.MAX_SIZE, vector.getBlockY());
Preconditions.checkArgument(CraftStructureBlock.isBetween(vector.getBlockZ(), -CraftStructureBlock.MAX_SIZE, CraftStructureBlock.MAX_SIZE), "Structure Size (Z) must be between -%s and %s but got %s", CraftStructureBlock.MAX_SIZE, CraftStructureBlock.MAX_SIZE, vector.getBlockZ());
this.getSnapshot().structurePos = CraftBlockVector.toBlockPosition(vector);
}
@Override
public BlockVector getStructureSize() {
return CraftBlockVector.toBukkit(getSnapshot().structureSize);
return CraftBlockVector.toBukkit(this.getSnapshot().structureSize);
}
@Override
public void setStructureSize(BlockVector vector) {
Preconditions.checkArgument(isBetween(vector.getBlockX(), 0, MAX_SIZE), "Structure Size (X) must be between %s and %s but got %s", 0, MAX_SIZE, vector.getBlockX());
Preconditions.checkArgument(isBetween(vector.getBlockY(), 0, MAX_SIZE), "Structure Size (Y) must be between %s and %s but got %s", 0, MAX_SIZE, vector.getBlockY());
Preconditions.checkArgument(isBetween(vector.getBlockZ(), 0, MAX_SIZE), "Structure Size (Z) must be between %s and %s but got %s", 0, MAX_SIZE, vector.getBlockZ());
getSnapshot().structureSize = CraftBlockVector.toBlockPosition(vector);
Preconditions.checkArgument(CraftStructureBlock.isBetween(vector.getBlockX(), 0, CraftStructureBlock.MAX_SIZE), "Structure Size (X) must be between %s and %s but got %s", 0, CraftStructureBlock.MAX_SIZE, vector.getBlockX());
Preconditions.checkArgument(CraftStructureBlock.isBetween(vector.getBlockY(), 0, CraftStructureBlock.MAX_SIZE), "Structure Size (Y) must be between %s and %s but got %s", 0, CraftStructureBlock.MAX_SIZE, vector.getBlockY());
Preconditions.checkArgument(CraftStructureBlock.isBetween(vector.getBlockZ(), 0, CraftStructureBlock.MAX_SIZE), "Structure Size (Z) must be between %s and %s but got %s", 0, CraftStructureBlock.MAX_SIZE, vector.getBlockZ());
this.getSnapshot().structureSize = CraftBlockVector.toBlockPosition(vector);
}
@Override
public void setMirror(Mirror mirror) {
Preconditions.checkArgument(mirror != null, "Mirror cannot be null");
getSnapshot().mirror = EnumBlockMirror.valueOf(mirror.name());
this.getSnapshot().mirror = net.minecraft.world.level.block.Mirror.valueOf(mirror.name());
}
@Override
public Mirror getMirror() {
return Mirror.valueOf(getSnapshot().mirror.name());
return Mirror.valueOf(this.getSnapshot().mirror.name());
}
@Override
public void setRotation(StructureRotation rotation) {
Preconditions.checkArgument(rotation != null, "StructureRotation cannot be null");
getSnapshot().rotation = EnumBlockRotation.valueOf(rotation.name());
this.getSnapshot().rotation = Rotation.valueOf(rotation.name());
}
@Override
public StructureRotation getRotation() {
return StructureRotation.valueOf(getSnapshot().rotation.name());
return StructureRotation.valueOf(this.getSnapshot().rotation.name());
}
@Override
public void setUsageMode(UsageMode mode) {
Preconditions.checkArgument(mode != null, "UsageMode cannot be null");
getSnapshot().mode = BlockPropertyStructureMode.valueOf(mode.name());
this.getSnapshot().mode = StructureMode.valueOf(mode.name());
}
@Override
public UsageMode getUsageMode() {
return UsageMode.valueOf(getSnapshot().getMode().name());
return UsageMode.valueOf(this.getSnapshot().getMode().name());
}
@Override
public void setIgnoreEntities(boolean flag) {
getSnapshot().ignoreEntities = flag;
this.getSnapshot().ignoreEntities = flag;
}
@Override
public boolean isIgnoreEntities() {
return getSnapshot().ignoreEntities;
return this.getSnapshot().ignoreEntities;
}
@Override
public void setShowAir(boolean showAir) {
getSnapshot().showAir = showAir;
this.getSnapshot().showAir = showAir;
}
@Override
public boolean isShowAir() {
return getSnapshot().showAir;
return this.getSnapshot().showAir;
}
@Override
public void setBoundingBoxVisible(boolean showBoundingBox) {
getSnapshot().showBoundingBox = showBoundingBox;
this.getSnapshot().showBoundingBox = showBoundingBox;
}
@Override
public boolean isBoundingBoxVisible() {
return getSnapshot().showBoundingBox;
return this.getSnapshot().showBoundingBox;
}
@Override
public void setIntegrity(float integrity) {
Preconditions.checkArgument(isBetween(integrity, 0.0f, 1.0f), "Integrity must be between 0.0f and 1.0f but got %s", integrity);
getSnapshot().integrity = integrity;
Preconditions.checkArgument(CraftStructureBlock.isBetween(integrity, 0.0f, 1.0f), "Integrity must be between 0.0f and 1.0f but got %s", integrity);
this.getSnapshot().integrity = integrity;
}
@Override
public float getIntegrity() {
return getSnapshot().integrity;
return this.getSnapshot().integrity;
}
@Override
public void setSeed(long seed) {
getSnapshot().seed = seed;
this.getSnapshot().seed = seed;
}
@Override
public long getSeed() {
return getSnapshot().seed;
return this.getSnapshot().seed;
}
@Override
public void setMetadata(String metadata) {
Preconditions.checkArgument(metadata != null, "Structure metadata cannot be null");
if (getUsageMode() == UsageMode.DATA) {
getSnapshot().metaData = metadata;
if (this.getUsageMode() == UsageMode.DATA) {
this.getSnapshot().metaData = metadata;
}
}
@Override
public String getMetadata() {
return getSnapshot().metaData;
return this.getSnapshot().metaData;
}
@Override
protected void applyTo(TileEntityStructure tileEntity) {
protected void applyTo(StructureBlockEntity tileEntity) {
super.applyTo(tileEntity);
net.minecraft.world.level.GeneratorAccess access = getWorldHandle();
net.minecraft.world.level.LevelAccessor access = this.getWorldHandle();
// Ensure block type is correct
if (access instanceof net.minecraft.world.level.World) {
if (access instanceof net.minecraft.world.level.Level) {
tileEntity.setMode(tileEntity.getMode());
} else if (access != null) {
// Custom handle during world generation
// From TileEntityStructure#setUsageMode(BlockPropertyStructureMode)
net.minecraft.world.level.block.state.IBlockData data = access.getBlockState(this.getPosition());
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.BlockStructure.MODE, tileEntity.getMode()), 2);
access.setBlock(this.getPosition(), data.setValue(net.minecraft.world.level.block.StructureBlock.MODE, tileEntity.getMode()), 2);
}
}
}

View File

@@ -23,8 +23,8 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
public CraftTrialSpawner(World world, TrialSpawnerBlockEntity tileEntity) {
super(world, tileEntity);
this.normalConfig = new CraftTrialSpawnerConfiguration(tileEntity.getTrialSpawner().getNormalConfig(), getSnapshot());
this.ominousConfig = new CraftTrialSpawnerConfiguration(tileEntity.getTrialSpawner().getOminousConfig(), getSnapshot());
this.normalConfig = new CraftTrialSpawnerConfiguration(tileEntity.getTrialSpawner().getNormalConfig(), this.getSnapshot());
this.ominousConfig = new CraftTrialSpawnerConfiguration(tileEntity.getTrialSpawner().getOminousConfig(), this.getSnapshot());
}
protected CraftTrialSpawner(CraftTrialSpawner state, Location location) {
@@ -35,29 +35,29 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
@Override
public int getCooldownLength() {
return getSnapshot().trialSpawner.getTargetCooldownLength();
return this.getSnapshot().trialSpawner.getTargetCooldownLength();
}
@Override
public void setCooldownLength(int ticks) {
getSnapshot().trialSpawner.targetCooldownLength = ticks;
this.getSnapshot().trialSpawner.targetCooldownLength = ticks;
}
@Override
public int getRequiredPlayerRange() {
return getSnapshot().trialSpawner.getRequiredPlayerRange();
return this.getSnapshot().trialSpawner.getRequiredPlayerRange();
}
@Override
public void setRequiredPlayerRange(int requiredPlayerRange) {
getSnapshot().trialSpawner.requiredPlayerRange = requiredPlayerRange;
this.getSnapshot().trialSpawner.requiredPlayerRange = requiredPlayerRange;
}
@Override
public Collection<Player> getTrackedPlayers() {
ImmutableSet.Builder<Player> players = ImmutableSet.builder();
for (UUID uuid : getTrialData().detectedPlayers) {
for (UUID uuid : this.getTrialData().detectedPlayers) {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
players.add(player);
@@ -70,28 +70,28 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
public boolean isTrackingPlayer(Player player) {
Preconditions.checkArgument(player != null, "Player cannot be null");
return getTrialData().detectedPlayers.contains(player.getUniqueId());
return this.getTrialData().detectedPlayers.contains(player.getUniqueId());
}
@Override
public void startTrackingPlayer(Player player) {
Preconditions.checkArgument(player != null, "Player cannot be null");
getTrialData().detectedPlayers.add(player.getUniqueId());
this.getTrialData().detectedPlayers.add(player.getUniqueId());
}
@Override
public void stopTrackingPlayer(Player player) {
Preconditions.checkArgument(player != null, "Player cannot be null");
getTrialData().detectedPlayers.remove(player.getUniqueId());
this.getTrialData().detectedPlayers.remove(player.getUniqueId());
}
@Override
public Collection<Entity> getTrackedEntities() {
ImmutableSet.Builder<Entity> entities = ImmutableSet.builder();
for (UUID uuid : getTrialData().currentMobs) {
for (UUID uuid : this.getTrialData().currentMobs) {
Entity entity = Bukkit.getEntity(uuid);
if (entity != null) {
entities.add(entity);
@@ -104,60 +104,60 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
public boolean isTrackingEntity(Entity entity) {
Preconditions.checkArgument(entity != null, "Entity cannot be null");
return getTrialData().currentMobs.contains(entity.getUniqueId());
return this.getTrialData().currentMobs.contains(entity.getUniqueId());
}
@Override
public void startTrackingEntity(Entity entity) {
Preconditions.checkArgument(entity != null, "Entity cannot be null");
getTrialData().currentMobs.add(entity.getUniqueId());
this.getTrialData().currentMobs.add(entity.getUniqueId());
}
@Override
public void stopTrackingEntity(Entity entity) {
Preconditions.checkArgument(entity != null, "Entity cannot be null");
getTrialData().currentMobs.remove(entity.getUniqueId());
this.getTrialData().currentMobs.remove(entity.getUniqueId());
}
@Override
public boolean isOminous() {
return getHandle().getValue(TrialSpawnerBlock.OMINOUS);
return this.getHandle().getValue(TrialSpawnerBlock.OMINOUS);
}
@Override
public void setOminous(boolean ominous) {
getSnapshot().trialSpawner.isOminous = ominous;
this.getSnapshot().trialSpawner.isOminous = ominous;
if (ominous) {
setData(getHandle().setValue(TrialSpawnerBlock.OMINOUS, true));
this.setData(this.getHandle().setValue(TrialSpawnerBlock.OMINOUS, true));
// TODO: Consider calling TrialSpawnerData#resetAfterBecomingOminous in update(...), but note that method also removes entities
return;
}
setData(getHandle().setValue(TrialSpawnerBlock.OMINOUS, false));
this.setData(this.getHandle().setValue(TrialSpawnerBlock.OMINOUS, false));
}
@Override
public TrialSpawnerConfiguration getNormalConfiguration() {
return normalConfig;
return this.normalConfig;
}
@Override
public TrialSpawnerConfiguration getOminousConfiguration() {
return ominousConfig;
return this.ominousConfig;
}
@Override
protected void applyTo(TrialSpawnerBlockEntity tileEntity) {
super.applyTo(tileEntity);
tileEntity.trialSpawner.normalConfig = Holder.direct(normalConfig.toMinecraft());
tileEntity.trialSpawner.ominousConfig = Holder.direct(ominousConfig.toMinecraft());
tileEntity.trialSpawner.normalConfig = Holder.direct(this.normalConfig.toMinecraft());
tileEntity.trialSpawner.ominousConfig = Holder.direct(this.ominousConfig.toMinecraft());
}
private TrialSpawnerData getTrialData() {
return getSnapshot().getTrialSpawner().getData();
return this.getSnapshot().getTrialSpawner().getData();
}
@Override

View File

@@ -8,12 +8,11 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.random.WeightedEntry.b;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.level.MobSpawnerData;
import net.minecraft.util.random.WeightedEntry.Wrapper;
import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerConfig;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData;
@@ -36,7 +35,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
private float totalMobsAddedPerPlayer;
private float simultaneousMobsAddedPerPlayer;
private int ticksBetweenSpawn;
private SimpleWeightedRandomList<MobSpawnerData> spawnPotentialsDefinition;
private SimpleWeightedRandomList<SpawnData> spawnPotentialsDefinition;
private SimpleWeightedRandomList<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> lootTablesToEject;
private ResourceKey<net.minecraft.world.level.storage.loot.LootTable> itemsToDropWhenOminous;
@@ -56,84 +55,84 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
@Override
public EntityType getSpawnedType() {
if (spawnPotentialsDefinition.isEmpty()) {
if (this.spawnPotentialsDefinition.isEmpty()) {
return null;
}
Optional<EntityTypes<?>> type = EntityTypes.by(spawnPotentialsDefinition.unwrap().get(0).data().getEntityToSpawn());
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(this.spawnPotentialsDefinition.unwrap().get(0).data().getEntityToSpawn());
return type.map(CraftEntityType::minecraftToBukkit).orElse(null);
}
@Override
public void setSpawnedType(EntityType entityType) {
if (entityType == null) {
getTrialData().nextSpawnData = Optional.empty();
spawnPotentialsDefinition = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
this.getTrialData().nextSpawnData = Optional.empty();
this.spawnPotentialsDefinition = SimpleWeightedRandomList.empty(); // 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);
MobSpawnerData data = new MobSpawnerData();
SpawnData data = new SpawnData();
data.getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(CraftEntityType.bukkitToMinecraft(entityType)).toString());
getTrialData().nextSpawnData = Optional.of(data);
spawnPotentialsDefinition = SimpleWeightedRandomList.single(data);
this.getTrialData().nextSpawnData = Optional.of(data);
this.spawnPotentialsDefinition = SimpleWeightedRandomList.single(data);
}
@Override
public float getBaseSpawnsBeforeCooldown() {
return totalMobs;
return this.totalMobs;
}
@Override
public void setBaseSpawnsBeforeCooldown(float amount) {
totalMobs = amount;
this.totalMobs = amount;
}
@Override
public float getBaseSimultaneousEntities() {
return simultaneousMobs;
return this.simultaneousMobs;
}
@Override
public void setBaseSimultaneousEntities(float amount) {
simultaneousMobs = amount;
this.simultaneousMobs = amount;
}
@Override
public float getAdditionalSpawnsBeforeCooldown() {
return totalMobsAddedPerPlayer;
return this.totalMobsAddedPerPlayer;
}
@Override
public void setAdditionalSpawnsBeforeCooldown(float amount) {
totalMobsAddedPerPlayer = amount;
this.totalMobsAddedPerPlayer = amount;
}
@Override
public float getAdditionalSimultaneousEntities() {
return simultaneousMobsAddedPerPlayer;
return this.simultaneousMobsAddedPerPlayer;
}
@Override
public void setAdditionalSimultaneousEntities(float amount) {
simultaneousMobsAddedPerPlayer = amount;
this.simultaneousMobsAddedPerPlayer = amount;
}
@Override
public int getDelay() {
return ticksBetweenSpawn;
return this.ticksBetweenSpawn;
}
@Override
public void setDelay(int delay) {
Preconditions.checkArgument(delay >= 0, "Delay cannot be less than 0");
ticksBetweenSpawn = delay;
this.ticksBetweenSpawn = delay;
}
@Override
public int getSpawnRange() {
return spawnRange;
return this.spawnRange;
}
@Override
@@ -143,7 +142,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
@Override
public EntitySnapshot getSpawnedEntity() {
SimpleWeightedRandomList<MobSpawnerData> potentials = spawnPotentialsDefinition;
SimpleWeightedRandomList<SpawnData> potentials = this.spawnPotentialsDefinition;
if (potentials.isEmpty()) {
return null;
}
@@ -153,70 +152,70 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
@Override
public void setSpawnedEntity(EntitySnapshot snapshot) {
setSpawnedEntity(snapshot, null, null);
this.setSpawnedEntity(snapshot, null, null);
}
@Override
public void setSpawnedEntity(SpawnerEntry spawnerEntry) {
Preconditions.checkArgument(spawnerEntry != null, "Entry cannot be null");
setSpawnedEntity(spawnerEntry.getSnapshot(), spawnerEntry.getSpawnRule(), spawnerEntry.getEquipment());
this.setSpawnedEntity(spawnerEntry.getSnapshot(), spawnerEntry.getSpawnRule(), spawnerEntry.getEquipment());
}
private void setSpawnedEntity(EntitySnapshot snapshot, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
if (snapshot == null) {
getTrialData().nextSpawnData = Optional.empty();
spawnPotentialsDefinition = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
this.getTrialData().nextSpawnData = Optional.empty();
this.spawnPotentialsDefinition = SimpleWeightedRandomList.empty(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later
return;
}
NBTTagCompound compoundTag = ((CraftEntitySnapshot) snapshot).getData();
MobSpawnerData data = new MobSpawnerData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment));
CompoundTag compoundTag = ((CraftEntitySnapshot) snapshot).getData();
SpawnData data = new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment));
getTrialData().nextSpawnData = Optional.of(data);
spawnPotentialsDefinition = SimpleWeightedRandomList.single(data);
this.getTrialData().nextSpawnData = Optional.of(data);
this.spawnPotentialsDefinition = SimpleWeightedRandomList.single(data);
}
@Override
public void addPotentialSpawn(EntitySnapshot snapshot, int weight, SpawnRule spawnRule) {
addPotentialSpawn(snapshot, weight, spawnRule, null);
this.addPotentialSpawn(snapshot, weight, spawnRule, null);
}
private void addPotentialSpawn(EntitySnapshot snapshot, int weight, SpawnRule spawnRule, SpawnerEntry.Equipment equipment) {
Preconditions.checkArgument(snapshot != null, "Snapshot cannot be null");
NBTTagCompound compoundTag = ((CraftEntitySnapshot) snapshot).getData();
CompoundTag compoundTag = ((CraftEntitySnapshot) snapshot).getData();
SimpleWeightedRandomList.a<MobSpawnerData> builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder
spawnPotentialsDefinition.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment)), weight);
spawnPotentialsDefinition = builder.build();
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder
this.spawnPotentialsDefinition.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnRule)), CraftCreatureSpawner.getEquipment(equipment)), weight);
this.spawnPotentialsDefinition = builder.build();
}
@Override
public void addPotentialSpawn(SpawnerEntry spawnerEntry) {
Preconditions.checkArgument(spawnerEntry != null, "Entry cannot be null");
addPotentialSpawn(spawnerEntry.getSnapshot(), spawnerEntry.getSpawnWeight(), spawnerEntry.getSpawnRule(), spawnerEntry.getEquipment());
this.addPotentialSpawn(spawnerEntry.getSnapshot(), spawnerEntry.getSpawnWeight(), spawnerEntry.getSpawnRule(), spawnerEntry.getEquipment());
}
@Override
public void setPotentialSpawns(Collection<SpawnerEntry> entries) {
Preconditions.checkArgument(entries != null, "Entries cannot be null");
SimpleWeightedRandomList.a<MobSpawnerData> builder = SimpleWeightedRandomList.builder();
SimpleWeightedRandomList.Builder<SpawnData> builder = SimpleWeightedRandomList.builder();
for (SpawnerEntry spawnerEntry : entries) {
NBTTagCompound compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData();
builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnerEntry.getSpawnRule())), CraftCreatureSpawner.getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight());
CompoundTag compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData();
builder.add(new SpawnData(compoundTag, Optional.ofNullable(CraftCreatureSpawner.toMinecraftRule(spawnerEntry.getSpawnRule())), CraftCreatureSpawner.getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight());
}
spawnPotentialsDefinition = builder.build();
this.spawnPotentialsDefinition = builder.build();
}
@Override
public List<SpawnerEntry> getPotentialSpawns() {
List<SpawnerEntry> entries = new ArrayList<>();
for (b<MobSpawnerData> entry : spawnPotentialsDefinition.unwrap()) { // PAIL rename Wrapper
for (Wrapper<SpawnData> entry : this.spawnPotentialsDefinition.unwrap()) { // PAIL rename Wrapper
CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.data().getEntityToSpawn());
if (snapshot != null) {
@@ -231,7 +230,7 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
public Map<LootTable, Integer> getPossibleRewards() {
Map<LootTable, Integer> tables = new HashMap<>();
for (b<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : lootTablesToEject.unwrap()) {
for (Wrapper<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : this.lootTablesToEject.unwrap()) {
LootTable table = CraftLootTable.minecraftToBukkit(entry.data());
if (table != null) {
tables.put(table, entry.getWeight().asInt());
@@ -246,10 +245,10 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
Preconditions.checkArgument(table != null, "Table cannot be null");
Preconditions.checkArgument(weight >= 1, "Weight must be at least 1");
SimpleWeightedRandomList.a<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
lootTablesToEject.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt()));
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()));
builder.add(CraftLootTable.bukkitToMinecraft(table), weight);
lootTablesToEject = builder.build();
this.lootTablesToEject = builder.build();
}
@Override
@@ -257,24 +256,24 @@ 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.a<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
SimpleWeightedRandomList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
for (b<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> entry : lootTablesToEject.unwrap()) {
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());
}
}
lootTablesToEject = builder.build();
this.lootTablesToEject = builder.build();
}
@Override
public void setPossibleRewards(Map<LootTable, Integer> rewards) {
if (rewards == null || rewards.isEmpty()) {
lootTablesToEject = SimpleWeightedRandomList.empty();
this.lootTablesToEject = SimpleWeightedRandomList.empty();
return;
}
SimpleWeightedRandomList.a<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
SimpleWeightedRandomList.Builder<ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> builder = SimpleWeightedRandomList.builder();
rewards.forEach((table, weight) -> {
Preconditions.checkArgument(table != null, "Table cannot be null");
Preconditions.checkArgument(weight >= 1, "Weight must be at least 1");
@@ -282,24 +281,24 @@ public class CraftTrialSpawnerConfiguration implements TrialSpawnerConfiguration
builder.add(CraftLootTable.bukkitToMinecraft(table), weight);
});
lootTablesToEject = builder.build();
this.lootTablesToEject = builder.build();
}
@Override
public int getRequiredPlayerRange() {
return snapshot.trialSpawner.getRequiredPlayerRange();
return this.snapshot.trialSpawner.getRequiredPlayerRange();
}
@Override
public void setRequiredPlayerRange(int requiredPlayerRange) {
snapshot.trialSpawner.requiredPlayerRange = requiredPlayerRange;
this.snapshot.trialSpawner.requiredPlayerRange = requiredPlayerRange;
}
private TrialSpawnerData getTrialData() {
return snapshot.getTrialSpawner().getData();
return this.snapshot.getTrialSpawner().getData();
}
protected TrialSpawnerConfig toMinecraft() {
return new TrialSpawnerConfig(spawnRange, totalMobs, simultaneousMobs, totalMobsAddedPerPlayer, simultaneousMobsAddedPerPlayer, ticksBetweenSpawn, spawnPotentialsDefinition, lootTablesToEject, itemsToDropWhenOminous);
return new TrialSpawnerConfig(this.spawnRange, this.totalMobs, this.simultaneousMobs, this.totalMobsAddedPerPlayer, this.simultaneousMobsAddedPerPlayer, this.ticksBetweenSpawn, this.spawnPotentialsDefinition, this.lootTablesToEject, this.itemsToDropWhenOminous);
}
}

View File

@@ -3,37 +3,36 @@ package org.bukkit.craftbukkit.block.banner;
import com.google.common.base.Preconditions;
import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.entity.EnumBannerPatternType;
import net.minecraft.world.level.block.entity.BannerPattern;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.block.banner.PatternType;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
public class CraftPatternType implements PatternType, Handleable<EnumBannerPatternType> {
public class CraftPatternType implements PatternType, Handleable<BannerPattern> {
private static int count = 0;
public static PatternType minecraftToBukkit(EnumBannerPatternType minecraft) {
public static PatternType minecraftToBukkit(BannerPattern minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.BANNER_PATTERN, Registry.BANNER_PATTERN);
}
public static PatternType minecraftHolderToBukkit(Holder<EnumBannerPatternType> minecraft) {
return minecraftToBukkit(minecraft.value());
public static PatternType minecraftHolderToBukkit(Holder<BannerPattern> minecraft) {
return CraftPatternType.minecraftToBukkit(minecraft.value());
}
public static EnumBannerPatternType bukkitToMinecraft(PatternType bukkit) {
public static BannerPattern bukkitToMinecraft(PatternType bukkit) {
return CraftRegistry.bukkitToMinecraft(bukkit);
}
public static Holder<EnumBannerPatternType> bukkitToMinecraftHolder(PatternType bukkit) {
public static Holder<BannerPattern> bukkitToMinecraftHolder(PatternType bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<EnumBannerPatternType> registry = CraftRegistry.getMinecraftRegistry(Registries.BANNER_PATTERN);
net.minecraft.core.Registry<BannerPattern> registry = CraftRegistry.getMinecraftRegistry(Registries.BANNER_PATTERN);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<EnumBannerPatternType> holder) {
if (registry.wrapAsHolder(CraftPatternType.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<BannerPattern> holder) {
return holder;
}
@@ -42,11 +41,11 @@ public class CraftPatternType implements PatternType, Handleable<EnumBannerPatte
}
private final NamespacedKey key;
private final EnumBannerPatternType bannerPatternType;
private final BannerPattern bannerPatternType;
private final String name;
private final int ordinal;
public CraftPatternType(NamespacedKey key, EnumBannerPatternType bannerPatternType) {
public CraftPatternType(NamespacedKey key, BannerPattern bannerPatternType) {
this.key = key;
this.bannerPatternType = bannerPatternType;
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
@@ -58,38 +57,38 @@ public class CraftPatternType implements PatternType, Handleable<EnumBannerPatte
} else {
this.name = key.toString();
}
this.ordinal = count++;
this.ordinal = CraftPatternType.count++;
}
@Override
public EnumBannerPatternType getHandle() {
return bannerPatternType;
public BannerPattern getHandle() {
return this.bannerPatternType;
}
@Override
public NamespacedKey getKey() {
return key;
return this.key;
}
@Override
public int compareTo(PatternType patternType) {
return ordinal - patternType.ordinal();
return this.ordinal - patternType.ordinal();
}
@Override
public String name() {
return name;
return this.name;
}
@Override
public int ordinal() {
return ordinal;
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return name();
return this.name();
}
@Override
@@ -102,12 +101,12 @@ public class CraftPatternType implements PatternType, Handleable<EnumBannerPatte
return false;
}
return getKey().equals(((PatternType) other).getKey());
return this.getKey().equals(((PatternType) other).getKey());
}
@Override
public int hashCode() {
return getKey().hashCode();
return this.getKey().hashCode();
}
@Override

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,22 +9,20 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.commands.arguments.blocks.ArgumentBlock;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.EnumDirection;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.util.INamable;
import net.minecraft.world.level.BlockAccessAir;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EnumBlockMirror;
import net.minecraft.world.level.block.EnumBlockRotation;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.state.IBlockDataHolder;
import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
import net.minecraft.world.level.block.state.properties.BlockStateEnum;
import net.minecraft.world.level.block.state.properties.BlockStateInteger;
import net.minecraft.world.level.block.state.properties.IBlockState;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.Property;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -52,24 +50,24 @@ import org.jetbrains.annotations.NotNull;
public class CraftBlockData implements BlockData {
private IBlockData state;
private Map<IBlockState<?>, Comparable<?>> parsedStates;
private net.minecraft.world.level.block.state.BlockState state;
private Map<Property<?>, Comparable<?>> parsedStates;
protected CraftBlockData() {
throw new AssertionError("Template Constructor");
}
protected CraftBlockData(IBlockData state) {
protected CraftBlockData(net.minecraft.world.level.block.state.BlockState state) {
this.state = state;
}
@Override
public Material getMaterial() {
return CraftBlockType.minecraftToBukkit(state.getBlock());
return CraftBlockType.minecraftToBukkit(this.state.getBlock());
}
public IBlockData getState() {
return state;
public net.minecraft.world.level.block.state.BlockState getState() {
return this.state;
}
/**
@@ -80,8 +78,8 @@ public class CraftBlockData implements BlockData {
* @param <B> the type
* @return the matching Bukkit type
*/
protected <B extends Enum<B>> B get(BlockStateEnum<?> nms, Class<B> bukkit) {
return toBukkit(state.getValue(nms), bukkit);
protected <B extends Enum<B>> B get(EnumProperty<?> nms, Class<B> bukkit) {
return CraftBlockData.toBukkit(this.state.getValue(nms), bukkit);
}
/**
@@ -94,27 +92,27 @@ public class CraftBlockData implements BlockData {
* @return an immutable Set of values in their appropriate Bukkit type
*/
@SuppressWarnings("unchecked")
protected <B extends Enum<B>> Set<B> getValues(BlockStateEnum<?> nms, Class<B> bukkit) {
protected <B extends Enum<B>> Set<B> getValues(EnumProperty<?> nms, Class<B> bukkit) {
ImmutableSet.Builder<B> values = ImmutableSet.builder();
for (Enum<?> e : nms.getPossibleValues()) {
values.add(toBukkit(e, bukkit));
values.add(CraftBlockData.toBukkit(e, bukkit));
}
return values.build();
}
/**
* Set a given {@link BlockStateEnum} with the matching enum from Bukkit.
* Set a given {@link EnumProperty} with the matching enum from Bukkit.
*
* @param nms the NMS BlockStateEnum to set
* @param bukkit the matching Bukkit Enum
* @param <B> the Bukkit type
* @param <N> the NMS type
*/
protected <B extends Enum<B>, N extends Enum<N> & INamable> void set(BlockStateEnum<N> nms, Enum<B> bukkit) {
protected <B extends Enum<B>, N extends Enum<N> & StringRepresentable> void set(EnumProperty<N> nms, Enum<B> bukkit) {
this.parsedStates = null;
this.state = this.state.setValue(nms, toNMS(bukkit, nms.getValueClass()));
this.state = this.state.setValue(nms, CraftBlockData.toNMS(bukkit, nms.getValueClass()));
}
@Override
@@ -126,7 +124,7 @@ public class CraftBlockData implements BlockData {
CraftBlockData clone = (CraftBlockData) this.clone();
clone.parsedStates = null;
for (IBlockState parsed : craft.parsedStates.keySet()) {
for (Property parsed : craft.parsedStates.keySet()) {
clone.state = clone.state.setValue(parsed, craft.state.getValue(parsed));
}
@@ -168,10 +166,10 @@ public class CraftBlockData implements BlockData {
*/
@SuppressWarnings("unchecked")
private static <B extends Enum<B>> B toBukkit(Enum<?> nms, Class<B> bukkit) {
if (nms instanceof EnumDirection) {
return (B) CraftBlock.notchToBlockFace((EnumDirection) nms);
if (nms instanceof Direction) {
return (B) CraftBlock.notchToBlockFace((Direction) nms);
}
return (B) ENUM_VALUES.computeIfAbsent(bukkit, Class::getEnumConstants)[nms.ordinal()];
return (B) CraftBlockData.ENUM_VALUES.computeIfAbsent(bukkit, Class::getEnumConstants)[nms.ordinal()];
}
/**
@@ -183,11 +181,11 @@ public class CraftBlockData implements BlockData {
* @throws IllegalStateException if the Enum could not be converted
*/
@SuppressWarnings("unchecked")
private static <N extends Enum<N> & INamable> N toNMS(Enum<?> bukkit, Class<N> nms) {
public static <N extends Enum<N> & StringRepresentable> N toNMS(Enum<?> bukkit, Class<N> nms) {
if (bukkit instanceof BlockFace) {
return (N) CraftBlock.blockFaceToNotch((BlockFace) bukkit);
}
return (N) ENUM_VALUES.computeIfAbsent(nms, Class::getEnumConstants)[bukkit.ordinal()];
return (N) CraftBlockData.ENUM_VALUES.computeIfAbsent(nms, Class::getEnumConstants)[bukkit.ordinal()];
}
/**
@@ -197,7 +195,7 @@ public class CraftBlockData implements BlockData {
* @param <T> the type
* @return the current value of the given state
*/
protected <T extends Comparable<T>> T get(IBlockState<T> ibs) {
protected <T extends Comparable<T>> T get(Property<T> ibs) {
// Straight integer or boolean getter
return this.state.getValue(ibs);
}
@@ -210,7 +208,7 @@ public class CraftBlockData implements BlockData {
* @param <T> the state's type
* @param <V> the value's type. Must match the state's type.
*/
public <T extends Comparable<T>, V extends T> void set(IBlockState<T> ibs, V v) {
public <T extends Comparable<T>, V extends T> void set(Property<T> ibs, V v) {
// Straight integer or boolean setter
this.parsedStates = null;
this.state = this.state.setValue(ibs, v);
@@ -218,12 +216,12 @@ public class CraftBlockData implements BlockData {
@Override
public String getAsString() {
return toString(state.getValues());
return this.toString(this.state.getValues());
}
@Override
public String getAsString(boolean hideUnspecified) {
return (hideUnspecified && parsedStates != null) ? toString(parsedStates) : getAsString();
return (hideUnspecified && this.parsedStates != null) ? this.toString(this.parsedStates) : this.getAsString();
}
@Override
@@ -237,16 +235,16 @@ public class CraftBlockData implements BlockData {
@Override
public String toString() {
return "CraftBlockData{" + getAsString() + "}";
return "CraftBlockData{" + this.getAsString() + "}";
}
// Mimicked from BlockDataAbstract#toString()
public String toString(Map<IBlockState<?>, Comparable<?>> states) {
StringBuilder stateString = new StringBuilder(BuiltInRegistries.BLOCK.getKey(state.getBlock()).toString());
public String toString(Map<Property<?>, Comparable<?>> states) {
StringBuilder stateString = new StringBuilder(BuiltInRegistries.BLOCK.getKey(this.state.getBlock()).toString());
if (!states.isEmpty()) {
stateString.append('[');
stateString.append(states.entrySet().stream().map(IBlockDataHolder.PROPERTY_ENTRY_TO_STRING_FUNCTION).collect(Collectors.joining(",")));
stateString.append(states.entrySet().stream().map(StateHolder.PROPERTY_ENTRY_TO_STRING_FUNCTION).collect(Collectors.joining(",")));
stateString.append(']');
}
@@ -254,14 +252,14 @@ public class CraftBlockData implements BlockData {
}
public Map<String, String> toStates(boolean hideUnspecified) {
return (hideUnspecified && parsedStates != null) ? toStates(parsedStates) : toStates(state.getValues());
return (hideUnspecified && this.parsedStates != null) ? CraftBlockData.toStates(this.parsedStates) : CraftBlockData.toStates(this.state.getValues());
}
private static Map<String, String> toStates(Map<IBlockState<?>, Comparable<?>> states) {
private static Map<String, String> toStates(Map<Property<?>, Comparable<?>> states) {
Map<String, String> compound = new HashMap<>();
for (Map.Entry<IBlockState<?>, Comparable<?>> entry : states.entrySet()) {
IBlockState iblockstate = (IBlockState) entry.getKey();
for (Map.Entry<Property<?>, Comparable<?>> entry : states.entrySet()) {
Property iblockstate = (Property) entry.getKey();
compound.put(iblockstate.getName(), iblockstate.getName(entry.getValue()));
}
@@ -271,48 +269,48 @@ public class CraftBlockData implements BlockData {
@Override
public boolean equals(Object obj) {
return obj instanceof CraftBlockData && state.equals(((CraftBlockData) obj).state);
return obj instanceof CraftBlockData && this.state.equals(((CraftBlockData) obj).state);
}
@Override
public int hashCode() {
return state.hashCode();
return this.state.hashCode();
}
protected static BlockStateBoolean getBoolean(String name) {
protected static BooleanProperty getBoolean(String name) {
throw new AssertionError("Template Method");
}
protected static BlockStateBoolean getBoolean(String name, boolean optional) {
protected static BooleanProperty getBoolean(String name, boolean optional) {
throw new AssertionError("Template Method");
}
protected static BlockStateEnum<?> getEnum(String name) {
protected static EnumProperty<?> getEnum(String name) {
throw new AssertionError("Template Method");
}
protected static BlockStateInteger getInteger(String name) {
protected static IntegerProperty getInteger(String name) {
throw new AssertionError("Template Method");
}
protected static BlockStateBoolean getBoolean(Class<? extends Block> block, String name) {
return (BlockStateBoolean) getState(block, name, false);
protected static BooleanProperty getBoolean(Class<? extends Block> block, String name) {
return (BooleanProperty) CraftBlockData.getState(block, name, false);
}
protected static BlockStateBoolean getBoolean(Class<? extends Block> block, String name, boolean optional) {
return (BlockStateBoolean) getState(block, name, optional);
protected static BooleanProperty getBoolean(Class<? extends Block> block, String name, boolean optional) {
return (BooleanProperty) CraftBlockData.getState(block, name, optional);
}
protected static BlockStateEnum<?> getEnum(Class<? extends Block> block, String name) {
return (BlockStateEnum<?>) getState(block, name, false);
protected static EnumProperty<?> getEnum(Class<? extends Block> block, String name) {
return (EnumProperty<?>) CraftBlockData.getState(block, name, false);
}
protected static BlockStateInteger getInteger(Class<? extends Block> block, String name) {
return (BlockStateInteger) getState(block, name, false);
protected static IntegerProperty getInteger(Class<? extends Block> block, String name) {
return (IntegerProperty) CraftBlockData.getState(block, name, false);
}
/**
* Get a specified {@link IBlockState} from a given block's class with a
* Get a specified {@link Property} from a given block's class with a
* given name
*
* @param block the class to retrieve the state from
@@ -322,15 +320,15 @@ public class CraftBlockData implements BlockData {
* @throws IllegalStateException if the state is null and {@code optional}
* is false.
*/
private static IBlockState<?> getState(Class<? extends Block> block, String name, boolean optional) {
IBlockState<?> state = null;
private static Property<?> getState(Class<? extends Block> block, String name, boolean optional) {
Property<?> state = null;
for (Block instance : BuiltInRegistries.BLOCK) {
if (instance.getClass() == block) {
if (state == null) {
state = instance.getStateDefinition().getProperty(name);
} else {
IBlockState<?> newState = instance.getStateDefinition().getProperty(name);
Property<?> newState = instance.getStateDefinition().getProperty(name);
Preconditions.checkState(state == newState, "State mistmatch %s,%s", state, newState);
}
@@ -348,7 +346,7 @@ public class CraftBlockData implements BlockData {
* @param state the state to check
* @return the minimum value allowed
*/
protected static int getMin(BlockStateInteger state) {
protected static int getMin(IntegerProperty state) {
return state.min;
}
@@ -358,140 +356,140 @@ public class CraftBlockData implements BlockData {
* @param state the state to check
* @return the maximum value allowed
*/
protected static int getMax(BlockStateInteger state) {
protected static int getMax(IntegerProperty state) {
return state.max;
}
//
private static final Map<Class<? extends Block>, Function<IBlockData, CraftBlockData>> MAP = new HashMap<>();
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">
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.BlockAnvil.class, org.bukkit.craftbukkit.block.impl.CraftAnvil::new);
register(net.minecraft.world.level.block.BlockBamboo.class, org.bukkit.craftbukkit.block.impl.CraftBamboo::new);
register(net.minecraft.world.level.block.BlockBanner.class, org.bukkit.craftbukkit.block.impl.CraftBanner::new);
register(net.minecraft.world.level.block.BlockBannerWall.class, org.bukkit.craftbukkit.block.impl.CraftBannerWall::new);
register(net.minecraft.world.level.block.BlockBarrel.class, org.bukkit.craftbukkit.block.impl.CraftBarrel::new);
register(net.minecraft.world.level.block.BlockBarrier.class, org.bukkit.craftbukkit.block.impl.CraftBarrier::new);
register(net.minecraft.world.level.block.BlockBed.class, org.bukkit.craftbukkit.block.impl.CraftBed::new);
register(net.minecraft.world.level.block.BlockBeehive.class, org.bukkit.craftbukkit.block.impl.CraftBeehive::new);
register(net.minecraft.world.level.block.BlockBeetroot.class, org.bukkit.craftbukkit.block.impl.CraftBeetroot::new);
register(net.minecraft.world.level.block.BlockBell.class, org.bukkit.craftbukkit.block.impl.CraftBell::new);
register(net.minecraft.world.level.block.BlockBlastFurnace.class, org.bukkit.craftbukkit.block.impl.CraftBlastFurnace::new);
register(net.minecraft.world.level.block.BlockBrewingStand.class, org.bukkit.craftbukkit.block.impl.CraftBrewingStand::new);
register(net.minecraft.world.level.block.BlockBubbleColumn.class, org.bukkit.craftbukkit.block.impl.CraftBubbleColumn::new);
register(net.minecraft.world.level.block.BlockButtonAbstract.class, org.bukkit.craftbukkit.block.impl.CraftButtonAbstract::new);
register(net.minecraft.world.level.block.BlockCactus.class, org.bukkit.craftbukkit.block.impl.CraftCactus::new);
register(net.minecraft.world.level.block.BlockCake.class, org.bukkit.craftbukkit.block.impl.CraftCake::new);
register(net.minecraft.world.level.block.BlockCampfire.class, org.bukkit.craftbukkit.block.impl.CraftCampfire::new);
register(net.minecraft.world.level.block.BlockCarrots.class, org.bukkit.craftbukkit.block.impl.CraftCarrots::new);
register(net.minecraft.world.level.block.BlockChain.class, org.bukkit.craftbukkit.block.impl.CraftChain::new);
register(net.minecraft.world.level.block.BlockChest.class, org.bukkit.craftbukkit.block.impl.CraftChest::new);
register(net.minecraft.world.level.block.BlockChestTrapped.class, org.bukkit.craftbukkit.block.impl.CraftChestTrapped::new);
register(net.minecraft.world.level.block.BlockChorusFlower.class, org.bukkit.craftbukkit.block.impl.CraftChorusFlower::new);
register(net.minecraft.world.level.block.BlockChorusFruit.class, org.bukkit.craftbukkit.block.impl.CraftChorusFruit::new);
register(net.minecraft.world.level.block.BlockCobbleWall.class, org.bukkit.craftbukkit.block.impl.CraftCobbleWall::new);
register(net.minecraft.world.level.block.BlockCocoa.class, org.bukkit.craftbukkit.block.impl.CraftCocoa::new);
register(net.minecraft.world.level.block.BlockCommand.class, org.bukkit.craftbukkit.block.impl.CraftCommand::new);
register(net.minecraft.world.level.block.BlockComposter.class, org.bukkit.craftbukkit.block.impl.CraftComposter::new);
register(net.minecraft.world.level.block.BlockConduit.class, org.bukkit.craftbukkit.block.impl.CraftConduit::new);
register(net.minecraft.world.level.block.BlockCoralDead.class, org.bukkit.craftbukkit.block.impl.CraftCoralDead::new);
register(net.minecraft.world.level.block.BlockCoralFan.class, org.bukkit.craftbukkit.block.impl.CraftCoralFan::new);
register(net.minecraft.world.level.block.BlockCoralFanAbstract.class, org.bukkit.craftbukkit.block.impl.CraftCoralFanAbstract::new);
register(net.minecraft.world.level.block.BlockCoralFanWall.class, org.bukkit.craftbukkit.block.impl.CraftCoralFanWall::new);
register(net.minecraft.world.level.block.BlockCoralFanWallAbstract.class, org.bukkit.craftbukkit.block.impl.CraftCoralFanWallAbstract::new);
register(net.minecraft.world.level.block.BlockCoralPlant.class, org.bukkit.craftbukkit.block.impl.CraftCoralPlant::new);
register(net.minecraft.world.level.block.BlockCrops.class, org.bukkit.craftbukkit.block.impl.CraftCrops::new);
register(net.minecraft.world.level.block.BlockDaylightDetector.class, org.bukkit.craftbukkit.block.impl.CraftDaylightDetector::new);
register(net.minecraft.world.level.block.BlockDirtSnow.class, org.bukkit.craftbukkit.block.impl.CraftDirtSnow::new);
register(net.minecraft.world.level.block.BlockDispenser.class, org.bukkit.craftbukkit.block.impl.CraftDispenser::new);
register(net.minecraft.world.level.block.BlockDoor.class, org.bukkit.craftbukkit.block.impl.CraftDoor::new);
register(net.minecraft.world.level.block.BlockDropper.class, org.bukkit.craftbukkit.block.impl.CraftDropper::new);
register(net.minecraft.world.level.block.BlockEndRod.class, org.bukkit.craftbukkit.block.impl.CraftEndRod::new);
register(net.minecraft.world.level.block.BlockEnderChest.class, org.bukkit.craftbukkit.block.impl.CraftEnderChest::new);
register(net.minecraft.world.level.block.BlockEnderPortalFrame.class, org.bukkit.craftbukkit.block.impl.CraftEnderPortalFrame::new);
register(net.minecraft.world.level.block.BlockFence.class, org.bukkit.craftbukkit.block.impl.CraftFence::new);
register(net.minecraft.world.level.block.BlockFenceGate.class, org.bukkit.craftbukkit.block.impl.CraftFenceGate::new);
register(net.minecraft.world.level.block.BlockFire.class, org.bukkit.craftbukkit.block.impl.CraftFire::new);
register(net.minecraft.world.level.block.BlockFloorSign.class, org.bukkit.craftbukkit.block.impl.CraftFloorSign::new);
register(net.minecraft.world.level.block.BlockFluids.class, org.bukkit.craftbukkit.block.impl.CraftFluids::new);
register(net.minecraft.world.level.block.BlockFurnaceFurace.class, org.bukkit.craftbukkit.block.impl.CraftFurnaceFurace::new);
register(net.minecraft.world.level.block.BlockGlazedTerracotta.class, org.bukkit.craftbukkit.block.impl.CraftGlazedTerracotta::new);
register(net.minecraft.world.level.block.BlockGrass.class, org.bukkit.craftbukkit.block.impl.CraftGrass::new);
register(net.minecraft.world.level.block.BlockGrindstone.class, org.bukkit.craftbukkit.block.impl.CraftGrindstone::new);
register(net.minecraft.world.level.block.BlockHay.class, org.bukkit.craftbukkit.block.impl.CraftHay::new);
register(net.minecraft.world.level.block.BlockHopper.class, org.bukkit.craftbukkit.block.impl.CraftHopper::new);
register(net.minecraft.world.level.block.BlockHugeMushroom.class, org.bukkit.craftbukkit.block.impl.CraftHugeMushroom::new);
register(net.minecraft.world.level.block.BlockIceFrost.class, org.bukkit.craftbukkit.block.impl.CraftIceFrost::new);
register(net.minecraft.world.level.block.BlockIronBars.class, org.bukkit.craftbukkit.block.impl.CraftIronBars::new);
register(net.minecraft.world.level.block.BlockJigsaw.class, org.bukkit.craftbukkit.block.impl.CraftJigsaw::new);
register(net.minecraft.world.level.block.BlockJukeBox.class, org.bukkit.craftbukkit.block.impl.CraftJukeBox::new);
register(net.minecraft.world.level.block.BlockKelp.class, org.bukkit.craftbukkit.block.impl.CraftKelp::new);
register(net.minecraft.world.level.block.BlockLadder.class, org.bukkit.craftbukkit.block.impl.CraftLadder::new);
register(net.minecraft.world.level.block.BlockLantern.class, org.bukkit.craftbukkit.block.impl.CraftLantern::new);
register(net.minecraft.world.level.block.BlockLeaves.class, org.bukkit.craftbukkit.block.impl.CraftLeaves::new);
register(net.minecraft.world.level.block.BlockLectern.class, org.bukkit.craftbukkit.block.impl.CraftLectern::new);
register(net.minecraft.world.level.block.BlockLever.class, org.bukkit.craftbukkit.block.impl.CraftLever::new);
register(net.minecraft.world.level.block.BlockLoom.class, org.bukkit.craftbukkit.block.impl.CraftLoom::new);
register(net.minecraft.world.level.block.BlockMinecartDetector.class, org.bukkit.craftbukkit.block.impl.CraftMinecartDetector::new);
register(net.minecraft.world.level.block.BlockMinecartTrack.class, org.bukkit.craftbukkit.block.impl.CraftMinecartTrack::new);
register(net.minecraft.world.level.block.BlockMycel.class, org.bukkit.craftbukkit.block.impl.CraftMycel::new);
register(net.minecraft.world.level.block.BlockNetherWart.class, org.bukkit.craftbukkit.block.impl.CraftNetherWart::new);
register(net.minecraft.world.level.block.BlockNote.class, org.bukkit.craftbukkit.block.impl.CraftNote::new);
register(net.minecraft.world.level.block.BlockObserver.class, org.bukkit.craftbukkit.block.impl.CraftObserver::new);
register(net.minecraft.world.level.block.BlockPortal.class, org.bukkit.craftbukkit.block.impl.CraftPortal::new);
register(net.minecraft.world.level.block.BlockPotatoes.class, org.bukkit.craftbukkit.block.impl.CraftPotatoes::new);
register(net.minecraft.world.level.block.BlockPoweredRail.class, org.bukkit.craftbukkit.block.impl.CraftPoweredRail::new);
register(net.minecraft.world.level.block.BlockPressurePlateBinary.class, org.bukkit.craftbukkit.block.impl.CraftPressurePlateBinary::new);
register(net.minecraft.world.level.block.BlockPressurePlateWeighted.class, org.bukkit.craftbukkit.block.impl.CraftPressurePlateWeighted::new);
register(net.minecraft.world.level.block.BlockPumpkinCarved.class, org.bukkit.craftbukkit.block.impl.CraftPumpkinCarved::new);
register(net.minecraft.world.level.block.BlockRedstoneComparator.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneComparator::new);
register(net.minecraft.world.level.block.BlockRedstoneLamp.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneLamp::new);
register(net.minecraft.world.level.block.BlockRedstoneOre.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneOre::new);
register(net.minecraft.world.level.block.BlockRedstoneTorch.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneTorch::new);
register(net.minecraft.world.level.block.BlockRedstoneTorchWall.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneTorchWall::new);
register(net.minecraft.world.level.block.BlockRedstoneWire.class, org.bukkit.craftbukkit.block.impl.CraftRedstoneWire::new);
register(net.minecraft.world.level.block.BlockReed.class, org.bukkit.craftbukkit.block.impl.CraftReed::new);
register(net.minecraft.world.level.block.BlockRepeater.class, org.bukkit.craftbukkit.block.impl.CraftRepeater::new);
register(net.minecraft.world.level.block.BlockRespawnAnchor.class, org.bukkit.craftbukkit.block.impl.CraftRespawnAnchor::new);
register(net.minecraft.world.level.block.BlockRotatable.class, org.bukkit.craftbukkit.block.impl.CraftRotatable::new);
register(net.minecraft.world.level.block.BlockSapling.class, org.bukkit.craftbukkit.block.impl.CraftSapling::new);
register(net.minecraft.world.level.block.BlockScaffolding.class, org.bukkit.craftbukkit.block.impl.CraftScaffolding::new);
register(net.minecraft.world.level.block.BlockSeaPickle.class, org.bukkit.craftbukkit.block.impl.CraftSeaPickle::new);
register(net.minecraft.world.level.block.BlockShulkerBox.class, org.bukkit.craftbukkit.block.impl.CraftShulkerBox::new);
register(net.minecraft.world.level.block.BlockSkull.class, org.bukkit.craftbukkit.block.impl.CraftSkull::new);
register(net.minecraft.world.level.block.BlockSkullPlayer.class, org.bukkit.craftbukkit.block.impl.CraftSkullPlayer::new);
register(net.minecraft.world.level.block.BlockSkullPlayerWall.class, org.bukkit.craftbukkit.block.impl.CraftSkullPlayerWall::new);
register(net.minecraft.world.level.block.BlockSkullWall.class, org.bukkit.craftbukkit.block.impl.CraftSkullWall::new);
register(net.minecraft.world.level.block.BlockSmoker.class, org.bukkit.craftbukkit.block.impl.CraftSmoker::new);
register(net.minecraft.world.level.block.BlockSnow.class, org.bukkit.craftbukkit.block.impl.CraftSnow::new);
register(net.minecraft.world.level.block.BlockSoil.class, org.bukkit.craftbukkit.block.impl.CraftSoil::new);
register(net.minecraft.world.level.block.BlockStainedGlassPane.class, org.bukkit.craftbukkit.block.impl.CraftStainedGlassPane::new);
register(net.minecraft.world.level.block.BlockStairs.class, org.bukkit.craftbukkit.block.impl.CraftStairs::new);
register(net.minecraft.world.level.block.BlockStem.class, org.bukkit.craftbukkit.block.impl.CraftStem::new);
register(net.minecraft.world.level.block.BlockStemAttached.class, org.bukkit.craftbukkit.block.impl.CraftStemAttached::new);
register(net.minecraft.world.level.block.BlockStepAbstract.class, org.bukkit.craftbukkit.block.impl.CraftStepAbstract::new);
register(net.minecraft.world.level.block.BlockStonecutter.class, org.bukkit.craftbukkit.block.impl.CraftStonecutter::new);
register(net.minecraft.world.level.block.BlockStructure.class, org.bukkit.craftbukkit.block.impl.CraftStructure::new);
register(net.minecraft.world.level.block.BlockSweetBerryBush.class, org.bukkit.craftbukkit.block.impl.CraftSweetBerryBush::new);
register(net.minecraft.world.level.block.BlockTNT.class, org.bukkit.craftbukkit.block.impl.CraftTNT::new);
register(net.minecraft.world.level.block.BlockTallPlant.class, org.bukkit.craftbukkit.block.impl.CraftTallPlant::new);
register(net.minecraft.world.level.block.BlockTallPlantFlower.class, org.bukkit.craftbukkit.block.impl.CraftTallPlantFlower::new);
register(net.minecraft.world.level.block.BlockTarget.class, org.bukkit.craftbukkit.block.impl.CraftTarget::new);
register(net.minecraft.world.level.block.BlockTorchWall.class, org.bukkit.craftbukkit.block.impl.CraftTorchWall::new);
register(net.minecraft.world.level.block.BlockTrapdoor.class, org.bukkit.craftbukkit.block.impl.CraftTrapdoor::new);
register(net.minecraft.world.level.block.BlockTripwire.class, org.bukkit.craftbukkit.block.impl.CraftTripwire::new);
register(net.minecraft.world.level.block.BlockTripwireHook.class, org.bukkit.craftbukkit.block.impl.CraftTripwireHook::new);
register(net.minecraft.world.level.block.BlockTurtleEgg.class, org.bukkit.craftbukkit.block.impl.CraftTurtleEgg::new);
register(net.minecraft.world.level.block.BlockTwistingVines.class, org.bukkit.craftbukkit.block.impl.CraftTwistingVines::new);
register(net.minecraft.world.level.block.BlockVine.class, org.bukkit.craftbukkit.block.impl.CraftVine::new);
register(net.minecraft.world.level.block.BlockWallSign.class, org.bukkit.craftbukkit.block.impl.CraftWallSign::new);
register(net.minecraft.world.level.block.BlockWeepingVines.class, org.bukkit.craftbukkit.block.impl.CraftWeepingVines::new);
register(net.minecraft.world.level.block.BlockWitherSkull.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkull::new);
register(net.minecraft.world.level.block.BlockWitherSkullWall.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkullWall::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.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.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.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.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.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.CandleBlock.class, org.bukkit.craftbukkit.block.impl.CraftCandle::new);
@@ -540,20 +538,20 @@ 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.BlockPiston.class, org.bukkit.craftbukkit.block.impl.CraftPiston::new);
register(net.minecraft.world.level.block.piston.BlockPistonExtension.class, org.bukkit.craftbukkit.block.impl.CraftPistonExtension::new);
register(net.minecraft.world.level.block.piston.BlockPistonMoving.class, org.bukkit.craftbukkit.block.impl.CraftPistonMoving::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);
//</editor-fold>
}
private static void register(Class<? extends Block> nms, Function<IBlockData, CraftBlockData> bukkit) {
Preconditions.checkState(MAP.put(nms, bukkit) == null, "Duplicate mapping %s->%s", nms, bukkit);
private static void register(Class<? extends Block> nms, Function<net.minecraft.world.level.block.state.BlockState, CraftBlockData> bukkit) {
Preconditions.checkState(CraftBlockData.MAP.put(nms, bukkit) == null, "Duplicate mapping %s->%s", nms, bukkit);
}
public static CraftBlockData newData(BlockType blockType, String data) {
IBlockData blockData;
net.minecraft.world.level.block.state.BlockState blockData;
Block block = blockType == null ? null : ((CraftBlockType<?>) blockType).getHandle();
Map<IBlockState<?>, Comparable<?>> parsed = null;
Map<Property<?>, Comparable<?>> parsed = null;
// Data provided, use it
if (data != null) {
@@ -564,7 +562,7 @@ public class CraftBlockData implements BlockData {
}
StringReader reader = new StringReader(data);
ArgumentBlock.a arg = ArgumentBlock.parseForBlock(CraftRegistry.getMinecraftRegistry(Registries.BLOCK), reader, false);
BlockStateParser.BlockResult arg = BlockStateParser.parseForBlock(CraftRegistry.getMinecraftRegistry(Registries.BLOCK), reader, false);
Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data: " + data);
blockData = arg.blockState();
@@ -576,33 +574,33 @@ public class CraftBlockData implements BlockData {
blockData = block.defaultBlockState();
}
CraftBlockData craft = fromData(blockData);
CraftBlockData craft = CraftBlockData.fromData(blockData);
craft.parsedStates = parsed;
return craft;
}
public static CraftBlockData fromData(IBlockData data) {
return MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
public static CraftBlockData fromData(net.minecraft.world.level.block.state.BlockState data) {
return CraftBlockData.MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
}
@Override
public SoundGroup getSoundGroup() {
return CraftSoundGroup.getSoundGroup(state.getSoundType());
return CraftSoundGroup.getSoundGroup(this.state.getSoundType());
}
@Override
public int getLightEmission() {
return state.getLightEmission();
return this.state.getLightEmission();
}
@Override
public boolean isOccluding() {
return state.canOcclude();
return this.state.canOcclude();
}
@Override
public boolean requiresCorrectToolForDrops() {
return state.requiresCorrectToolForDrops();
return this.state.requiresCorrectToolForDrops();
}
@Override
@@ -610,16 +608,16 @@ public class CraftBlockData implements BlockData {
Preconditions.checkArgument(tool != null, "tool must not be null");
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(tool);
return isPreferredTool(state, nms);
return CraftBlockData.isPreferredTool(this.state, nms);
}
public static boolean isPreferredTool(IBlockData iblockdata, net.minecraft.world.item.ItemStack nmsItem) {
public static boolean isPreferredTool(net.minecraft.world.level.block.state.BlockState iblockdata, net.minecraft.world.item.ItemStack nmsItem) {
return !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata);
}
@Override
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(state.getPistonPushReaction().ordinal());
return PistonMoveReaction.getById(this.state.getPistonPushReaction().ordinal());
}
@Override
@@ -627,7 +625,7 @@ public class CraftBlockData implements BlockData {
Preconditions.checkArgument(block != null, "block must not be null");
CraftBlock craftBlock = (CraftBlock) block;
return state.canSurvive(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition());
return this.state.canSurvive(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition());
}
@Override
@@ -637,8 +635,8 @@ public class CraftBlockData implements BlockData {
CraftWorld world = (CraftWorld) location.getWorld();
Preconditions.checkArgument(world != null, "location must not have a null world");
BlockPosition position = CraftLocation.toBlockPosition(location);
return state.canSurvive(world.getHandle(), position);
BlockPos position = CraftLocation.toBlockPosition(location);
return this.state.canSurvive(world.getHandle(), position);
}
@Override
@@ -646,43 +644,43 @@ public class CraftBlockData implements BlockData {
Preconditions.checkArgument(face != null, "face must not be null");
Preconditions.checkArgument(support != null, "support must not be null");
return state.isFaceSturdy(BlockAccessAir.INSTANCE, BlockPosition.ZERO, CraftBlock.blockFaceToNotch(face), CraftBlockSupport.toNMS(support));
return this.state.isFaceSturdy(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, CraftBlock.blockFaceToNotch(face), CraftBlockSupport.toNMS(support));
}
@Override
public Color getMapColor() {
return Color.fromRGB(state.getMapColor(null, null).col);
return Color.fromRGB(this.state.getMapColor(null, null).col);
}
@Override
public Material getPlacementMaterial() {
return CraftItemType.minecraftToBukkit(state.getBlock().asItem());
return CraftItemType.minecraftToBukkit(this.state.getBlock().asItem());
}
@Override
public void rotate(StructureRotation rotation) {
this.state = state.rotate(EnumBlockRotation.valueOf(rotation.name()));
this.state = this.state.rotate(Rotation.valueOf(rotation.name()));
}
@Override
public void mirror(Mirror mirror) {
this.state = state.mirror(EnumBlockMirror.valueOf(mirror.name()));
this.state = this.state.mirror(net.minecraft.world.level.block.Mirror.valueOf(mirror.name()));
}
@Override
public void copyTo(BlockData blockData) {
CraftBlockData other = (CraftBlockData) blockData;
IBlockData nms = other.state;
for (IBlockState<?> property : state.getBlock().getStateDefinition().getProperties()) {
net.minecraft.world.level.block.state.BlockState nms = other.state;
for (Property<?> property : this.state.getBlock().getStateDefinition().getProperties()) {
if (nms.hasProperty(property)) {
nms = copyProperty(state, nms, property);
nms = this.copyProperty(this.state, nms, property);
}
}
other.state = nms;
}
private <T extends Comparable<T>> IBlockData copyProperty(IBlockData source, IBlockData target, IBlockState<T> property) {
private <T extends Comparable<T>> net.minecraft.world.level.block.state.BlockState copyProperty(net.minecraft.world.level.block.state.BlockState source, net.minecraft.world.level.block.state.BlockState target, Property<T> property) {
return target.setValue(property, source.getValue(property));
}

View File

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

View File

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

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