mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 17:52:28 +01:00
#1250: Standardize and centralize Bukkit / Minecraft registry conversion
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
0b9699cc2e
commit
4248b8a4d8
47 changed files with 468 additions and 252 deletions
|
@ -19,12 +19,12 @@
|
|||
}).ifPresent((villagerprofession) -> {
|
||||
- entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(villagerprofession));
|
||||
+ // CraftBukkit start - Fire VillagerCareerChangeEvent where Villager gets employed
|
||||
+ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.nmsToBukkitProfession(villagerprofession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED);
|
||||
+ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.CraftProfession.minecraftToBukkit(villagerprofession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED);
|
||||
+ if (event.isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(event.getProfession())));
|
||||
+ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.CraftProfession.bukkitToMinecraft(event.getProfession())));
|
||||
+ // CraftBukkit end
|
||||
entityvillager.refreshBrain(worldserver);
|
||||
});
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
if (villagerdata.getProfession() != VillagerProfession.NONE && villagerdata.getProfession() != VillagerProfession.NITWIT && entityvillager.getVillagerXp() == 0 && villagerdata.getLevel() <= 1) {
|
||||
- entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(VillagerProfession.NONE));
|
||||
+ // CraftBukkit start
|
||||
+ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.nmsToBukkitProfession(VillagerProfession.NONE), VillagerCareerChangeEvent.ChangeReason.LOSING_JOB);
|
||||
+ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.CraftProfession.minecraftToBukkit(VillagerProfession.NONE), VillagerCareerChangeEvent.ChangeReason.LOSING_JOB);
|
||||
+ if (event.isCancelled()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(event.getProfession())));
|
||||
+ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.CraftProfession.bukkitToMinecraft(event.getProfession())));
|
||||
+ // CraftBukkit end
|
||||
entityvillager.refreshBrain(worldserver);
|
||||
return true;
|
||||
|
|
|
@ -1,35 +1,48 @@
|
|||
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.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
||||
public class CraftArt {
|
||||
private static final BiMap<Holder<PaintingVariant>, Art> artwork;
|
||||
|
||||
static {
|
||||
ImmutableBiMap.Builder<Holder<PaintingVariant>, Art> artworkBuilder = ImmutableBiMap.builder();
|
||||
for (ResourceKey<PaintingVariant> key : BuiltInRegistries.PAINTING_VARIANT.registryKeySet()) {
|
||||
artworkBuilder.put(BuiltInRegistries.PAINTING_VARIANT.getHolderOrThrow(key), Art.getByName(key.location().getPath()));
|
||||
}
|
||||
public static Art minecraftToBukkit(PaintingVariant minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
artwork = artworkBuilder.build();
|
||||
}
|
||||
IRegistry<PaintingVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT);
|
||||
Art bukkit = Registry.ART.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
public static Art NotchToBukkit(Holder<PaintingVariant> art) {
|
||||
Art bukkit = artwork.get(art);
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static Holder<PaintingVariant> BukkitToNotch(Art art) {
|
||||
Holder<PaintingVariant> nms = artwork.inverse().get(art);
|
||||
Preconditions.checkArgument(nms != null);
|
||||
return nms;
|
||||
public static Art minecraftHolderToBukkit(Holder<PaintingVariant> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static PaintingVariant bukkitToMinecraft(Art bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<PaintingVariant> bukkitToMinecraftHolder(Art bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<PaintingVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<PaintingVariant> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own painting variant with out properly registering it.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.bukkit.block.Biome;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -279,7 +280,7 @@ public class CraftChunk implements Chunk {
|
|||
Preconditions.checkArgument(biome != null, "Biome cannot be null");
|
||||
|
||||
IChunkAccess chunk = getHandle(ChunkStatus.BIOMES);
|
||||
Predicate<Holder<BiomeBase>> nms = Predicates.equalTo(CraftBlock.biomeToBiomeBase(chunk.biomeRegistry, biome));
|
||||
Predicate<Holder<BiomeBase>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section != null && section.getBiomes().maybeHas(nms)) {
|
||||
return true;
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.bukkit.ChunkSnapshot;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
|
|||
public boolean contains(Biome biome) {
|
||||
Preconditions.checkArgument(biome != null, "Biome cannot be null");
|
||||
|
||||
Predicate<Holder<BiomeBase>> nms = Predicates.equalTo(CraftBlock.biomeToBiomeBase(this.biomeRegistry, biome));
|
||||
Predicate<Holder<BiomeBase>> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome));
|
||||
for (PalettedContainerRO<Holder<BiomeBase>> palette : this.biome) {
|
||||
if (palette.maybeHas(nms)) {
|
||||
return true;
|
||||
|
@ -151,7 +151,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
|
|||
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 CraftBlock.biomeBaseToBiome(biomeRegistry, biome.get(x >> 2, (y & 0xF) >> 2, z >> 2));
|
||||
return CraftBiome.minecraftHolderToBukkit(biome.get(x >> 2, (y & 0xF) >> 2, z >> 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.level.material.FluidType;
|
||||
import org.bukkit.Fluid;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
||||
public class CraftFluid {
|
||||
|
||||
public static Fluid minecraftToBukkit(FluidType minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<FluidType> registry = CraftRegistry.getMinecraftRegistry(Registries.FLUID);
|
||||
Fluid bukkit = Registry.FLUID.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static FluidType bukkitToMinecraft(Fluid bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.FLUID)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
|
@ -229,11 +229,7 @@ public enum CraftParticle {
|
|||
throw new IllegalArgumentException(particle.getDataType().toString());
|
||||
}
|
||||
|
||||
public static Particle toBukkit(net.minecraft.core.particles.ParticleParam nms) {
|
||||
return toBukkit(nms.getType());
|
||||
}
|
||||
|
||||
public static Particle toBukkit(net.minecraft.core.particles.Particle nms) {
|
||||
return particles.inverse().get(BuiltInRegistries.PARTICLE_TYPE.getKey(nms));
|
||||
public static Particle minecraftToBukkit(net.minecraft.core.particles.Particle<?> minecraft) {
|
||||
return particles.inverse().get(BuiltInRegistries.PARTICLE_TYPE.getKey(minecraft));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ import org.bukkit.block.Biome;
|
|||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
|
@ -231,7 +232,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
|||
|
||||
@Override
|
||||
public Biome getBiome(int x, int y, int z) {
|
||||
return CraftBlock.biomeBaseToBiome(getHandle().registryAccess().registryOrThrow(Registries.BIOME), getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
|
||||
return CraftBiome.minecraftHolderToBukkit(getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,7 +243,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
|||
@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 = CraftBlock.biomeToBiomeBase(getHandle().registryAccess().registryOrThrow(Registries.BIOME), biome);
|
||||
Holder<BiomeBase> biomeBase = CraftBiome.bukkitToMinecraftHolder(biome);
|
||||
setBiome(x, y, z, biomeBase);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.sounds.SoundEffect;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Sound;
|
||||
|
@ -10,21 +11,34 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
|||
|
||||
public class CraftSound {
|
||||
|
||||
public static SoundEffect getSoundEffect(String s) {
|
||||
SoundEffect effect = BuiltInRegistries.SOUND_EVENT.get(new MinecraftKey(s));
|
||||
Preconditions.checkArgument(effect != null, "Sound effect %s does not exist", s);
|
||||
public static Sound minecraftToBukkit(SoundEffect minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
return effect;
|
||||
IRegistry<SoundEffect> registry = CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT);
|
||||
Sound bukkit = Registry.SOUNDS.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static SoundEffect getSoundEffect(Sound s) {
|
||||
SoundEffect effect = BuiltInRegistries.SOUND_EVENT.get(CraftNamespacedKey.toMinecraft(s.getKey()));
|
||||
Preconditions.checkArgument(effect != null, "Sound effect %s does not exist", s);
|
||||
public static SoundEffect bukkitToMinecraft(Sound bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return effect;
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Sound getBukkit(SoundEffect soundEffect) {
|
||||
return Registry.SOUNDS.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.SOUND_EVENT.getKey(soundEffect)));
|
||||
public static Holder<SoundEffect> bukkitToMinecraftHolder(Sound bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<SoundEffect> registry = CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<SoundEffect> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own sound effect with out properly registering it.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,26 +34,26 @@ public class CraftSoundGroup implements SoundGroup {
|
|||
|
||||
@Override
|
||||
public Sound getBreakSound() {
|
||||
return CraftSound.getBukkit(getHandle().breakSound);
|
||||
return CraftSound.minecraftToBukkit(getHandle().breakSound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getStepSound() {
|
||||
return CraftSound.getBukkit(getHandle().getStepSound());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getStepSound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getPlaceSound() {
|
||||
return CraftSound.getBukkit(getHandle().getPlaceSound());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getPlaceSound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getHitSound() {
|
||||
return CraftSound.getBukkit(getHandle().hitSound);
|
||||
return CraftSound.minecraftToBukkit(getHandle().hitSound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getFallSound() {
|
||||
return CraftSound.getBukkit(getHandle().getFallSound());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getFallSound());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.world.level.block.Block;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.Statistic.Type;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
@ -171,7 +172,7 @@ public enum CraftStatistic {
|
|||
public static net.minecraft.stats.Statistic getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {
|
||||
Preconditions.checkArgument(entity != null, "EntityType cannot be null");
|
||||
if (entity.getName() != null) {
|
||||
EntityTypes<?> nmsEntity = BuiltInRegistries.ENTITY_TYPE.get(new MinecraftKey(entity.getName()));
|
||||
EntityTypes<?> nmsEntity = CraftEntityType.bukkitToMinecraft(entity);
|
||||
|
||||
if (stat == org.bukkit.Statistic.KILL_ENTITY) {
|
||||
return net.minecraft.stats.StatisticList.ENTITY_KILLED.get(nmsEntity);
|
||||
|
@ -185,8 +186,7 @@ public enum CraftStatistic {
|
|||
|
||||
public static EntityType getEntityTypeFromStatistic(net.minecraft.stats.Statistic<EntityTypes<?>> statistic) {
|
||||
Preconditions.checkArgument(statistic != null, "NMS Statistic cannot be null");
|
||||
MinecraftKey name = EntityTypes.getKey(statistic.getValue());
|
||||
return EntityType.fromName(name.getPath());
|
||||
return CraftEntityType.minecraftToBukkit(statistic.getValue());
|
||||
}
|
||||
|
||||
public static Material getMaterialFromStatistic(net.minecraft.stats.Statistic<?> statistic) {
|
||||
|
|
|
@ -1556,7 +1556,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|||
double y = loc.getY();
|
||||
double z = loc.getZ();
|
||||
|
||||
getHandle().playSound(null, x, y, z, CraftSound.getSoundEffect(sound), SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
getHandle().playSound(null, x, y, z, CraftSound.bukkitToMinecraft(sound), SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1585,7 +1585,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|||
public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
|
||||
|
||||
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
PlayerChunkMap.EntityTracker entityTracker = getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
|
||||
if (entityTracker != null) {
|
||||
entityTracker.broadcastAndSend(packet);
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package org.bukkit.craftbukkit.attribute;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
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;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
||||
public class CraftAttribute {
|
||||
|
||||
public static Attribute minecraftToBukkit(AttributeBase minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<AttributeBase> registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE);
|
||||
Attribute bukkit = Registry.ATTRIBUTE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static Attribute stringToBukkit(String bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return Registry.ATTRIBUTE.get(NamespacedKey.fromString(bukkit));
|
||||
}
|
||||
|
||||
public static AttributeBase bukkitToMinecraft(Attribute bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
|
@ -1,14 +1,10 @@
|
|||
package org.bukkit.craftbukkit.attribute;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeBase;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeMapBase;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.attribute.Attributable;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
||||
public class CraftAttributeMap implements Attributable {
|
||||
|
||||
|
@ -21,16 +17,8 @@ public class CraftAttributeMap implements Attributable {
|
|||
@Override
|
||||
public AttributeInstance getAttribute(Attribute attribute) {
|
||||
Preconditions.checkArgument(attribute != null, "attribute");
|
||||
net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(toMinecraft(attribute));
|
||||
net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(CraftAttribute.bukkitToMinecraft(attribute));
|
||||
|
||||
return (nms == null) ? null : new CraftAttributeInstance(nms, attribute);
|
||||
}
|
||||
|
||||
public static AttributeBase toMinecraft(Attribute attribute) {
|
||||
return BuiltInRegistries.ATTRIBUTE.get(CraftNamespacedKey.toMinecraft(attribute.getKey()));
|
||||
}
|
||||
|
||||
public static Attribute fromMinecraft(String nms) {
|
||||
return Registry.ATTRIBUTE.get(CraftNamespacedKey.fromString(nms));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
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.level.biome.BiomeBase;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
||||
public class CraftBiome {
|
||||
|
||||
public static Biome minecraftToBukkit(BiomeBase minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<BiomeBase> registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME);
|
||||
Biome bukkit = Registry.BIOME.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
if (bukkit == null) {
|
||||
return Biome.CUSTOM;
|
||||
}
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static Biome minecraftHolderToBukkit(Holder<BiomeBase> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static BiomeBase bukkitToMinecraft(Biome bukkit) {
|
||||
if (bukkit == null || bukkit == Biome.CUSTOM) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.BIOME)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<BiomeBase> bukkitToMinecraftHolder(Biome bukkit) {
|
||||
if (bukkit == null || bukkit == Biome.CUSTOM) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IRegistry<BiomeBase> registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<BiomeBase> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own biome base with out properly registering it.");
|
||||
}
|
||||
}
|
|
@ -8,10 +8,6 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.EnumDirection;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.EnumHand;
|
||||
import net.minecraft.world.EnumInteractionResult;
|
||||
|
@ -21,7 +17,6 @@ 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.biome.BiomeBase;
|
||||
import net.minecraft.world.level.block.BlockRedstoneWire;
|
||||
import net.minecraft.world.level.block.BlockSapling;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
@ -36,7 +31,6 @@ import org.bukkit.Chunk;
|
|||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
@ -53,7 +47,6 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
|
||||
import org.bukkit.craftbukkit.util.CraftVoxelShape;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -345,27 +338,6 @@ public class CraftBlock implements Block {
|
|||
getWorld().setBiome(getX(), getY(), getZ(), bio);
|
||||
}
|
||||
|
||||
public static Biome biomeBaseToBiome(IRegistry<BiomeBase> registry, Holder<BiomeBase> base) {
|
||||
return biomeBaseToBiome(registry, base.value());
|
||||
}
|
||||
|
||||
public static Biome biomeBaseToBiome(IRegistry<BiomeBase> registry, BiomeBase base) {
|
||||
if (base == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Biome biome = Registry.BIOME.get(CraftNamespacedKey.fromMinecraft(registry.getKey(base)));
|
||||
return (biome == null) ? Biome.CUSTOM : biome;
|
||||
}
|
||||
|
||||
public static Holder<BiomeBase> biomeToBiomeBase(IRegistry<BiomeBase> registry, Biome bio) {
|
||||
if (bio == null || bio == Biome.CUSTOM) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(bio.getKey())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperature() {
|
||||
return world.getBiome(position).value().getTemperature(position);
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.world.level.MobSpawnerData;
|
|||
import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpawner> implements CreatureSpawner {
|
||||
|
@ -25,7 +26,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
|
|||
}
|
||||
|
||||
Optional<EntityTypes<?>> type = EntityTypes.by(spawnData.getEntityToSpawn());
|
||||
return type.map(entityTypes -> EntityType.fromName(EntityTypes.getKey(entityTypes).getPath())).orElse(null);
|
||||
return type.map(CraftEntityType::minecraftToBukkit).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,7 +39,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
|
|||
Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "Can't spawn EntityType %s from mob spawners!", entityType);
|
||||
|
||||
RandomSource rand = (this.isPlaced()) ? this.getWorldHandle().getRandom() : RandomSource.create();
|
||||
this.getSnapshot().setEntityId(EntityTypes.byString(entityType.getName()).get(), rand);
|
||||
this.getSnapshot().setEntityId(CraftEntityType.bukkitToMinecraft(entityType), rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -110,7 +110,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
|||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return CraftParticle.toBukkit(getHandle().getParticle());
|
||||
return CraftParticle.minecraftToBukkit(getHandle().getParticle().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.animal.CatVariant;
|
||||
import net.minecraft.world.entity.animal.EntityCat;
|
||||
import net.minecraft.world.item.EnumColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.Cat.Type;
|
||||
|
||||
public class CraftCat extends CraftTameableAnimal implements Cat {
|
||||
|
||||
|
@ -27,14 +29,14 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
|
|||
|
||||
@Override
|
||||
public Type getCatType() {
|
||||
return Type.values()[BuiltInRegistries.CAT_VARIANT.getId(getHandle().getVariant())];
|
||||
return CraftType.minecraftToBukkit(getHandle().getVariant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatType(Type type) {
|
||||
Preconditions.checkArgument(type != null, "Cannot have null Type");
|
||||
|
||||
getHandle().setVariant(BuiltInRegistries.CAT_VARIANT.byId(type.ordinal()));
|
||||
getHandle().setVariant(CraftType.bukkitToMinecraft(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,4 +48,22 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
|
|||
public void setCollarColor(DyeColor color) {
|
||||
getHandle().setCollarColor(EnumColor.byId(color.getWoolData()));
|
||||
}
|
||||
|
||||
public static class CraftType {
|
||||
|
||||
public static Type minecraftToBukkit(CatVariant minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<CatVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT);
|
||||
|
||||
return Type.values()[registry.getId(minecraft)];
|
||||
}
|
||||
|
||||
public static CatVariant bukkitToMinecraft(Type bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT)
|
||||
.byId(bukkit.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,8 +210,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|||
public CraftEntity(final CraftServer server, final Entity entity) {
|
||||
this.server = server;
|
||||
this.entity = entity;
|
||||
EntityType type = Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(EntityTypes.getKey(entity.getType())));
|
||||
this.entityType = (type != null) ? type : EntityType.UNKNOWN;
|
||||
this.entityType = CraftEntityType.minecraftToBukkit(entity.getType());
|
||||
}
|
||||
|
||||
public static CraftEntity getEntity(CraftServer server, Entity entity) {
|
||||
|
@ -778,17 +777,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|||
|
||||
@Override
|
||||
public Sound getSwimSound() {
|
||||
return CraftSound.getBukkit(getHandle().getSwimSound0());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getSwimSound0());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getSwimSplashSound() {
|
||||
return CraftSound.getBukkit(getHandle().getSwimSplashSound0());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getSwimSplashSound0());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getSwimHighSpeedSplashSound() {
|
||||
return CraftSound.getBukkit(getHandle().getSwimHighSpeedSplashSound0());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getSwimHighSpeedSplashSound0());
|
||||
}
|
||||
|
||||
public void setHandle(final Entity entity) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class CraftEntityType {
|
||||
|
||||
public static EntityType minecraftToBukkit(EntityTypes<?> minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<EntityTypes<?>> registry = CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE);
|
||||
EntityType bukkit = Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static EntityTypes<?> bukkitToMinecraft(EntityType bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.animal.FrogVariant;
|
||||
import net.minecraft.world.entity.animal.frog.Frog;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -40,13 +43,34 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
|
|||
|
||||
@Override
|
||||
public Variant getVariant() {
|
||||
return Registry.FROG_VARIANT.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.FROG_VARIANT.getKey(getHandle().getVariant())));
|
||||
return CraftVariant.minecraftToBukkit(getHandle().getVariant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVariant(Variant variant) {
|
||||
Preconditions.checkArgument(variant != null, "variant");
|
||||
|
||||
getHandle().setVariant(BuiltInRegistries.FROG_VARIANT.get(CraftNamespacedKey.toMinecraft(variant.getKey())));
|
||||
getHandle().setVariant(CraftVariant.bukkitToMinecraft(variant));
|
||||
}
|
||||
|
||||
public static class CraftVariant {
|
||||
|
||||
public static Variant minecraftToBukkit(FrogVariant minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<FrogVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT);
|
||||
Variant bukkit = Registry.FROG_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static FrogVariant bukkitToMinecraft(Variant bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -710,51 +710,51 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|||
|
||||
@Override
|
||||
public <T> T getMemory(MemoryKey<T> memoryKey) {
|
||||
return (T) getHandle().getBrain().getMemory(CraftMemoryKey.fromMemoryKey(memoryKey)).map(CraftMemoryMapper::fromNms).orElse(null);
|
||||
return (T) getHandle().getBrain().getMemory(CraftMemoryKey.bukkitToMinecraft(memoryKey)).map(CraftMemoryMapper::fromNms).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setMemory(MemoryKey<T> memoryKey, T t) {
|
||||
getHandle().getBrain().setMemory(CraftMemoryKey.fromMemoryKey(memoryKey), CraftMemoryMapper.toNms(t));
|
||||
getHandle().getBrain().setMemory(CraftMemoryKey.bukkitToMinecraft(memoryKey), CraftMemoryMapper.toNms(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getHurtSound() {
|
||||
SoundEffect sound = getHandle().getHurtSound0(getHandle().damageSources().generic());
|
||||
return (sound != null) ? CraftSound.getBukkit(sound) : null;
|
||||
return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getDeathSound() {
|
||||
SoundEffect sound = getHandle().getDeathSound0();
|
||||
return (sound != null) ? CraftSound.getBukkit(sound) : null;
|
||||
return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getFallDamageSound(int fallHeight) {
|
||||
return CraftSound.getBukkit(getHandle().getFallDamageSound0(fallHeight));
|
||||
return CraftSound.minecraftToBukkit(getHandle().getFallDamageSound0(fallHeight));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getFallDamageSoundSmall() {
|
||||
return CraftSound.getBukkit(getHandle().getFallSounds().small());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getFallSounds().small());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getFallDamageSoundBig() {
|
||||
return CraftSound.getBukkit(getHandle().getFallSounds().big());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getFallSounds().big());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getDrinkingSound(ItemStack itemStack) {
|
||||
Preconditions.checkArgument(itemStack != null, "itemStack must not be null");
|
||||
return CraftSound.getBukkit(getHandle().getDrinkingSound0(CraftItemStack.asNMSCopy(itemStack)));
|
||||
return CraftSound.minecraftToBukkit(getHandle().getDrinkingSound0(CraftItemStack.asNMSCopy(itemStack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getEatingSound(ItemStack itemStack) {
|
||||
Preconditions.checkArgument(itemStack != null, "itemStack must not be null");
|
||||
return CraftSound.getBukkit(getHandle().getEatingSound0(CraftItemStack.asNMSCopy(itemStack)));
|
||||
return CraftSound.minecraftToBukkit(getHandle().getEatingSound0(CraftItemStack.asNMSCopy(itemStack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
|
|||
@Override
|
||||
public Sound getAmbientSound() {
|
||||
SoundEffect sound = getHandle().getAmbientSound0();
|
||||
return (sound != null) ? CraftSound.getBukkit(sound) : null;
|
||||
return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,8 +17,7 @@ public class CraftPainting extends CraftHanging implements Painting {
|
|||
|
||||
@Override
|
||||
public Art getArt() {
|
||||
Holder<PaintingVariant> art = getHandle().getVariant();
|
||||
return CraftArt.NotchToBukkit(art);
|
||||
return CraftArt.minecraftHolderToBukkit(getHandle().getVariant());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +29,7 @@ public class CraftPainting extends CraftHanging implements Painting {
|
|||
public boolean setArt(Art art, boolean force) {
|
||||
EntityPainting painting = this.getHandle();
|
||||
Holder<PaintingVariant> oldArt = painting.getVariant();
|
||||
painting.setVariant(CraftArt.BukkitToNotch(art));
|
||||
painting.setVariant(CraftArt.bukkitToMinecraftHolder(art));
|
||||
painting.setDirection(painting.getDirection());
|
||||
if (!force && !getHandle().generation && !painting.survives()) {
|
||||
// Revert painting since it doesn't fit
|
||||
|
|
|
@ -436,29 +436,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
String instrumentName = switch (instrument.ordinal()) {
|
||||
case 0 -> "harp";
|
||||
case 1 -> "basedrum";
|
||||
case 2 -> "snare";
|
||||
case 3 -> "hat";
|
||||
case 4 -> "bass";
|
||||
case 5 -> "flute";
|
||||
case 6 -> "bell";
|
||||
case 7 -> "guitar";
|
||||
case 8 -> "chime";
|
||||
case 9 -> "xylophone";
|
||||
case 10 -> "iron_xylophone";
|
||||
case 11 -> "cow_bell";
|
||||
case 12 -> "didgeridoo";
|
||||
case 13 -> "bit";
|
||||
case 14 -> "banjo";
|
||||
case 15 -> "pling";
|
||||
case 16 -> "xylophone";
|
||||
Sound instrumentSound = switch (instrument.ordinal()) {
|
||||
case 0 -> Sound.BLOCK_NOTE_BLOCK_HARP;
|
||||
case 1 -> Sound.BLOCK_NOTE_BLOCK_BASEDRUM;
|
||||
case 2 -> Sound.BLOCK_NOTE_BLOCK_SNARE;
|
||||
case 3 -> Sound.BLOCK_NOTE_BLOCK_HAT;
|
||||
case 4 -> Sound.BLOCK_NOTE_BLOCK_BASS;
|
||||
case 5 -> Sound.BLOCK_NOTE_BLOCK_FLUTE;
|
||||
case 6 -> Sound.BLOCK_NOTE_BLOCK_BELL;
|
||||
case 7 -> Sound.BLOCK_NOTE_BLOCK_GUITAR;
|
||||
case 8 -> Sound.BLOCK_NOTE_BLOCK_CHIME;
|
||||
case 9 -> Sound.BLOCK_NOTE_BLOCK_XYLOPHONE;
|
||||
case 10 -> Sound.BLOCK_NOTE_BLOCK_IRON_XYLOPHONE;
|
||||
case 11 -> Sound.BLOCK_NOTE_BLOCK_COW_BELL;
|
||||
case 12 -> Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO;
|
||||
case 13 -> Sound.BLOCK_NOTE_BLOCK_BIT;
|
||||
case 14 -> Sound.BLOCK_NOTE_BLOCK_BANJO;
|
||||
case 15 -> Sound.BLOCK_NOTE_BLOCK_PLING;
|
||||
case 16 -> Sound.BLOCK_NOTE_BLOCK_XYLOPHONE;
|
||||
default -> null;
|
||||
};
|
||||
|
||||
float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D);
|
||||
getHandle().connection.send(new PacketPlayOutNamedSoundEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect("block.note_block." + instrumentName)), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong()));
|
||||
getHandle().connection.send(new PacketPlayOutNamedSoundEffect(CraftSound.bukkitToMinecraftHolder(instrumentSound), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -475,7 +475,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (loc == null || sound == null || category == null || getHandle().connection == null) return;
|
||||
|
||||
playSound0(loc, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
playSound0(loc, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -508,7 +508,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return;
|
||||
|
||||
playSound0(entity, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
playSound0(entity, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,6 +106,6 @@ public abstract class CraftRaider extends CraftMonster implements Raider {
|
|||
|
||||
@Override
|
||||
public Sound getCelebrationSound() {
|
||||
return CraftSound.getBukkit(getHandle().getCelebrateSound());
|
||||
return CraftSound.minecraftToBukkit(getHandle().getCelebrateSound());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.monster.EntityZombie;
|
||||
import net.minecraft.world.entity.monster.EntityZombieVillager;
|
||||
import net.minecraft.world.entity.npc.EntityVillager;
|
||||
import net.minecraft.world.entity.npc.VillagerProfession;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import net.minecraft.world.level.block.BlockBed;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
@ -43,24 +46,24 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
|||
|
||||
@Override
|
||||
public Profession getProfession() {
|
||||
return CraftVillager.nmsToBukkitProfession(getHandle().getVillagerData().getProfession());
|
||||
return CraftProfession.minecraftToBukkit(getHandle().getVillagerData().getProfession());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProfession(Profession profession) {
|
||||
Preconditions.checkArgument(profession != null, "Profession cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(profession)));
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftProfession.bukkitToMinecraft(profession)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getVillagerType() {
|
||||
return Type.valueOf(BuiltInRegistries.VILLAGER_TYPE.getKey(getHandle().getVillagerData().getType()).getPath().toUpperCase(Locale.ROOT));
|
||||
return CraftType.minecraftToBukkit(getHandle().getVillagerData().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVillagerType(Type type) {
|
||||
Preconditions.checkArgument(type != null, "Type cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setType(BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()))));
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setType(CraftType.bukkitToMinecraft(type)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,11 +126,45 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
|||
return (entityzombievillager != null) ? (ZombieVillager) entityzombievillager.getBukkitEntity() : null;
|
||||
}
|
||||
|
||||
public static Profession nmsToBukkitProfession(VillagerProfession nms) {
|
||||
return Profession.valueOf(BuiltInRegistries.VILLAGER_PROFESSION.getKey(nms).getPath().toUpperCase(Locale.ROOT));
|
||||
public static class CraftType {
|
||||
|
||||
public static Type minecraftToBukkit(VillagerType minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<VillagerType> registry = CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_TYPE);
|
||||
Type bukkit = Registry.VILLAGER_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static VillagerType bukkitToMinecraft(Type bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_TYPE)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
||||
|
||||
public static VillagerProfession bukkitToNmsProfession(Profession bukkit) {
|
||||
return BuiltInRegistries.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(bukkit.getKey()));
|
||||
public static class CraftProfession {
|
||||
|
||||
public static Profession minecraftToBukkit(VillagerProfession minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<VillagerProfession> registry = CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_PROFESSION);
|
||||
Profession bukkit = Registry.VILLAGER_PROFESSION.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static VillagerProfession bukkitToMinecraft(Profession bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_PROFESSION)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.monster.EntityZombieVillager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.ZombieVillager;
|
||||
|
||||
|
@ -31,24 +27,24 @@ public class CraftVillagerZombie extends CraftZombie implements ZombieVillager {
|
|||
|
||||
@Override
|
||||
public Villager.Profession getVillagerProfession() {
|
||||
return Villager.Profession.valueOf(BuiltInRegistries.VILLAGER_PROFESSION.getKey(getHandle().getVillagerData().getProfession()).getPath().toUpperCase(Locale.ROOT));
|
||||
return CraftVillager.CraftProfession.minecraftToBukkit(getHandle().getVillagerData().getProfession());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVillagerProfession(Villager.Profession profession) {
|
||||
Preconditions.checkArgument(profession != null, "Villager.Profession cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setProfession(BuiltInRegistries.VILLAGER_PROFESSION.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT)))));
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftVillager.CraftProfession.bukkitToMinecraft(profession)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Villager.Type getVillagerType() {
|
||||
return Villager.Type.valueOf(BuiltInRegistries.VILLAGER_TYPE.getKey(getHandle().getVillagerData().getType()).getPath().toUpperCase(Locale.ROOT));
|
||||
return CraftVillager.CraftType.minecraftToBukkit(getHandle().getVillagerData().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVillagerType(Villager.Type type) {
|
||||
Preconditions.checkArgument(type != null, "Villager.Type cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setType(BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()))));
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setType(CraftVillager.CraftType.bukkitToMinecraft(type)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.bukkit.craftbukkit.entity.memory;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.memory.MemoryKey;
|
||||
|
||||
|
@ -9,11 +13,23 @@ public final class CraftMemoryKey {
|
|||
|
||||
private CraftMemoryKey() {}
|
||||
|
||||
public static <T, U> MemoryModuleType<U> fromMemoryKey(MemoryKey<T> memoryKey) {
|
||||
return (MemoryModuleType<U>) BuiltInRegistries.MEMORY_MODULE_TYPE.get(CraftNamespacedKey.toMinecraft(memoryKey.getKey()));
|
||||
public static <T, U> MemoryKey<U> minecraftToBukkit(MemoryModuleType<T> minecraft) {
|
||||
if (minecraft == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IRegistry<MemoryModuleType<?>> registry = CraftRegistry.getMinecraftRegistry(Registries.MEMORY_MODULE_TYPE);
|
||||
MemoryKey<U> bukkit = Registry.MEMORY_MODULE_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static <T, U> MemoryKey<U> toMemoryKey(MemoryModuleType<T> memoryModuleType) {
|
||||
return MemoryKey.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType)));
|
||||
public static <T, U> MemoryModuleType<U> bukkitToMinecraft(MemoryKey<T> bukkit) {
|
||||
if (bukkit == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (MemoryModuleType<U>) CraftRegistry.getMinecraftRegistry(Registries.MEMORY_MODULE_TYPE)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
@ -60,7 +60,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
|
|||
|
||||
@Override
|
||||
public Biome getBiome(int x, int y, int z) {
|
||||
return CraftBlock.biomeBaseToBiome(getHandle().biomeRegistry, getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
|
||||
return CraftBiome.minecraftHolderToBukkit(getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,7 @@ import net.minecraft.world.level.levelgen.blending.Blender;
|
|||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.CraftHeightMap;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
@ -76,13 +76,13 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
|
|||
|
||||
@Override
|
||||
public Biome getBiome(int x, int y, int z) {
|
||||
return CraftBlock.biomeBaseToBiome(biome.biomeRegistry, biome.getNoiseBiome(x >> 2, y >> 2, z >> 2));
|
||||
return CraftBiome.minecraftHolderToBukkit(biome.getNoiseBiome(x >> 2, y >> 2, z >> 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int y, int z, Biome bio) {
|
||||
Preconditions.checkArgument(bio != Biome.CUSTOM, "Cannot set the biome to %s", bio);
|
||||
biome.setBiome(x >> 2, y >> 2, z >> 2, CraftBlock.biomeToBiomeBase(biome.biomeRegistry, bio));
|
||||
biome.setBiome(x >> 2, y >> 2, z >> 2, CraftBiome.bukkitToMinecraftHolder(bio));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import net.minecraft.world.level.biome.BiomeBase;
|
|||
import net.minecraft.world.level.biome.Climate;
|
||||
import net.minecraft.world.level.biome.WorldChunkManager;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class CustomWorldChunkManager extends WorldChunkManager {
|
|||
|
||||
for (Biome biome : biomes) {
|
||||
Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome);
|
||||
biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome));
|
||||
biomeBases.add(CraftBiome.bukkitToMinecraftHolder(biome));
|
||||
}
|
||||
|
||||
return biomeBases;
|
||||
|
@ -48,7 +48,7 @@ public class CustomWorldChunkManager extends WorldChunkManager {
|
|||
Biome biome = biomeProvider.getBiome(worldInfo, x << 2, y << 2, z << 2, CraftBiomeParameterPoint.createBiomeParameterPoint(sampler, sampler.sample(x, y, z)));
|
||||
Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot set the biome to %s", biome);
|
||||
|
||||
return CraftBlock.biomeToBiomeBase(registry, biome);
|
||||
return CraftBiome.bukkitToMinecraftHolder(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.bukkit.craftbukkit.generator.structure;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.IRegistryCustom;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.generator.structure.Structure;
|
||||
import org.bukkit.generator.structure.StructureType;
|
||||
|
@ -11,17 +14,18 @@ import org.bukkit.generator.structure.StructureType;
|
|||
public class CraftStructure extends Structure {
|
||||
|
||||
public static Structure minecraftToBukkit(net.minecraft.world.level.levelgen.structure.Structure minecraft, IRegistryCustom registryHolder) {
|
||||
if (minecraft == null) {
|
||||
return null;
|
||||
}
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
return Registry.STRUCTURE.get(CraftNamespacedKey.fromMinecraft(registryHolder.registryOrThrow(Registries.STRUCTURE).getKey(minecraft)));
|
||||
IRegistry<net.minecraft.world.level.levelgen.structure.Structure> registry = CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE);
|
||||
Structure bukkit = Registry.STRUCTURE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static net.minecraft.world.level.levelgen.structure.Structure bukkitToMinecraft(Structure bukkit) {
|
||||
if (bukkit == null) {
|
||||
return null;
|
||||
}
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return ((CraftStructure) bukkit).getHandle();
|
||||
}
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
package org.bukkit.craftbukkit.generator.structure;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.generator.structure.StructureType;
|
||||
|
||||
public class CraftStructureType extends StructureType {
|
||||
|
||||
public static StructureType minecraftToBukkit(net.minecraft.world.level.levelgen.structure.StructureType<?> minecraft) {
|
||||
if (minecraft == null) {
|
||||
return null;
|
||||
}
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
return Registry.STRUCTURE_TYPE.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.STRUCTURE_TYPE.getKey(minecraft)));
|
||||
IRegistry<net.minecraft.world.level.levelgen.structure.StructureType<?>> registry = CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE_TYPE);
|
||||
StructureType bukkit = Registry.STRUCTURE_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static net.minecraft.world.level.levelgen.structure.StructureType<?> bukkitToMinecraft(StructureType bukkit) {
|
||||
if (bukkit == null) {
|
||||
return null;
|
||||
}
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return ((CraftStructureType) bukkit).getHandle();
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import net.minecraft.world.item.ItemMonsterEgg;
|
|||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.util.CraftLegacy;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -448,7 +448,7 @@ public final class CraftItemFactory implements ItemFactory {
|
|||
if (type == EntityType.UNKNOWN) {
|
||||
return null;
|
||||
}
|
||||
EntityTypes<?> nmsType = BuiltInRegistries.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()));
|
||||
EntityTypes<?> nmsType = CraftEntityType.bukkitToMinecraft(type);
|
||||
Item nmsItem = ItemMonsterEgg.byId(nmsType);
|
||||
|
||||
if (nmsItem == null) {
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.bukkit.configuration.serialization.DelegateDeserialization;
|
|||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.Overridden;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttribute;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeInstance;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
|
@ -434,7 +435,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|||
continue;
|
||||
}
|
||||
|
||||
Attribute attribute = CraftAttributeMap.fromMinecraft(attributeName);
|
||||
Attribute attribute = CraftAttribute.stringToBukkit(attributeName);
|
||||
if (attribute == null) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import com.google.common.base.Preconditions;
|
|||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.server.packs.repository.ResourcePackLoader;
|
||||
import net.minecraft.server.packs.repository.ResourcePackRepository;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
|
@ -13,6 +11,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.packs.DataPack;
|
||||
|
@ -96,7 +95,7 @@ public class CraftDataPackManager implements DataPackManager {
|
|||
Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "EntityType.UNKNOWN its not allowed here");
|
||||
|
||||
CraftWorld craftWorld = ((CraftWorld) world);
|
||||
EntityTypes<?> nmsEntity = BuiltInRegistries.ENTITY_TYPE.get(new MinecraftKey(entityType.getKey().getKey()));
|
||||
EntityTypes<?> nmsEntity = CraftEntityType.bukkitToMinecraft(entityType);
|
||||
return nmsEntity.isEnabled(craftWorld.getHandle().enabledFeatures());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package org.bukkit.craftbukkit.tag;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class CraftEntityTag extends CraftTag<EntityTypes<?>, EntityType> {
|
||||
|
@ -20,11 +17,11 @@ public class CraftEntityTag extends CraftTag<EntityTypes<?>, EntityType> {
|
|||
|
||||
@Override
|
||||
public boolean isTagged(EntityType entity) {
|
||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(entity.getKey()))).is(tag);
|
||||
return CraftEntityType.bukkitToMinecraft(entity).is(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EntityType> getValues() {
|
||||
return getHandle().stream().map((nms) -> Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(EntityTypes.getKey(nms.value())))).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet());
|
||||
return getHandle().stream().map(Holder::value).map(CraftEntityType::minecraftToBukkit).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,12 @@ package org.bukkit.craftbukkit.tag;
|
|||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.material.FluidType;
|
||||
import org.bukkit.Fluid;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.CraftFluid;
|
||||
|
||||
public class CraftFluidTag extends CraftTag<FluidType, Fluid> {
|
||||
|
||||
|
@ -16,11 +17,11 @@ public class CraftFluidTag extends CraftTag<FluidType, Fluid> {
|
|||
|
||||
@Override
|
||||
public boolean isTagged(Fluid fluid) {
|
||||
return CraftMagicNumbers.getFluid(fluid).is(tag);
|
||||
return CraftFluid.bukkitToMinecraft(fluid).is(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Fluid> getValues() {
|
||||
return getHandle().stream().map((fluid) -> CraftMagicNumbers.getFluid(fluid.value())).collect(Collectors.toUnmodifiableSet());
|
||||
return getHandle().stream().map(Holder::value).map(CraftFluid::minecraftToBukkit).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package org.bukkit.craftbukkit.util;
|
|||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
@ -43,14 +41,11 @@ import net.minecraft.world.entity.ai.attributes.AttributeBase;
|
|||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.material.FluidType;
|
||||
import net.minecraft.world.level.storage.SavedFile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.bukkit.Fluid;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
|
@ -58,9 +53,8 @@ import org.bukkit.attribute.AttributeModifier;
|
|||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftFeatureFlag;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttribute;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeInstance;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.legacy.CraftLegacy;
|
||||
|
@ -105,7 +99,6 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
// ========================================================================
|
||||
private static final Map<Block, Material> BLOCK_MATERIAL = new HashMap<>();
|
||||
private static final Map<Item, Material> ITEM_MATERIAL = new HashMap<>();
|
||||
private static final BiMap<FluidType, Fluid> FLUIDTYPE_FLUID = HashBiMap.create();
|
||||
private static final Map<Material, Item> MATERIAL_ITEM = new HashMap<>();
|
||||
private static final Map<Material, Block> MATERIAL_BLOCK = new HashMap<>();
|
||||
|
||||
|
@ -118,11 +111,6 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
ITEM_MATERIAL.put(item, Material.getMaterial(BuiltInRegistries.ITEM.getKey(item).getPath().toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
for (FluidType fluidType : BuiltInRegistries.FLUID) {
|
||||
Fluid fluid = Registry.FLUID.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.FLUID.getKey(fluidType)));
|
||||
FLUIDTYPE_FLUID.put(fluidType, fluid);
|
||||
}
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
if (material.isLegacy()) {
|
||||
continue;
|
||||
|
@ -146,10 +134,6 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
return ITEM_MATERIAL.getOrDefault(item, Material.AIR);
|
||||
}
|
||||
|
||||
public static Fluid getFluid(FluidType fluid) {
|
||||
return FLUIDTYPE_FLUID.get(fluid);
|
||||
}
|
||||
|
||||
public static Item getItem(Material material) {
|
||||
if (material != null && material.isLegacy()) {
|
||||
material = CraftLegacy.fromLegacy(material);
|
||||
|
@ -166,10 +150,6 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
return MATERIAL_BLOCK.get(material);
|
||||
}
|
||||
|
||||
public static FluidType getFluid(Fluid fluid) {
|
||||
return FLUIDTYPE_FLUID.inverse().get(fluid);
|
||||
}
|
||||
|
||||
public static MinecraftKey key(Material mat) {
|
||||
return CraftNamespacedKey.toMinecraft(mat.getKey());
|
||||
}
|
||||
|
@ -352,7 +332,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
|
||||
Multimap<AttributeBase, net.minecraft.world.entity.ai.attributes.AttributeModifier> nmsDefaultAttributes = getItem(material).getDefaultAttributeModifiers(CraftEquipmentSlot.getNMS(slot));
|
||||
for (Entry<AttributeBase, net.minecraft.world.entity.ai.attributes.AttributeModifier> mapEntry : nmsDefaultAttributes.entries()) {
|
||||
Attribute attribute = CraftAttributeMap.fromMinecraft(BuiltInRegistries.ATTRIBUTE.getKey(mapEntry.getKey()).toString());
|
||||
Attribute attribute = CraftAttribute.minecraftToBukkit(mapEntry.getKey());
|
||||
defaultAttributes.put(attribute, CraftAttributeInstance.convert(mapEntry.getValue(), slot));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ArtTest extends AbstractTestingBase {
|
|||
int width = enumArt.value().getWidth() / UNIT_MULTIPLIER;
|
||||
int height = enumArt.value().getHeight() / UNIT_MULTIPLIER;
|
||||
|
||||
Art subject = CraftArt.NotchToBukkit(enumArt);
|
||||
Art subject = CraftArt.minecraftHolderToBukkit(enumArt);
|
||||
|
||||
String message = String.format("org.bukkit.Art is missing '%s'", name);
|
||||
assertNotNull(message, subject);
|
||||
|
@ -48,7 +48,7 @@ public class ArtTest extends AbstractTestingBase {
|
|||
public void testCraftArtToNotch() {
|
||||
Map<Holder<PaintingVariant>, Art> cache = new HashMap<>();
|
||||
for (Art art : Art.values()) {
|
||||
Holder<PaintingVariant> enumArt = CraftArt.BukkitToNotch(art);
|
||||
Holder<PaintingVariant> enumArt = CraftArt.bukkitToMinecraftHolder(art);
|
||||
assertNotNull(art.name(), enumArt);
|
||||
assertThat(art.name(), cache.put(enumArt, art), is(nullValue()));
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class ArtTest extends AbstractTestingBase {
|
|||
public void testCraftArtToBukkit() {
|
||||
Map<Art, Holder<PaintingVariant>> cache = new EnumMap(Art.class);
|
||||
for (Holder<PaintingVariant> enumArt : BuiltInRegistries.PAINTING_VARIANT.asHolderIdMap()) {
|
||||
Art art = CraftArt.NotchToBukkit(enumArt);
|
||||
Art art = CraftArt.minecraftHolderToBukkit(enumArt);
|
||||
assertNotNull("Could not CraftArt.NotchToBukkit " + enumArt, art);
|
||||
assertThat("Duplicate artwork " + enumArt, cache.put(art, enumArt), is(nullValue()));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bukkit;
|
|||
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.support.AbstractTestingBase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -16,14 +16,14 @@ public class BiomeTest extends AbstractTestingBase {
|
|||
continue;
|
||||
}
|
||||
|
||||
Assert.assertNotNull("No NMS mapping for " + biome, CraftBlock.biomeToBiomeBase(BIOMES, biome));
|
||||
Assert.assertNotNull("No NMS mapping for " + biome, CraftBiome.bukkitToMinecraftHolder(biome));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinecraftToBukkit() {
|
||||
for (BiomeBase biomeBase : BIOMES) {
|
||||
Biome biome = CraftBlock.biomeBaseToBiome(BIOMES, biomeBase);
|
||||
Biome biome = CraftBiome.minecraftToBukkit(biomeBase);
|
||||
Assert.assertTrue("No Bukkit mapping for " + biomeBase, biome != null && biome != Biome.CUSTOM);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ParticleTest extends AbstractTestingBase {
|
|||
Assert.assertNotNull("Missing Bukkit->NMS particle mapping for " + bukkit, CraftParticle.toNMS(bukkit, data));
|
||||
}
|
||||
for (net.minecraft.core.particles.Particle nms : BuiltInRegistries.PARTICLE_TYPE) {
|
||||
Assert.assertNotNull("Missing NMS->Bukkit particle mapping for " + BuiltInRegistries.PARTICLE_TYPE.getKey(nms), CraftParticle.toBukkit(nms));
|
||||
Assert.assertNotNull("Missing NMS->Bukkit particle mapping for " + BuiltInRegistries.PARTICLE_TYPE.getKey(nms), CraftParticle.minecraftToBukkit(nms));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class SoundTest extends AbstractTestingBase {
|
|||
@Test
|
||||
public void testGetSound() {
|
||||
for (Sound sound : Sound.values()) {
|
||||
assertThat(sound.name(), CraftSound.getSoundEffect(sound), is(not(nullValue())));
|
||||
assertThat(sound.name(), CraftSound.bukkitToMinecraft(sound), is(not(nullValue())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bukkit.craftbukkit.attribute;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeBase;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.support.AbstractTestingBase;
|
||||
|
@ -12,8 +11,8 @@ public class AttributeTest extends AbstractTestingBase {
|
|||
|
||||
@Test
|
||||
public void testToBukkit() {
|
||||
for (MinecraftKey nms : BuiltInRegistries.ATTRIBUTE.keySet()) {
|
||||
Attribute bukkit = CraftAttributeMap.fromMinecraft(nms.toString());
|
||||
for (AttributeBase nms : BuiltInRegistries.ATTRIBUTE) {
|
||||
Attribute bukkit = CraftAttribute.minecraftToBukkit(nms);
|
||||
|
||||
Assert.assertNotNull(nms.toString(), bukkit);
|
||||
}
|
||||
|
@ -22,7 +21,7 @@ public class AttributeTest extends AbstractTestingBase {
|
|||
@Test
|
||||
public void testToNMS() {
|
||||
for (Attribute attribute : Attribute.values()) {
|
||||
AttributeBase nms = CraftAttributeMap.toMinecraft(attribute);
|
||||
AttributeBase nms = CraftAttribute.bukkitToMinecraft(attribute);
|
||||
|
||||
Assert.assertNotNull(attribute.name(), nms);
|
||||
}
|
||||
|
|
|
@ -14,43 +14,43 @@ public class CraftMemoryKeyTest extends AbstractTestingBase {
|
|||
|
||||
@Test
|
||||
public void shouldConvertBukkitHomeKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.HOME);
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME);
|
||||
Assert.assertEquals("MemoryModuleType should be HOME", MemoryModuleType.HOME, nmsHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.JOB_SITE);
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE);
|
||||
Assert.assertEquals("MemoryModuleType should be JOB_SITE", MemoryModuleType.JOB_SITE, nmsHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.MEETING_POINT);
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT);
|
||||
Assert.assertEquals("MemoryModuleType should be MEETING_POINT", MemoryModuleType.MEETING_POINT, nmsHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSHomeKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.HOME);
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME);
|
||||
Assert.assertEquals("MemoryModuleType should be HOME", MemoryKey.HOME, bukkitHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.JOB_SITE);
|
||||
MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE);
|
||||
Assert.assertEquals("MemoryKey should be JOB_SITE", MemoryKey.JOB_SITE, bukkitJobSiteKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.MEETING_POINT);
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.MEETING_POINT);
|
||||
Assert.assertEquals("MemoryKey should be MEETING_POINT", MemoryKey.MEETING_POINT, bukkitHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailable() {
|
||||
MemoryKey bukkitNoKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.NEAREST_LIVING_ENTITIES);
|
||||
MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.NEAREST_LIVING_ENTITIES);
|
||||
Assert.assertNull("MemoryModuleType should be null", bukkitNoKey);
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class CraftMemoryKeyTest extends AbstractTestingBase {
|
|||
public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailableAndSerializerIsNotPresent() {
|
||||
for (MemoryModuleType<?> memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) {
|
||||
if (!memoryModuleType.getCodec().isPresent()) {
|
||||
MemoryKey bukkitNoKey = CraftMemoryKey.toMemoryKey(memoryModuleType);
|
||||
MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType);
|
||||
Assert.assertNull("MemoryModuleType should be null", bukkitNoKey);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class CraftMemoryKeyTest extends AbstractTestingBase {
|
|||
public void shouldReturnAnInstanceOfMemoryKeyWhenBukkitRepresentationOfKeyisAvailableAndSerializerIsPresent() {
|
||||
for (MemoryModuleType<?> memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) {
|
||||
if (memoryModuleType.getCodec().isPresent()) {
|
||||
MemoryKey bukkitNoKey = CraftMemoryKey.toMemoryKey(memoryModuleType);
|
||||
MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType);
|
||||
Assert.assertNotNull("MemoryModuleType should not be null " + BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType), bukkitNoKey);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue