@@ -17,7 +17,7 @@ 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.util.thread.ThreadedMailbox;
|
||||
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;
|
||||
@@ -31,8 +31,8 @@ import net.minecraft.world.level.chunk.NibbleArray;
|
||||
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.ChunkRegionLoader;
|
||||
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;
|
||||
@@ -111,7 +111,7 @@ public class CraftChunk implements Chunk {
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
validateChunkCoordinates(worldServer.getMinBuildHeight(), worldServer.getMaxBuildHeight(), x, y, z);
|
||||
validateChunkCoordinates(worldServer.getMinY(), worldServer.getMaxY(), x, y, z);
|
||||
|
||||
return new CraftBlock(worldServer, new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z));
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class CraftChunk implements Chunk {
|
||||
entityManager.ensureChunkQueuedForLoad(pair); // Start entity loading
|
||||
|
||||
// SPIGOT-6772: Use entity mailbox and re-schedule entities if they get unloaded
|
||||
ThreadedMailbox<Runnable> mailbox = ((EntityStorage) entityManager.permanentStorage).entityDeserializerQueue;
|
||||
ConsecutiveExecutor mailbox = ((EntityStorage) entityManager.permanentStorage).entityDeserializerQueue;
|
||||
BooleanSupplier supplier = () -> {
|
||||
// only execute inbox if our entities are not present
|
||||
if (entityManager.areEntitiesLoaded(pair)) {
|
||||
@@ -310,14 +310,14 @@ public class CraftChunk implements Chunk {
|
||||
boolean[] sectionEmpty = new boolean[cs.length];
|
||||
PalettedContainerRO<Holder<BiomeBase>>[] biome = (includeBiome || includeBiomeTempRain) ? new DataPaletteBlock[cs.length] : null;
|
||||
|
||||
IRegistry<BiomeBase> iregistry = worldServer.registryAccess().registryOrThrow(Registries.BIOME);
|
||||
Codec<PalettedContainerRO<Holder<BiomeBase>>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getHolderOrThrow(Biomes.PLAINS));
|
||||
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));
|
||||
|
||||
for (int i = 0; i < cs.length; i++) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
data.put("block_states", ChunkRegionLoader.BLOCK_STATE_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getStates()).getOrThrow());
|
||||
sectionBlockIDs[i] = ChunkRegionLoader.BLOCK_STATE_CODEC.parse(DynamicOpsNBT.INSTANCE, data.getCompound("block_states")).getOrThrow(ChunkRegionLoader.a::new);
|
||||
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);
|
||||
sectionEmpty[i] = cs[i].hasOnlyAir();
|
||||
|
||||
LevelLightEngine lightengine = worldServer.getLightEngine();
|
||||
@@ -338,7 +338,7 @@ public class CraftChunk implements Chunk {
|
||||
|
||||
if (biome != null) {
|
||||
data.put("biomes", biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getBiomes()).getOrThrow());
|
||||
biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).getOrThrow(ChunkRegionLoader.a::new);
|
||||
biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).getOrThrow(SerializableChunkData.a::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ public class CraftChunk implements Chunk {
|
||||
}
|
||||
|
||||
World world = getWorld();
|
||||
return new CraftChunkSnapshot(getX(), getZ(), chunk.getMinBuildHeight(), chunk.getMaxBuildHeight(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, iregistry, biome);
|
||||
return new CraftChunkSnapshot(getX(), getZ(), chunk.getMinY(), chunk.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, iregistry, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -411,9 +411,9 @@ public class CraftChunk implements Chunk {
|
||||
byte[][] skyLight = new byte[hSection][];
|
||||
byte[][] emitLight = new byte[hSection][];
|
||||
boolean[] empty = new boolean[hSection];
|
||||
IRegistry<BiomeBase> iregistry = world.getHandle().registryAccess().registryOrThrow(Registries.BIOME);
|
||||
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.getHolderOrThrow(Biomes.PLAINS));
|
||||
Codec<PalettedContainerRO<Holder<BiomeBase>>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
|
||||
|
||||
for (int i = 0; i < hSection; i++) {
|
||||
blockIDs[i] = emptyBlockIDs;
|
||||
@@ -422,11 +422,11 @@ public class CraftChunk implements Chunk {
|
||||
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(ChunkRegionLoader.a::new);
|
||||
biome[i] = (DataPaletteBlock<Holder<BiomeBase>>) biomeCodec.parse(DynamicOpsNBT.INSTANCE, biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, actual.getSection(i).getBiomes()).getOrThrow()).getOrThrow(SerializableChunkData.a::new);
|
||||
}
|
||||
}
|
||||
|
||||
return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxHeight(), 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.Type.MOTION_BLOCKING), iregistry, biome);
|
||||
}
|
||||
|
||||
static void validateChunkCoordinates(int minY, int maxY, int x, int y, int z) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
*/
|
||||
public class CraftChunkSnapshot implements ChunkSnapshot {
|
||||
private final int x, z;
|
||||
private final int minHeight, maxHeight;
|
||||
private final int minHeight, maxHeight, seaLevel;
|
||||
private final String worldname;
|
||||
private final DataPaletteBlock<IBlockData>[] blockids;
|
||||
private final byte[][] skylight;
|
||||
@@ -37,11 +37,12 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
|
||||
private final IRegistry<BiomeBase> biomeRegistry;
|
||||
private final PalettedContainerRO<Holder<BiomeBase>>[] biome;
|
||||
|
||||
CraftChunkSnapshot(int x, int z, int minHeight, int maxHeight, 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, DataPaletteBlock<IBlockData>[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, HeightMap hmap, IRegistry<BiomeBase> biomeRegistry, PalettedContainerRO<Holder<BiomeBase>>[] biome) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.minHeight = minHeight;
|
||||
this.maxHeight = maxHeight;
|
||||
this.seaLevel = seaLevel;
|
||||
this.worldname = wname;
|
||||
this.captureFulltime = wtime;
|
||||
this.blockids = sectionBlockIDs;
|
||||
@@ -166,7 +167,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 biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z));
|
||||
return biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z), seaLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,14 +9,14 @@ 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.util.context.ContextKey;
|
||||
import net.minecraft.util.context.ContextKeySet;
|
||||
import net.minecraft.world.IInventory;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
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.LootContextParameter;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParameterSet;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -132,12 +132,12 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
||||
}
|
||||
|
||||
// SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
|
||||
LootContextParameterSet.Builder nmsBuilder = new LootContextParameterSet.Builder();
|
||||
for (LootContextParameter<?> param : getHandle().getParamSet().getRequired()) {
|
||||
ContextKeySet.a nmsBuilder = new ContextKeySet.a();
|
||||
for (ContextKey<?> param : getHandle().getParamSet().required()) {
|
||||
nmsBuilder.required(param);
|
||||
}
|
||||
for (LootContextParameter<?> param : getHandle().getParamSet().getAllowed()) {
|
||||
if (!getHandle().getParamSet().getRequired().contains(param)) {
|
||||
for (ContextKey<?> param : getHandle().getParamSet().allowed()) {
|
||||
if (!getHandle().getParamSet().required().contains(param)) {
|
||||
nmsBuilder.optional(param);
|
||||
}
|
||||
}
|
||||
@@ -145,29 +145,29 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
||||
return builder.create(getHandle().getParamSet());
|
||||
}
|
||||
|
||||
private <T> void setMaybe(LootParams.a builder, LootContextParameter<T> param, T value) {
|
||||
if (getHandle().getParamSet().getRequired().contains(param) || getHandle().getParamSet().getAllowed().contains(param)) {
|
||||
private <T> void setMaybe(LootParams.a builder, ContextKey<T> param, T value) {
|
||||
if (getHandle().getParamSet().required().contains(param) || getHandle().getParamSet().allowed().contains(param)) {
|
||||
builder.withParameter(param, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static LootContext convertContext(LootTableInfo info) {
|
||||
Vec3D position = info.getParamOrNull(LootContextParameters.ORIGIN);
|
||||
Vec3D position = info.getOptionalParameter(LootContextParameters.ORIGIN);
|
||||
if (position == null) {
|
||||
position = info.getParamOrNull(LootContextParameters.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParameterSets
|
||||
position = info.getOptionalParameter(LootContextParameters.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.hasParam(LootContextParameters.ATTACKING_ENTITY)) {
|
||||
CraftEntity killer = info.getParamOrNull(LootContextParameters.ATTACKING_ENTITY).getBukkitEntity();
|
||||
if (info.hasParameter(LootContextParameters.ATTACKING_ENTITY)) {
|
||||
CraftEntity killer = info.getOptionalParameter(LootContextParameters.ATTACKING_ENTITY).getBukkitEntity();
|
||||
if (killer instanceof CraftHumanEntity) {
|
||||
contextBuilder.killer((CraftHumanEntity) killer);
|
||||
}
|
||||
}
|
||||
|
||||
if (info.hasParam(LootContextParameters.THIS_ENTITY)) {
|
||||
contextBuilder.lootedEntity(info.getParamOrNull(LootContextParameters.THIS_ENTITY).getBukkitEntity());
|
||||
if (info.hasParameter(LootContextParameters.THIS_ENTITY)) {
|
||||
contextBuilder.lootedEntity(info.getOptionalParameter(LootContextParameters.THIS_ENTITY).getBukkitEntity());
|
||||
}
|
||||
|
||||
contextBuilder.luck(info.getLuck());
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.core.particles.ParticleParamRedstone;
|
||||
import net.minecraft.core.particles.ParticleType;
|
||||
import net.minecraft.core.particles.SculkChargeParticleOptions;
|
||||
import net.minecraft.core.particles.ShriekParticleOption;
|
||||
import net.minecraft.core.particles.TargetColorParticleOption;
|
||||
import net.minecraft.core.particles.VibrationParticleOption;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@@ -37,7 +38,6 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public abstract class CraftParticle<D> implements Keyed {
|
||||
|
||||
@@ -124,7 +124,7 @@ public abstract class CraftParticle<D> implements Keyed {
|
||||
@Override
|
||||
public ParticleParam createParticleParam(Particle.DustOptions data) {
|
||||
Color color = data.getColor();
|
||||
return new ParticleParamRedstone(new Vector3f(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f), data.getSize());
|
||||
return new ParticleParamRedstone(color.asRGB(), data.getSize());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -147,7 +147,7 @@ public abstract class CraftParticle<D> implements Keyed {
|
||||
public ParticleParam createParticleParam(Particle.DustTransition data) {
|
||||
Color from = data.getColor();
|
||||
Color to = data.getToColor();
|
||||
return new DustColorTransitionOptions(new Vector3f(from.getRed() / 255.0f, from.getGreen() / 255.0f, from.getBlue() / 255.0f), new Vector3f(to.getRed() / 255.0f, to.getGreen() / 255.0f, to.getBlue() / 255.0f), data.getSize());
|
||||
return new DustColorTransitionOptions(from.asRGB(), to.asRGB(), data.getSize());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -190,6 +190,13 @@ public abstract class CraftParticle<D> implements Keyed {
|
||||
}
|
||||
};
|
||||
|
||||
BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> targetColorFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.TargetColor.class) {
|
||||
@Override
|
||||
public ParticleParam createParticleParam(Particle.TargetColor data) {
|
||||
return new TargetColorParticleOption(CraftLocation.toVec3D(data.getTarget()), data.getColor().asRGB());
|
||||
}
|
||||
};
|
||||
|
||||
add("dust", dustOptionsFunction);
|
||||
add("item", itemStackFunction);
|
||||
add("block", blockDataFunction);
|
||||
@@ -201,6 +208,8 @@ public abstract class CraftParticle<D> implements Keyed {
|
||||
add("block_marker", blockDataFunction);
|
||||
add("entity_effect", colorFunction);
|
||||
add("dust_pillar", blockDataFunction);
|
||||
add("block_crumble", blockDataFunction);
|
||||
add("trail", targetColorFunction);
|
||||
}
|
||||
|
||||
private static void add(String name, BiFunction<NamespacedKey, net.minecraft.core.particles.Particle<?>, CraftParticle<?>> function) {
|
||||
|
||||
@@ -14,7 +14,7 @@ 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.EnumMobSpawn;
|
||||
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;
|
||||
@@ -24,7 +24,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.feature.WorldGenFeatureConfigured;
|
||||
import net.minecraft.world.level.portal.DimensionTransition;
|
||||
import net.minecraft.world.level.portal.TeleportTransition;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.RegionAccessor;
|
||||
@@ -280,7 +280,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||
break;
|
||||
}
|
||||
|
||||
Holder<WorldGenFeatureConfigured<?, ?>> holder = access.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(gen).orElse(null);
|
||||
Holder<WorldGenFeatureConfigured<?, ?>> holder = access.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(gen).orElse(null);
|
||||
return (holder != null) ? holder.value().place(access, chunkGenerator, random, pos) : false;
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||
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.changeDimension(new DimensionTransition(getHandle().getLevel(), nmsEntity, DimensionTransition.DO_NOTHING));
|
||||
nmsEntity = nmsEntity.teleport(new TeleportTransition(getHandle().getLevel(), nmsEntity, TeleportTransition.DO_NOTHING));
|
||||
}
|
||||
|
||||
addEntityWithPassengers(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
@@ -436,7 +436,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||
Preconditions.checkArgument(entity != null, "Cannot spawn null entity");
|
||||
|
||||
if (randomizeData && entity instanceof EntityInsentient) {
|
||||
((EntityInsentient) entity).finalizeSpawn(getHandle(), getHandle().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null);
|
||||
((EntityInsentient) entity).finalizeSpawn(getHandle(), getHandle().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (GroupDataEntity) null);
|
||||
}
|
||||
|
||||
if (!isNormalWorld()) {
|
||||
|
||||
@@ -73,7 +73,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
||||
}
|
||||
|
||||
public static <E> IRegistry<E> getMinecraftRegistry(ResourceKey<IRegistry<E>> key) {
|
||||
return getMinecraftRegistry().registryOrThrow(key);
|
||||
return getMinecraftRegistry().lookupOrThrow(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,64 +132,64 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
||||
*/
|
||||
public static <B extends Keyed> Registry<?> createRegistry(Class<? super B> bukkitClass, IRegistryCustom registryHolder) {
|
||||
if (bukkitClass == Enchantment.class) {
|
||||
return new CraftRegistry<>(Enchantment.class, registryHolder.registryOrThrow(Registries.ENCHANTMENT), CraftEnchantment::new, FieldRename.ENCHANTMENT_RENAME);
|
||||
return new CraftRegistry<>(Enchantment.class, registryHolder.lookupOrThrow(Registries.ENCHANTMENT), CraftEnchantment::new, FieldRename.ENCHANTMENT_RENAME);
|
||||
}
|
||||
if (bukkitClass == GameEvent.class) {
|
||||
return new CraftRegistry<>(GameEvent.class, registryHolder.registryOrThrow(Registries.GAME_EVENT), CraftGameEvent::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(GameEvent.class, registryHolder.lookupOrThrow(Registries.GAME_EVENT), CraftGameEvent::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == MusicInstrument.class) {
|
||||
return new CraftRegistry<>(MusicInstrument.class, registryHolder.registryOrThrow(Registries.INSTRUMENT), CraftMusicInstrument::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(MusicInstrument.class, registryHolder.lookupOrThrow(Registries.INSTRUMENT), CraftMusicInstrument::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == MenuType.class) {
|
||||
return new CraftRegistry<>(MenuType.class, registryHolder.registryOrThrow(Registries.MENU), CraftMenuType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(MenuType.class, registryHolder.lookupOrThrow(Registries.MENU), CraftMenuType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == PotionEffectType.class) {
|
||||
return new CraftRegistry<>(PotionEffectType.class, registryHolder.registryOrThrow(Registries.MOB_EFFECT), CraftPotionEffectType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(PotionEffectType.class, registryHolder.lookupOrThrow(Registries.MOB_EFFECT), CraftPotionEffectType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == Structure.class) {
|
||||
return new CraftRegistry<>(Structure.class, registryHolder.registryOrThrow(Registries.STRUCTURE), CraftStructure::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(Structure.class, registryHolder.lookupOrThrow(Registries.STRUCTURE), CraftStructure::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == StructureType.class) {
|
||||
return new CraftRegistry<>(StructureType.class, registryHolder.registryOrThrow(Registries.STRUCTURE_TYPE), CraftStructureType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(StructureType.class, registryHolder.lookupOrThrow(Registries.STRUCTURE_TYPE), CraftStructureType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == Villager.Type.class) {
|
||||
return new CraftRegistry<>(Villager.Type.class, registryHolder.registryOrThrow(Registries.VILLAGER_TYPE), CraftVillager.CraftType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(Villager.Type.class, registryHolder.lookupOrThrow(Registries.VILLAGER_TYPE), CraftVillager.CraftType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == Villager.Profession.class) {
|
||||
return new CraftRegistry<>(Villager.Profession.class, registryHolder.registryOrThrow(Registries.VILLAGER_PROFESSION), CraftVillager.CraftProfession::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(Villager.Profession.class, registryHolder.lookupOrThrow(Registries.VILLAGER_PROFESSION), CraftVillager.CraftProfession::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == TrimMaterial.class) {
|
||||
return new CraftRegistry<>(TrimMaterial.class, registryHolder.registryOrThrow(Registries.TRIM_MATERIAL), CraftTrimMaterial::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(TrimMaterial.class, registryHolder.lookupOrThrow(Registries.TRIM_MATERIAL), CraftTrimMaterial::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == TrimPattern.class) {
|
||||
return new CraftRegistry<>(TrimPattern.class, registryHolder.registryOrThrow(Registries.TRIM_PATTERN), CraftTrimPattern::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(TrimPattern.class, registryHolder.lookupOrThrow(Registries.TRIM_PATTERN), CraftTrimPattern::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == DamageType.class) {
|
||||
return new CraftRegistry<>(DamageType.class, registryHolder.registryOrThrow(Registries.DAMAGE_TYPE), CraftDamageType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(DamageType.class, registryHolder.lookupOrThrow(Registries.DAMAGE_TYPE), CraftDamageType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == JukeboxSong.class) {
|
||||
return new CraftRegistry<>(JukeboxSong.class, registryHolder.registryOrThrow(Registries.JUKEBOX_SONG), CraftJukeboxSong::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(JukeboxSong.class, registryHolder.lookupOrThrow(Registries.JUKEBOX_SONG), CraftJukeboxSong::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == Wolf.Variant.class) {
|
||||
return new CraftRegistry<>(Wolf.Variant.class, registryHolder.registryOrThrow(Registries.WOLF_VARIANT), CraftWolf.CraftVariant::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(Wolf.Variant.class, registryHolder.lookupOrThrow(Registries.WOLF_VARIANT), CraftWolf.CraftVariant::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == BlockType.class) {
|
||||
return new CraftRegistry<>(BlockType.class, registryHolder.registryOrThrow(Registries.BLOCK), CraftBlockType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(BlockType.class, registryHolder.lookupOrThrow(Registries.BLOCK), CraftBlockType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == ItemType.class) {
|
||||
return new CraftRegistry<>(ItemType.class, registryHolder.registryOrThrow(Registries.ITEM), CraftItemType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(ItemType.class, registryHolder.lookupOrThrow(Registries.ITEM), CraftItemType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == Frog.Variant.class) {
|
||||
return new CraftRegistry<>(Frog.Variant.class, registryHolder.registryOrThrow(Registries.FROG_VARIANT), CraftFrog.CraftVariant::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(Frog.Variant.class, registryHolder.lookupOrThrow(Registries.FROG_VARIANT), CraftFrog.CraftVariant::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == Cat.Type.class) {
|
||||
return new CraftRegistry<>(Cat.Type.class, registryHolder.registryOrThrow(Registries.CAT_VARIANT), CraftCat.CraftType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(Cat.Type.class, registryHolder.lookupOrThrow(Registries.CAT_VARIANT), CraftCat.CraftType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == MapCursor.Type.class) {
|
||||
return new CraftRegistry<>(MapCursor.Type.class, registryHolder.registryOrThrow(Registries.MAP_DECORATION_TYPE), CraftMapCursor.CraftType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(MapCursor.Type.class, registryHolder.lookupOrThrow(Registries.MAP_DECORATION_TYPE), CraftMapCursor.CraftType::new, FieldRename.NONE);
|
||||
}
|
||||
if (bukkitClass == PatternType.class) {
|
||||
return new CraftRegistry<>(PatternType.class, registryHolder.registryOrThrow(Registries.BANNER_PATTERN), CraftPatternType::new, FieldRename.NONE);
|
||||
return new CraftRegistry<>(PatternType.class, registryHolder.lookupOrThrow(Registries.BANNER_PATTERN), CraftPatternType::new, FieldRename.NONE);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -51,7 +51,6 @@ import net.minecraft.commands.arguments.ArgumentEntity;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.IRegistryCustom;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.NbtException;
|
||||
@@ -80,6 +79,7 @@ import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.ChatDeserializer;
|
||||
import net.minecraft.util.datafix.DataConverterRegistry;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.damagesource.DamageType;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.ai.village.VillageSiege;
|
||||
import net.minecraft.world.entity.npc.MobSpawnerCat;
|
||||
@@ -180,6 +180,7 @@ import org.bukkit.craftbukkit.inventory.CraftSmithingTransformRecipe;
|
||||
import org.bukkit.craftbukkit.inventory.CraftSmithingTrimRecipe;
|
||||
import org.bukkit.craftbukkit.inventory.CraftSmokingRecipe;
|
||||
import org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe;
|
||||
import org.bukkit.craftbukkit.inventory.CraftTransmuteRecipe;
|
||||
import org.bukkit.craftbukkit.inventory.RecipeIterator;
|
||||
import org.bukkit.craftbukkit.inventory.util.CraftInventoryCreator;
|
||||
import org.bukkit.craftbukkit.map.CraftMapColorCache;
|
||||
@@ -196,6 +197,7 @@ import org.bukkit.craftbukkit.scoreboard.CraftCriteria;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager;
|
||||
import org.bukkit.craftbukkit.structure.CraftStructureManager;
|
||||
import org.bukkit.craftbukkit.tag.CraftBlockTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftDamageTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftEntityTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftFluidTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftItemTag;
|
||||
@@ -240,6 +242,7 @@ import org.bukkit.inventory.SmithingTransformRecipe;
|
||||
import org.bukkit.inventory.SmithingTrimRecipe;
|
||||
import org.bukkit.inventory.SmokingRecipe;
|
||||
import org.bukkit.inventory.StonecuttingRecipe;
|
||||
import org.bukkit.inventory.TransmuteRecipe;
|
||||
import org.bukkit.loot.LootTable;
|
||||
import org.bukkit.map.MapPalette;
|
||||
import org.bukkit.map.MapView;
|
||||
@@ -946,7 +949,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
for (WorldServer world : console.getAllLevels()) {
|
||||
world.serverLevelData.setDifficulty(config.difficulty);
|
||||
world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals);
|
||||
world.setSpawnSettings(config.spawnMonsters);
|
||||
|
||||
for (SpawnCategory spawnCategory : SpawnCategory.values()) {
|
||||
if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
|
||||
@@ -1169,7 +1172,7 @@ public final class CraftServer implements Server {
|
||||
WorldDataServer worlddata;
|
||||
WorldLoader.a worldloader_a = console.worldLoader;
|
||||
IRegistryCustom.Dimension iregistrycustom_dimension = worldloader_a.datapackDimensions();
|
||||
IRegistry<WorldDimension> iregistry = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM);
|
||||
IRegistry<WorldDimension> iregistry = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM);
|
||||
if (dynamic != null) {
|
||||
LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen());
|
||||
|
||||
@@ -1182,7 +1185,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
DedicatedServerProperties.WorldDimensionData properties = new DedicatedServerProperties.WorldDimensionData(ChatDeserializer.parse((creator.generatorSettings().isEmpty()) ? "{}" : creator.generatorSettings()), creator.type().name().toLowerCase(Locale.ROOT));
|
||||
|
||||
worldsettings = new WorldSettings(name, EnumGamemode.byId(getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(), worldloader_a.dataConfiguration());
|
||||
worldsettings = new WorldSettings(name, EnumGamemode.byId(getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
|
||||
worlddimensions = properties.create(worldloader_a.datapackWorldgen());
|
||||
|
||||
WorldDimensions.b worlddimensions_b = worlddimensions.bake(iregistry);
|
||||
@@ -1191,7 +1194,7 @@ public final class CraftServer implements Server {
|
||||
worlddata = new WorldDataServer(worldsettings, worldoptions, worlddimensions_b.specialWorldProperty(), lifecycle);
|
||||
iregistrycustom_dimension = worlddimensions_b.dimensionsRegistryAccess();
|
||||
}
|
||||
iregistry = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM);
|
||||
iregistry = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM);
|
||||
worlddata.customDimensions = iregistry;
|
||||
worlddata.checkName(name);
|
||||
worlddata.setModdedInfo(console.getServerModName(), console.getModdedStatus().shouldReportAsModified());
|
||||
@@ -1202,7 +1205,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
long j = BiomeManager.obfuscateSeed(creator.seed());
|
||||
List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(worlddata));
|
||||
WorldDimension worlddimension = iregistry.get(actualDimension);
|
||||
WorldDimension worlddimension = iregistry.getValue(actualDimension);
|
||||
|
||||
WorldInfo worldInfo = new CraftWorldInfo(worlddata, worldSession, creator.environment(), worlddimension.type().value());
|
||||
if (biomeProvider == null && generator != null) {
|
||||
@@ -1232,7 +1235,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
console.initWorld(internal, worlddata, worlddata, worlddata.worldGenOptions());
|
||||
|
||||
internal.setSpawnSettings(true, true);
|
||||
internal.setSpawnSettings(true);
|
||||
console.addLevel(internal);
|
||||
|
||||
getServer().prepareLevels(internal.getChunkSource().chunkMap.progressListener, internal);
|
||||
@@ -1376,6 +1379,8 @@ public final class CraftServer implements Server {
|
||||
toAdd = CraftSmithingTransformRecipe.fromBukkitRecipe((SmithingTransformRecipe) recipe);
|
||||
} else if (recipe instanceof SmithingTrimRecipe) {
|
||||
toAdd = CraftSmithingTrimRecipe.fromBukkitRecipe((SmithingTrimRecipe) recipe);
|
||||
} else if (recipe instanceof TransmuteRecipe) {
|
||||
toAdd = CraftTransmuteRecipe.fromBukkitRecipe((TransmuteRecipe) recipe);
|
||||
} else if (recipe instanceof ComplexRecipe) {
|
||||
throw new UnsupportedOperationException("Cannot add custom complex recipe");
|
||||
} else {
|
||||
@@ -1409,7 +1414,7 @@ public final class CraftServer implements Server {
|
||||
public Recipe getRecipe(NamespacedKey recipeKey) {
|
||||
Preconditions.checkArgument(recipeKey != null, "NamespacedKey recipeKey cannot be null");
|
||||
|
||||
return getServer().getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(recipeKey)).map(RecipeHolder::toBukkitRecipe).orElse(null);
|
||||
return getServer().getRecipeManager().byKey(CraftRecipe.toMinecraft(recipeKey)).map(RecipeHolder::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private InventoryCrafting createInventoryCrafting() {
|
||||
@@ -1464,7 +1469,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
if (recipe.isPresent()) {
|
||||
RecipeHolder<RecipeCrafting> recipeCrafting = recipe.get();
|
||||
if (craftResult.setRecipeUsed(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
if (craftResult.setRecipeUsed(craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.value().assemble(inventoryCrafting.asCraftInput(), craftWorld.getHandle().registryAccess());
|
||||
}
|
||||
}
|
||||
@@ -1472,7 +1477,7 @@ public final class CraftServer implements Server {
|
||||
// Call Bukkit event to check for matrix/result changes.
|
||||
net.minecraft.world.item.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, craftResult, itemstack, container.getBukkitView(), recipe.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair);
|
||||
|
||||
return createItemCraftResult(CraftItemStack.asBukkitCopy(result), inventoryCrafting, craftWorld.getHandle());
|
||||
return createItemCraftResult(recipe, CraftItemStack.asBukkitCopy(result), inventoryCrafting, craftWorld.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1498,34 +1503,34 @@ public final class CraftServer implements Server {
|
||||
itemStack = recipe.get().value().assemble(inventoryCrafting.asCraftInput(), craftWorld.getHandle().registryAccess());
|
||||
}
|
||||
|
||||
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
|
||||
return createItemCraftResult(recipe, CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
|
||||
}
|
||||
|
||||
private CraftItemCraftResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
|
||||
private CraftItemCraftResult createItemCraftResult(Optional<RecipeHolder<RecipeCrafting>> recipe, ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
|
||||
CraftItemCraftResult craftItemResult = new CraftItemCraftResult(itemStack);
|
||||
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = getServer().getRecipeManager().getRemainingItemsFor(Recipes.CRAFTING, inventoryCrafting.asCraftInput(), worldServer);
|
||||
recipe.map((holder) -> holder.value().getRemainingItems(inventoryCrafting.asCraftInput())).ifPresent((remainingItems) -> {
|
||||
// Set the resulting matrix items and overflow items
|
||||
for (int i = 0; i < remainingItems.size(); ++i) {
|
||||
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
|
||||
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
|
||||
|
||||
// Set the resulting matrix items and overflow items
|
||||
for (int i = 0; i < remainingItems.size(); ++i) {
|
||||
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
|
||||
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
|
||||
if (!itemstack1.isEmpty()) {
|
||||
inventoryCrafting.removeItem(i, 1);
|
||||
itemstack1 = inventoryCrafting.getItem(i);
|
||||
}
|
||||
|
||||
if (!itemstack1.isEmpty()) {
|
||||
inventoryCrafting.removeItem(i, 1);
|
||||
itemstack1 = inventoryCrafting.getItem(i);
|
||||
}
|
||||
|
||||
if (!itemstack2.isEmpty()) {
|
||||
if (itemstack1.isEmpty()) {
|
||||
inventoryCrafting.setItem(i, itemstack2);
|
||||
} else if (net.minecraft.world.item.ItemStack.isSameItemSameComponents(itemstack1, itemstack2)) {
|
||||
itemstack2.grow(itemstack1.getCount());
|
||||
inventoryCrafting.setItem(i, itemstack2);
|
||||
} else {
|
||||
craftItemResult.getOverflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
|
||||
if (!itemstack2.isEmpty()) {
|
||||
if (itemstack1.isEmpty()) {
|
||||
inventoryCrafting.setItem(i, itemstack2);
|
||||
} else if (net.minecraft.world.item.ItemStack.isSameItemSameComponents(itemstack1, itemstack2)) {
|
||||
itemstack2.grow(itemstack1.getCount());
|
||||
inventoryCrafting.setItem(i, itemstack2);
|
||||
} else {
|
||||
craftItemResult.getOverflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
|
||||
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
|
||||
@@ -1565,8 +1570,7 @@ public final class CraftServer implements Server {
|
||||
public boolean removeRecipe(NamespacedKey recipeKey) {
|
||||
Preconditions.checkArgument(recipeKey != null, "recipeKey == null");
|
||||
|
||||
MinecraftKey mcKey = CraftNamespacedKey.toMinecraft(recipeKey);
|
||||
return getServer().getRecipeManager().removeRecipe(mcKey);
|
||||
return getServer().getRecipeManager().removeRecipe(CraftRecipe.toMinecraft(recipeKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2292,7 +2296,7 @@ public final class CraftServer implements Server {
|
||||
public ChunkGenerator.ChunkData createChunkData(World world) {
|
||||
Preconditions.checkArgument(world != null, "World cannot be null");
|
||||
WorldServer handle = ((CraftWorld) world).getHandle();
|
||||
return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registries.BIOME));
|
||||
return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().lookupOrThrow(Registries.BIOME));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2428,31 +2432,39 @@ public final class CraftServer implements Server {
|
||||
case org.bukkit.Tag.REGISTRY_BLOCKS -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace (%s) must have material type", clazz.getName());
|
||||
TagKey<Block> blockTagKey = TagKey.create(Registries.BLOCK, key);
|
||||
if (BuiltInRegistries.BLOCK.getTag(blockTagKey).isPresent()) {
|
||||
if (BuiltInRegistries.BLOCK.get(blockTagKey).isPresent()) {
|
||||
return (org.bukkit.Tag<T>) new CraftBlockTag(BuiltInRegistries.BLOCK, blockTagKey);
|
||||
}
|
||||
}
|
||||
case org.bukkit.Tag.REGISTRY_ITEMS -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace (%s) must have material type", clazz.getName());
|
||||
TagKey<Item> itemTagKey = TagKey.create(Registries.ITEM, key);
|
||||
if (BuiltInRegistries.ITEM.getTag(itemTagKey).isPresent()) {
|
||||
if (BuiltInRegistries.ITEM.get(itemTagKey).isPresent()) {
|
||||
return (org.bukkit.Tag<T>) new CraftItemTag(BuiltInRegistries.ITEM, itemTagKey);
|
||||
}
|
||||
}
|
||||
case org.bukkit.Tag.REGISTRY_FLUIDS -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace (%s) must have fluid type", clazz.getName());
|
||||
TagKey<FluidType> fluidTagKey = TagKey.create(Registries.FLUID, key);
|
||||
if (BuiltInRegistries.FLUID.getTag(fluidTagKey).isPresent()) {
|
||||
if (BuiltInRegistries.FLUID.get(fluidTagKey).isPresent()) {
|
||||
return (org.bukkit.Tag<T>) new CraftFluidTag(BuiltInRegistries.FLUID, fluidTagKey);
|
||||
}
|
||||
}
|
||||
case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace (%s) must have entity type", clazz.getName());
|
||||
TagKey<EntityTypes<?>> entityTagKey = TagKey.create(Registries.ENTITY_TYPE, key);
|
||||
if (BuiltInRegistries.ENTITY_TYPE.getTag(entityTagKey).isPresent()) {
|
||||
if (BuiltInRegistries.ENTITY_TYPE.get(entityTagKey).isPresent()) {
|
||||
return (org.bukkit.Tag<T>) new CraftEntityTag(BuiltInRegistries.ENTITY_TYPE, entityTagKey);
|
||||
}
|
||||
}
|
||||
case org.bukkit.tag.DamageTypeTags.REGISTRY_DAMAGE_TYPES -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.damage.DamageType.class, "Damage type namespace (%s) must have damage type", clazz.getName());
|
||||
TagKey<DamageType> damageTagKey = TagKey.create(Registries.DAMAGE_TYPE, key);
|
||||
IRegistry<DamageType> damageRegistry = CraftRegistry.getMinecraftRegistry(Registries.DAMAGE_TYPE);
|
||||
if (damageRegistry.get(damageTagKey).isPresent()) {
|
||||
return (org.bukkit.Tag<T>) new CraftDamageTag(damageRegistry, damageTagKey);
|
||||
}
|
||||
}
|
||||
default -> throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
@@ -2468,22 +2480,27 @@ public final class CraftServer implements Server {
|
||||
case org.bukkit.Tag.REGISTRY_BLOCKS -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace (%s) must have material type", clazz.getName());
|
||||
IRegistry<Block> blockTags = BuiltInRegistries.BLOCK;
|
||||
return blockTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftBlockTag(blockTags, pair.getFirst())).collect(ImmutableList.toImmutableList());
|
||||
return blockTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftBlockTag(blockTags, pair.key())).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
case org.bukkit.Tag.REGISTRY_ITEMS -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace (%s) must have material type", clazz.getName());
|
||||
IRegistry<Item> itemTags = BuiltInRegistries.ITEM;
|
||||
return itemTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftItemTag(itemTags, pair.getFirst())).collect(ImmutableList.toImmutableList());
|
||||
return itemTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftItemTag(itemTags, pair.key())).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
case org.bukkit.Tag.REGISTRY_FLUIDS -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Fluid namespace (%s) must have fluid type", clazz.getName());
|
||||
IRegistry<FluidType> fluidTags = BuiltInRegistries.FLUID;
|
||||
return fluidTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftFluidTag(fluidTags, pair.getFirst())).collect(ImmutableList.toImmutableList());
|
||||
return fluidTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftFluidTag(fluidTags, pair.key())).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace (%s) must have entity type", clazz.getName());
|
||||
IRegistry<EntityTypes<?>> entityTags = BuiltInRegistries.ENTITY_TYPE;
|
||||
return entityTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftEntityTag(entityTags, pair.getFirst())).collect(ImmutableList.toImmutableList());
|
||||
return entityTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftEntityTag(entityTags, pair.key())).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
case org.bukkit.tag.DamageTypeTags.REGISTRY_DAMAGE_TYPES -> {
|
||||
Preconditions.checkArgument(clazz == org.bukkit.damage.DamageType.class, "Damage type namespace (%s) must have damage type", clazz.getName());
|
||||
IRegistry<DamageType> damageTags = CraftRegistry.getMinecraftRegistry(Registries.DAMAGE_TYPE);
|
||||
return damageTags.getTags().map(pair -> (org.bukkit.Tag<T>) new CraftDamageTag(damageTags, pair.key())).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
default -> throw new IllegalArgumentException();
|
||||
}
|
||||
@@ -2493,7 +2510,7 @@ public final class CraftServer implements Server {
|
||||
public LootTable getLootTable(NamespacedKey key) {
|
||||
Preconditions.checkArgument(key != null, "NamespacedKey key cannot be null");
|
||||
|
||||
ReloadableServerRegistries.b registry = getServer().reloadableRegistries();
|
||||
ReloadableServerRegistries.a registry = getServer().reloadableRegistries();
|
||||
return registry.lookup().lookup(Registries.LOOT_TABLE)
|
||||
.flatMap((lookup) -> lookup.get(CraftLootTable.bukkitKeyToMinecraft(key)))
|
||||
.map((holder) -> new CraftLootTable(key, holder.value()))
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.particles.Particles;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -46,10 +47,12 @@ import net.minecraft.server.level.TicketType;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.sounds.SoundCategory;
|
||||
import net.minecraft.sounds.SoundEffect;
|
||||
import net.minecraft.sounds.SoundEffects;
|
||||
import net.minecraft.util.ArraySetSorted;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.entity.EntityLightning;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.item.EntityFallingBlock;
|
||||
import net.minecraft.world.entity.item.EntityItem;
|
||||
@@ -57,6 +60,7 @@ import net.minecraft.world.entity.player.EntityHuman;
|
||||
import net.minecraft.world.entity.projectile.EntityArrow;
|
||||
import net.minecraft.world.entity.raid.PersistentRaid;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.RayTrace;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
@@ -296,7 +300,9 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
}
|
||||
net.minecraft.world.level.chunk.Chunk chunk = world.getChunk(x, z);
|
||||
|
||||
chunk.setUnsaved(!save); // Use method call to account for persistentDataContainer
|
||||
if (!save) {
|
||||
chunk.tryMarkSaved(); // Use method call to account for persistentDataContainer
|
||||
}
|
||||
unloadChunkRequest(x, z);
|
||||
|
||||
world.getChunkSource().purgeUnload();
|
||||
@@ -582,14 +588,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
|
||||
EntityArrow arrow;
|
||||
if (TippedArrow.class.isAssignableFrom(clazz)) {
|
||||
arrow = EntityTypes.ARROW.create(world);
|
||||
arrow = EntityTypes.ARROW.create(world, EntitySpawnReason.COMMAND);
|
||||
((Arrow) arrow.getBukkitEntity()).setBasePotionType(PotionType.WATER);
|
||||
} else if (SpectralArrow.class.isAssignableFrom(clazz)) {
|
||||
arrow = EntityTypes.SPECTRAL_ARROW.create(world);
|
||||
arrow = EntityTypes.SPECTRAL_ARROW.create(world, EntitySpawnReason.COMMAND);
|
||||
} else if (Trident.class.isAssignableFrom(clazz)) {
|
||||
arrow = EntityTypes.TRIDENT.create(world);
|
||||
arrow = EntityTypes.TRIDENT.create(world, EntitySpawnReason.COMMAND);
|
||||
} else {
|
||||
arrow = EntityTypes.ARROW.create(world);
|
||||
arrow = EntityTypes.ARROW.create(world, EntitySpawnReason.COMMAND);
|
||||
}
|
||||
|
||||
arrow.moveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
@@ -611,7 +617,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
private LightningStrike strikeLightning0(Location loc, boolean isVisual) {
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
|
||||
EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.create(world);
|
||||
EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.create(world, EntitySpawnReason.COMMAND);
|
||||
lightning.moveTo(loc.getX(), loc.getY(), loc.getZ());
|
||||
lightning.setVisualOnly(isVisual);
|
||||
world.strikeLightning(lightning, LightningStrikeEvent.Cause.CUSTOM);
|
||||
@@ -702,7 +708,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
CraftPlayer cp = (CraftPlayer) p;
|
||||
if (cp.getHandle().connection == null) continue;
|
||||
|
||||
cp.getHandle().connection.send(new PacketPlayOutUpdateTime(cp.getHandle().level().getGameTime(), cp.getHandle().getPlayerTime(), cp.getHandle().level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
|
||||
cp.getHandle().connection.send(new PacketPlayOutUpdateTime(cp.getHandle().level().getGameTime(), cp.getHandle().getPlayerTime(), cp.getHandle().serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +743,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
explosionType = net.minecraft.world.level.World.a.MOB; // Respect mobGriefing gamerule
|
||||
}
|
||||
|
||||
return !world.explode(source == null ? null : ((CraftEntity) source).getHandle(), x, y, z, power, setFire, explosionType).wasCanceled;
|
||||
net.minecraft.world.entity.Entity entity = (source == null) ? null : ((CraftEntity) source).getHandle();
|
||||
return !world.explode0(entity, Explosion.getDefaultDamageSource(world, entity), null, x, y, z, power, setFire, explosionType, Particles.EXPLOSION, Particles.EXPLOSION_EMITTER, SoundEffects.GENERIC_EXPLODE).wasCanceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -847,7 +854,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
if (chunk != null) {
|
||||
chunk.setBiome(x >> 2, y >> 2, z >> 2, bb);
|
||||
|
||||
chunk.setUnsaved(true); // SPIGOT-2890
|
||||
chunk.markUnsaved(); // SPIGOT-2890
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -860,7 +867,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
@Override
|
||||
public double getTemperature(int x, int y, int z) {
|
||||
BlockPosition pos = new BlockPosition(x, y, z);
|
||||
return this.world.getNoiseBiome(x >> 2, y >> 2, z >> 2).value().getTemperature(pos);
|
||||
return this.world.getNoiseBiome(x >> 2, y >> 2, z >> 2).value().getTemperature(pos, this.world.getSeaLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1268,7 +1275,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
|
||||
@Override
|
||||
public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals) {
|
||||
world.setSpawnSettings(allowMonsters, allowAnimals);
|
||||
world.getChunkSource().setSpawnSettings(allowMonsters, allowAnimals);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1283,12 +1290,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return world.getMinBuildHeight();
|
||||
return world.getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return world.getMaxBuildHeight();
|
||||
return world.getMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1709,38 +1716,41 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, GameRules.GameRuleKey<?>> gamerules;
|
||||
public static synchronized Map<String, GameRules.GameRuleKey<?>> getGameRulesNMS() {
|
||||
private Map<String, GameRules.GameRuleKey<?>> gamerules;
|
||||
public synchronized Map<String, GameRules.GameRuleKey<?>> getGameRulesNMS() {
|
||||
if (gamerules != null) {
|
||||
return gamerules;
|
||||
}
|
||||
|
||||
return this.gamerules = getGameRulesNMS(getHandle().getGameRules());
|
||||
}
|
||||
|
||||
public static Map<String, GameRules.GameRuleKey<?>> getGameRulesNMS(GameRules gameRules) {
|
||||
Map<String, GameRules.GameRuleKey<?>> gamerules = new HashMap<>();
|
||||
GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() {
|
||||
gameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() {
|
||||
@Override
|
||||
public <T extends GameRules.GameRuleValue<T>> void visit(GameRules.GameRuleKey<T> gamerules_gamerulekey, GameRules.GameRuleDefinition<T> gamerules_gameruledefinition) {
|
||||
gamerules.put(gamerules_gamerulekey.getId(), gamerules_gamerulekey);
|
||||
}
|
||||
});
|
||||
|
||||
return CraftWorld.gamerules = gamerules;
|
||||
return gamerules;
|
||||
}
|
||||
|
||||
private static Map<String, GameRules.GameRuleDefinition<?>> gameruleDefinitions;
|
||||
public static synchronized Map<String, GameRules.GameRuleDefinition<?>> getGameRuleDefinitions() {
|
||||
private Map<String, GameRules.GameRuleDefinition<?>> gameruleDefinitions;
|
||||
public synchronized Map<String, GameRules.GameRuleDefinition<?>> getGameRuleDefinitions() {
|
||||
if (gameruleDefinitions != null) {
|
||||
return gameruleDefinitions;
|
||||
}
|
||||
|
||||
Map<String, GameRules.GameRuleDefinition<?>> gameruleDefinitions = new HashMap<>();
|
||||
GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() {
|
||||
getHandle().getGameRules().visitGameRuleTypes(new GameRules.GameRuleVisitor() {
|
||||
@Override
|
||||
public <T extends GameRules.GameRuleValue<T>> void visit(GameRules.GameRuleKey<T> gamerules_gamerulekey, GameRules.GameRuleDefinition<T> gamerules_gameruledefinition) {
|
||||
gameruleDefinitions.put(gamerules_gamerulekey.getId(), gamerules_gameruledefinition);
|
||||
}
|
||||
});
|
||||
|
||||
return CraftWorld.gameruleDefinitions = gameruleDefinitions;
|
||||
return this.gameruleDefinitions = gameruleDefinitions;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -190,11 +190,11 @@ public class Main {
|
||||
useConsole = false;
|
||||
}
|
||||
|
||||
if (false && Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
|
||||
if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
|
||||
Date buildDate = new Date(Integer.parseInt(Main.class.getPackage().getImplementationVendor()) * 1000L);
|
||||
|
||||
Calendar deadline = Calendar.getInstance();
|
||||
deadline.add(Calendar.DAY_OF_YEAR, -28);
|
||||
deadline.add(Calendar.DAY_OF_YEAR, -3);
|
||||
if (buildDate.before(deadline.getTime())) {
|
||||
System.err.println("*** Error, this build is outdated ***");
|
||||
System.err.println("*** Please download a new build as per instructions from https://www.spigotmc.org/go/outdated-spigot ***");
|
||||
|
||||
@@ -2,6 +2,13 @@ package org.bukkit.craftbukkit.block;
|
||||
|
||||
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.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;
|
||||
@@ -9,9 +16,11 @@ import net.minecraft.world.level.block.entity.TileEntityBeacon;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Beacon;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@@ -85,17 +94,33 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
|
||||
|
||||
@Override
|
||||
public boolean isLocked() {
|
||||
return !this.getSnapshot().lockKey.key().isEmpty();
|
||||
return this.getSnapshot().lockKey != ChestLock.NO_LOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLock() {
|
||||
return this.getSnapshot().lockKey.key();
|
||||
Optional<? extends IChatBaseComponent> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
|
||||
|
||||
return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLock(String key) {
|
||||
this.getSnapshot().lockKey = (key == null) ? ChestLock.NO_LOCK : new ChestLock(key);
|
||||
if (key == null) {
|
||||
this.getSnapshot().lockKey = ChestLock.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()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockItem(ItemStack key) {
|
||||
if (key == null) {
|
||||
this.getSnapshot().lockKey = ChestLock.NO_LOCK;
|
||||
} else {
|
||||
this.getSnapshot().lockKey = new ChestLock(CraftItemStack.asCriterionConditionItem(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -341,7 +341,7 @@ public class CraftBlock implements Block {
|
||||
|
||||
@Override
|
||||
public double getTemperature() {
|
||||
return world.getBiome(position).value().getTemperature(position);
|
||||
return world.getBiome(position).value().getTemperature(position, world.getSeaLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.world.level.block.entity.BrushableBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.CrafterBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.HangingSignBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SculkCatalystBlockEntity;
|
||||
@@ -150,6 +151,8 @@ public final class CraftBlockStates {
|
||||
Material.MANGROVE_WALL_SIGN,
|
||||
Material.OAK_SIGN,
|
||||
Material.OAK_WALL_SIGN,
|
||||
Material.PALE_OAK_SIGN,
|
||||
Material.PALE_OAK_WALL_SIGN,
|
||||
Material.SPRUCE_SIGN,
|
||||
Material.SPRUCE_WALL_SIGN,
|
||||
Material.WARPED_SIGN,
|
||||
@@ -177,6 +180,8 @@ public final class CraftBlockStates {
|
||||
Material.MANGROVE_WALL_HANGING_SIGN,
|
||||
Material.OAK_HANGING_SIGN,
|
||||
Material.OAK_WALL_HANGING_SIGN,
|
||||
Material.PALE_OAK_HANGING_SIGN,
|
||||
Material.PALE_OAK_WALL_HANGING_SIGN,
|
||||
Material.SPRUCE_HANGING_SIGN,
|
||||
Material.SPRUCE_WALL_HANGING_SIGN,
|
||||
Material.WARPED_HANGING_SIGN,
|
||||
@@ -314,6 +319,7 @@ public final class CraftBlockStates {
|
||||
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.CREAKING_HEART, CraftCreakingHeart.class, CraftCreakingHeart::new, CreakingHeartBlockEntity::new);
|
||||
register(Material.DAYLIGHT_DETECTOR, CraftDaylightDetector.class, CraftDaylightDetector::new, TileEntityLightDetector::new);
|
||||
register(Material.DECORATED_POT, CraftDecoratedPot.class, CraftDecoratedPot::new, DecoratedPotBlockEntity::new);
|
||||
register(Material.DISPENSER, CraftDispenser.class, CraftDispenser::new, TileEntityDispenser::new);
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
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.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 org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Container;
|
||||
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 {
|
||||
|
||||
@@ -19,17 +28,33 @@ public abstract class CraftContainer<T extends TileEntityContainer> extends Craf
|
||||
|
||||
@Override
|
||||
public boolean isLocked() {
|
||||
return !this.getSnapshot().lockKey.key().isEmpty();
|
||||
return this.getSnapshot().lockKey != ChestLock.NO_LOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLock() {
|
||||
return this.getSnapshot().lockKey.key();
|
||||
Optional<? extends IChatBaseComponent> customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME);
|
||||
|
||||
return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLock(String key) {
|
||||
this.getSnapshot().lockKey = (key == null) ? ChestLock.NO_LOCK : new ChestLock(key);
|
||||
if (key == null) {
|
||||
this.getSnapshot().lockKey = ChestLock.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()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockItem(ItemStack key) {
|
||||
if (key == null) {
|
||||
this.getSnapshot().lockKey = ChestLock.NO_LOCK;
|
||||
} else {
|
||||
this.getSnapshot().lockKey = new ChestLock(CraftItemStack.asCriterionConditionItem(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.CreakingHeart;
|
||||
|
||||
public class CraftCreakingHeart extends CraftBlockEntityState<CreakingHeartBlockEntity> implements CreakingHeart {
|
||||
|
||||
public CraftCreakingHeart(World world, CreakingHeartBlockEntity tileEntity) {
|
||||
super(world, tileEntity);
|
||||
}
|
||||
|
||||
protected CraftCreakingHeart(CraftCreakingHeart state, Location location) {
|
||||
super(state, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftCreakingHeart copy() {
|
||||
return new CraftCreakingHeart(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftCreakingHeart copy(Location location) {
|
||||
return new CraftCreakingHeart(this, location);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.block;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.world.level.block.BlockFurnace;
|
||||
import net.minecraft.world.level.block.entity.TileEntityFurnace;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -74,12 +73,12 @@ public abstract class CraftFurnace<T extends TileEntityFurnace> extends CraftCon
|
||||
@Override
|
||||
public Map<CookingRecipe<?>, Integer> getRecipesUsed() {
|
||||
ImmutableMap.Builder<CookingRecipe<?>, Integer> recipesUsed = ImmutableMap.builder();
|
||||
for (Map.Entry<MinecraftKey, Integer> entrySet : this.getSnapshot().getRecipesUsed().object2IntEntrySet()) {
|
||||
Recipe recipe = Bukkit.getRecipe(CraftNamespacedKey.fromMinecraft(entrySet.getKey()));
|
||||
this.getSnapshot().recipesUsed.reference2IntEntrySet().fastForEach(entrySet -> {
|
||||
Recipe recipe = Bukkit.getRecipe(CraftNamespacedKey.fromMinecraft(entrySet.getKey().location()));
|
||||
if (recipe instanceof CookingRecipe<?> cookingRecipe) {
|
||||
recipesUsed.put(cookingRecipe, entrySet.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return recipesUsed.build();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.block.TrialSpawnerBlock;
|
||||
import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData;
|
||||
@@ -151,8 +152,8 @@ public class CraftTrialSpawner extends CraftBlockEntityState<TrialSpawnerBlockEn
|
||||
protected void applyTo(TrialSpawnerBlockEntity tileEntity) {
|
||||
super.applyTo(tileEntity);
|
||||
|
||||
tileEntity.trialSpawner.normalConfig = normalConfig.toMinecraft();
|
||||
tileEntity.trialSpawner.ominousConfig = ominousConfig.toMinecraft();
|
||||
tileEntity.trialSpawner.normalConfig = Holder.direct(normalConfig.toMinecraft());
|
||||
tileEntity.trialSpawner.ominousConfig = Holder.direct(ominousConfig.toMinecraft());
|
||||
}
|
||||
|
||||
private TrialSpawnerData getTrialData() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.commands.arguments.blocks.ArgumentBlock;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.EnumDirection;
|
||||
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.world.level.block.Block;
|
||||
@@ -36,6 +37,7 @@ import org.bukkit.block.PistonMoveReaction;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.structure.Mirror;
|
||||
import org.bukkit.block.structure.StructureRotation;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.CraftSoundGroup;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
@@ -497,9 +499,10 @@ public class CraftBlockData implements BlockData {
|
||||
register(net.minecraft.world.level.block.ChiseledBookShelfBlock.class, org.bukkit.craftbukkit.block.impl.CraftChiseledBookShelf::new);
|
||||
register(net.minecraft.world.level.block.CopperBulbBlock.class, org.bukkit.craftbukkit.block.impl.CraftCopperBulb::new);
|
||||
register(net.minecraft.world.level.block.CrafterBlock.class, org.bukkit.craftbukkit.block.impl.CraftCrafter::new);
|
||||
register(net.minecraft.world.level.block.CreakingHeartBlock.class, org.bukkit.craftbukkit.block.impl.CraftCreakingHeart::new);
|
||||
register(net.minecraft.world.level.block.DecoratedPotBlock.class, org.bukkit.craftbukkit.block.impl.CraftDecoratedPot::new);
|
||||
register(net.minecraft.world.level.block.EquipableCarvedPumpkinBlock.class, org.bukkit.craftbukkit.block.impl.CraftEquipableCarvedPumpkin::new);
|
||||
register(net.minecraft.world.level.block.GlowLichenBlock.class, org.bukkit.craftbukkit.block.impl.CraftGlowLichen::new);
|
||||
register(net.minecraft.world.level.block.HangingMossBlock.class, org.bukkit.craftbukkit.block.impl.CraftHangingMoss::new);
|
||||
register(net.minecraft.world.level.block.HangingRootsBlock.class, org.bukkit.craftbukkit.block.impl.CraftHangingRoots::new);
|
||||
register(net.minecraft.world.level.block.HeavyCoreBlock.class, org.bukkit.craftbukkit.block.impl.CraftHeavyCore::new);
|
||||
register(net.minecraft.world.level.block.InfestedRotatedPillarBlock.class, org.bukkit.craftbukkit.block.impl.CraftInfestedRotatedPillar::new);
|
||||
@@ -509,6 +512,7 @@ public class CraftBlockData implements BlockData {
|
||||
register(net.minecraft.world.level.block.MangroveLeavesBlock.class, org.bukkit.craftbukkit.block.impl.CraftMangroveLeaves::new);
|
||||
register(net.minecraft.world.level.block.MangrovePropaguleBlock.class, org.bukkit.craftbukkit.block.impl.CraftMangrovePropagule::new);
|
||||
register(net.minecraft.world.level.block.MangroveRootsBlock.class, org.bukkit.craftbukkit.block.impl.CraftMangroveRoots::new);
|
||||
register(net.minecraft.world.level.block.MossyCarpetBlock.class, org.bukkit.craftbukkit.block.impl.CraftMossyCarpet::new);
|
||||
register(net.minecraft.world.level.block.PiglinWallSkullBlock.class, org.bukkit.craftbukkit.block.impl.CraftPiglinWallSkull::new);
|
||||
register(net.minecraft.world.level.block.PinkPetalsBlock.class, org.bukkit.craftbukkit.block.impl.CraftPinkPetals::new);
|
||||
register(net.minecraft.world.level.block.PitcherCropBlock.class, org.bukkit.craftbukkit.block.impl.CraftPitcherCrop::new);
|
||||
@@ -555,7 +559,7 @@ public class CraftBlockData implements BlockData {
|
||||
}
|
||||
|
||||
StringReader reader = new StringReader(data);
|
||||
ArgumentBlock.a arg = ArgumentBlock.parseForBlock(BuiltInRegistries.BLOCK.asLookup(), reader, false);
|
||||
ArgumentBlock.a arg = ArgumentBlock.parseForBlock(CraftRegistry.getMinecraftRegistry(Registries.BLOCK), reader, false);
|
||||
Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data: " + data);
|
||||
|
||||
blockData = arg.blockState();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.bukkit.craftbukkit.block.data.type;
|
||||
|
||||
import org.bukkit.block.data.type.CreakingHeart;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
|
||||
public abstract class CraftCreakingHeart extends CraftBlockData implements CreakingHeart {
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateEnum<?> CREAKING = getEnum("creaking");
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.data.type.CreakingHeart.Creaking getCreaking() {
|
||||
return get(CREAKING, org.bukkit.block.data.type.CreakingHeart.Creaking.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreaking(org.bukkit.block.data.type.CreakingHeart.Creaking creaking) {
|
||||
set(CREAKING, creaking);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.bukkit.craftbukkit.block.data.type;
|
||||
|
||||
import org.bukkit.block.data.type.HangingMoss;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
|
||||
public abstract class CraftHangingMoss extends CraftBlockData implements HangingMoss {
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean TIP = getBoolean("tip");
|
||||
|
||||
@Override
|
||||
public boolean isTip() {
|
||||
return get(TIP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTip(boolean tip) {
|
||||
set(TIP, tip);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.bukkit.craftbukkit.block.data.type;
|
||||
|
||||
import org.bukkit.block.data.type.MossyCarpet;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
|
||||
public abstract class CraftMossyCarpet extends CraftBlockData implements MossyCarpet {
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean BOTTOM = getBoolean("bottom");
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateEnum<?>[] HEIGHTS = new net.minecraft.world.level.block.state.properties.BlockStateEnum[]{
|
||||
getEnum("north"), getEnum("east"), getEnum("south"), getEnum("west")
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean isBottom() {
|
||||
return get(BOTTOM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottom(boolean up) {
|
||||
set(BOTTOM, up);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.data.type.MossyCarpet.Height getHeight(org.bukkit.block.BlockFace face) {
|
||||
return get(HEIGHTS[face.ordinal()], org.bukkit.block.data.type.MossyCarpet.Height.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(org.bukkit.block.BlockFace face, org.bukkit.block.data.type.MossyCarpet.Height height) {
|
||||
set(HEIGHTS[face.ordinal()], height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Automatically generated file, changes will be lost.
|
||||
*/
|
||||
package org.bukkit.craftbukkit.block.impl;
|
||||
|
||||
public final class CraftCreakingHeart extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.CreakingHeart, org.bukkit.block.data.Orientable {
|
||||
|
||||
public CraftCreakingHeart() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CraftCreakingHeart(net.minecraft.world.level.block.state.IBlockData state) {
|
||||
super(state);
|
||||
}
|
||||
|
||||
// org.bukkit.craftbukkit.block.data.type.CraftCreakingHeart
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateEnum<?> CREAKING = getEnum(net.minecraft.world.level.block.CreakingHeartBlock.class, "creaking");
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.data.type.CreakingHeart.Creaking getCreaking() {
|
||||
return get(CREAKING, org.bukkit.block.data.type.CreakingHeart.Creaking.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreaking(org.bukkit.block.data.type.CreakingHeart.Creaking creaking) {
|
||||
set(CREAKING, creaking);
|
||||
}
|
||||
|
||||
// org.bukkit.craftbukkit.block.data.CraftOrientable
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateEnum<?> AXIS = getEnum(net.minecraft.world.level.block.CreakingHeartBlock.class, "axis");
|
||||
|
||||
@Override
|
||||
public org.bukkit.Axis getAxis() {
|
||||
return get(AXIS, org.bukkit.Axis.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAxis(org.bukkit.Axis axis) {
|
||||
set(AXIS, axis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Set<org.bukkit.Axis> getAxes() {
|
||||
return getValues(AXIS, org.bukkit.Axis.class);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Automatically generated file, changes will be lost.
|
||||
*/
|
||||
package org.bukkit.craftbukkit.block.impl;
|
||||
|
||||
public final class CraftEquipableCarvedPumpkin extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.Directional {
|
||||
|
||||
public CraftEquipableCarvedPumpkin() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CraftEquipableCarvedPumpkin(net.minecraft.world.level.block.state.IBlockData state) {
|
||||
super(state);
|
||||
}
|
||||
|
||||
// org.bukkit.craftbukkit.block.data.CraftDirectional
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateEnum<?> FACING = getEnum(net.minecraft.world.level.block.EquipableCarvedPumpkinBlock.class, "facing");
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.BlockFace getFacing() {
|
||||
return get(FACING, org.bukkit.block.BlockFace.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFacing(org.bukkit.block.BlockFace facing) {
|
||||
set(FACING, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Set<org.bukkit.block.BlockFace> getFaces() {
|
||||
return getValues(FACING, org.bukkit.block.BlockFace.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Automatically generated file, changes will be lost.
|
||||
*/
|
||||
package org.bukkit.craftbukkit.block.impl;
|
||||
|
||||
public final class CraftHangingMoss extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.HangingMoss {
|
||||
|
||||
public CraftHangingMoss() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CraftHangingMoss(net.minecraft.world.level.block.state.IBlockData state) {
|
||||
super(state);
|
||||
}
|
||||
|
||||
// org.bukkit.craftbukkit.block.data.type.CraftHangingMoss
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean TIP = getBoolean(net.minecraft.world.level.block.HangingMossBlock.class, "tip");
|
||||
|
||||
@Override
|
||||
public boolean isTip() {
|
||||
return get(TIP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTip(boolean tip) {
|
||||
set(TIP, tip);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Automatically generated file, changes will be lost.
|
||||
*/
|
||||
package org.bukkit.craftbukkit.block.impl;
|
||||
|
||||
public final class CraftMossyCarpet extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.MossyCarpet {
|
||||
|
||||
public CraftMossyCarpet() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CraftMossyCarpet(net.minecraft.world.level.block.state.IBlockData state) {
|
||||
super(state);
|
||||
}
|
||||
|
||||
// org.bukkit.craftbukkit.block.data.type.CraftMossyCarpet
|
||||
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean BOTTOM = getBoolean(net.minecraft.world.level.block.MossyCarpetBlock.class, "bottom");
|
||||
private static final net.minecraft.world.level.block.state.properties.BlockStateEnum<?>[] HEIGHTS = new net.minecraft.world.level.block.state.properties.BlockStateEnum[]{
|
||||
getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "north"), getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "east"), getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "south"), getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "west")
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean isBottom() {
|
||||
return get(BOTTOM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottom(boolean up) {
|
||||
set(BOTTOM, up);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.data.type.MossyCarpet.Height getHeight(org.bukkit.block.BlockFace face) {
|
||||
return get(HEIGHTS[face.ordinal()], org.bukkit.block.data.type.MossyCarpet.Height.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(org.bukkit.block.BlockFace face, org.bukkit.block.data.type.MossyCarpet.Height height) {
|
||||
set(HEIGHTS[face.ordinal()], height);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.minecraft.commands.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandListenerWrapper;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartCommandBlock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
@@ -20,7 +21,6 @@ import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftMinecartCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.minecart.CommandMinecart;
|
||||
|
||||
public final class VanillaCommandWrapper extends BukkitCommand {
|
||||
@@ -62,12 +62,12 @@ public final class VanillaCommandWrapper extends BukkitCommand {
|
||||
}
|
||||
|
||||
public static CommandListenerWrapper getListener(CommandSender sender) {
|
||||
if (sender instanceof Entity) {
|
||||
if (sender instanceof CraftEntity entity) {
|
||||
if (sender instanceof CommandMinecart) {
|
||||
return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock().createCommandSourceStack();
|
||||
}
|
||||
|
||||
return ((CraftEntity) sender).getHandle().createCommandSourceStack();
|
||||
return entity.getHandle().createCommandSourceStackForNameResolution((WorldServer) entity.getHandle().level());
|
||||
}
|
||||
if (sender instanceof BlockCommandSender) {
|
||||
return ((CraftBlockCommandSender) sender).getWrapper();
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.entity;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.projectile.EntityArrow;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
@@ -76,7 +77,7 @@ public class CraftAbstractArrow extends AbstractProjectile implements AbstractAr
|
||||
|
||||
@Override
|
||||
public boolean isInBlock() {
|
||||
return getHandle().inGround;
|
||||
return getHandle().isInGround();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,7 +111,9 @@ public class CraftAbstractArrow extends AbstractProjectile implements AbstractAr
|
||||
|
||||
@Override
|
||||
public boolean isShotFromCrossbow() {
|
||||
return getHandle().shotFromCrossbow();
|
||||
net.minecraft.world.item.ItemStack firedFromWeapon = getHandle().getWeaponItem();
|
||||
|
||||
return firedFromWeapon != null && firedFromWeapon.is(Items.CROSSBOW);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -133,7 +133,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
PotionContents old = getHandle().potionContents;
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(color.asRGB()), old.customEffects()));
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(color.asRGB()), old.customEffects(), old.customName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,7 +152,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
||||
@Override
|
||||
public void clearCustomEffects() {
|
||||
PotionContents old = getHandle().potionContents;
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of()));
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of(), old.customName()));
|
||||
getHandle().updateColor();
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
||||
Holder<MobEffectList> minecraft = CraftPotionEffectType.bukkitToMinecraftHolder(effect);
|
||||
|
||||
PotionContents old = getHandle().potionContents;
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList()));
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList(), old.customName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
||||
getHandle().setPotionContents(getHandle().potionContents.withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType)));
|
||||
} else {
|
||||
PotionContents old = getHandle().potionContents;
|
||||
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects()));
|
||||
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects(), old.customName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
|
||||
|
||||
@Override
|
||||
public boolean hasBasePlate() {
|
||||
return !getHandle().isNoBasePlate();
|
||||
return getHandle().showBasePlate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,7 +165,7 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
|
||||
|
||||
@Override
|
||||
public boolean hasArms() {
|
||||
return getHandle().isShowArms();
|
||||
return getHandle().showArms();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,16 +211,16 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
|
||||
|
||||
@Override
|
||||
public void addEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) {
|
||||
getHandle().disabledSlots |= (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterFlag() + lockType.ordinal() * 8);
|
||||
getHandle().disabledSlots |= (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterBit(lockType.ordinal() * 8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) {
|
||||
getHandle().disabledSlots &= ~(1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterFlag() + lockType.ordinal() * 8);
|
||||
getHandle().disabledSlots &= ~(1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterBit(lockType.ordinal() * 8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) {
|
||||
return (getHandle().disabledSlots & (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterFlag() + lockType.ordinal() * 8)) != 0;
|
||||
return (getHandle().disabledSlots & (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterBit(lockType.ordinal() * 8))) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow {
|
||||
@Override
|
||||
public void clearCustomEffects() {
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of()));
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of(), old.customName()));
|
||||
getHandle().updateColor();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow {
|
||||
Holder<MobEffectList> minecraft = CraftPotionEffectType.bukkitToMinecraftHolder(effect);
|
||||
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList()));
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList(), old.customName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow {
|
||||
getHandle().setPotionContents(getHandle().getPotionContents().withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType)));
|
||||
} else {
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects()));
|
||||
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects(), old.customName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow {
|
||||
public void setColor(Color color) {
|
||||
int colorRGB = (color == null) ? -1 : color.asRGB();
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects()));
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects(), old.customName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import net.minecraft.world.entity.vehicle.EntityBoat;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class CraftBoat extends CraftVehicle implements Boat {
|
||||
public abstract class CraftBoat extends CraftVehicle implements Boat {
|
||||
|
||||
public CraftBoat(CraftServer server, EntityBoat entity) {
|
||||
public CraftBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeSpecies getWoodType() {
|
||||
return getTreeSpecies(getHandle().getVariant());
|
||||
return getTreeSpecies(getHandle().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWoodType(TreeSpecies species) {
|
||||
getHandle().setVariant(getBoatType(species));
|
||||
throw new UnsupportedOperationException("Not supported - you must spawn a new entity to change boat type.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getBoatType() {
|
||||
return boatTypeFromNms(getHandle().getVariant());
|
||||
return boatTypeFromNms(getHandle().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoatType(Type type) {
|
||||
Preconditions.checkArgument(type != null, "Boat.Type cannot be null");
|
||||
|
||||
getHandle().setVariant(boatTypeToNms(type));
|
||||
throw new UnsupportedOperationException("Not supported - you must spawn a new entity to change boat type.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,8 +85,8 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityBoat getHandle() {
|
||||
return (EntityBoat) entity;
|
||||
public AbstractBoat getHandle() {
|
||||
return (AbstractBoat) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,34 +94,44 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
||||
return "CraftBoat{boatType=" + getBoatType() + ",status=" + getStatus() + ",passengers=" + getPassengers().stream().map(Entity::toString).collect(Collectors.joining("-", "{", "}")) + "}";
|
||||
}
|
||||
|
||||
public static Boat.Type boatTypeFromNms(EntityBoat.EnumBoatType boatType) {
|
||||
return switch (boatType) {
|
||||
default -> throw new EnumConstantNotPresentException(Type.class, boatType.name());
|
||||
case OAK -> Type.OAK;
|
||||
case BIRCH -> Type.BIRCH;
|
||||
case ACACIA -> Type.ACACIA;
|
||||
case CHERRY -> Type.CHERRY;
|
||||
case JUNGLE -> Type.JUNGLE;
|
||||
case SPRUCE -> Type.SPRUCE;
|
||||
case DARK_OAK -> Type.DARK_OAK;
|
||||
case MANGROVE -> Type.MANGROVE;
|
||||
case BAMBOO -> Type.BAMBOO;
|
||||
};
|
||||
}
|
||||
public static Boat.Type boatTypeFromNms(EntityTypes<?> boatType) {
|
||||
if (boatType == EntityTypes.OAK_BOAT || boatType == EntityTypes.OAK_CHEST_BOAT) {
|
||||
return Type.OAK;
|
||||
}
|
||||
|
||||
public static EntityBoat.EnumBoatType boatTypeToNms(Boat.Type type) {
|
||||
return switch (type) {
|
||||
default -> throw new EnumConstantNotPresentException(EntityBoat.EnumBoatType.class, type.name());
|
||||
case BAMBOO -> EntityBoat.EnumBoatType.BAMBOO;
|
||||
case MANGROVE -> EntityBoat.EnumBoatType.MANGROVE;
|
||||
case SPRUCE -> EntityBoat.EnumBoatType.SPRUCE;
|
||||
case DARK_OAK -> EntityBoat.EnumBoatType.DARK_OAK;
|
||||
case JUNGLE -> EntityBoat.EnumBoatType.JUNGLE;
|
||||
case CHERRY -> EntityBoat.EnumBoatType.CHERRY;
|
||||
case ACACIA -> EntityBoat.EnumBoatType.ACACIA;
|
||||
case BIRCH -> EntityBoat.EnumBoatType.BIRCH;
|
||||
case OAK -> EntityBoat.EnumBoatType.OAK;
|
||||
};
|
||||
if (boatType == EntityTypes.BIRCH_BOAT || boatType == EntityTypes.BIRCH_CHEST_BOAT) {
|
||||
return Type.BIRCH;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.ACACIA_BOAT || boatType == EntityTypes.ACACIA_CHEST_BOAT) {
|
||||
return Type.ACACIA;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.CHERRY_BOAT || boatType == EntityTypes.CHERRY_CHEST_BOAT) {
|
||||
return Type.CHERRY;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.JUNGLE_BOAT || boatType == EntityTypes.JUNGLE_CHEST_BOAT) {
|
||||
return Type.JUNGLE;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.SPRUCE_BOAT || boatType == EntityTypes.SPRUCE_CHEST_BOAT) {
|
||||
return Type.SPRUCE;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.DARK_OAK_BOAT || boatType == EntityTypes.DARK_OAK_CHEST_BOAT) {
|
||||
return Type.DARK_OAK;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.MANGROVE_BOAT || boatType == EntityTypes.MANGROVE_CHEST_BOAT) {
|
||||
return Type.MANGROVE;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.BAMBOO_RAFT || boatType == EntityTypes.BAMBOO_CHEST_RAFT) {
|
||||
return Type.BAMBOO;
|
||||
}
|
||||
|
||||
throw new EnumConstantNotPresentException(Type.class, boatType.toString());
|
||||
}
|
||||
|
||||
public static Status boatStatusFromNms(EntityBoat.EnumStatus enumStatus) {
|
||||
@@ -137,40 +146,27 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static TreeSpecies getTreeSpecies(EntityBoat.EnumBoatType boatType) {
|
||||
switch (boatType) {
|
||||
case SPRUCE:
|
||||
return TreeSpecies.REDWOOD;
|
||||
case BIRCH:
|
||||
return TreeSpecies.BIRCH;
|
||||
case JUNGLE:
|
||||
return TreeSpecies.JUNGLE;
|
||||
case ACACIA:
|
||||
return TreeSpecies.ACACIA;
|
||||
case DARK_OAK:
|
||||
return TreeSpecies.DARK_OAK;
|
||||
case OAK:
|
||||
default:
|
||||
return TreeSpecies.GENERIC;
|
||||
public static TreeSpecies getTreeSpecies(EntityTypes<?> boatType) {
|
||||
if (boatType == EntityTypes.SPRUCE_BOAT || boatType == EntityTypes.SPRUCE_CHEST_BOAT) {
|
||||
return TreeSpecies.REDWOOD;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static EntityBoat.EnumBoatType getBoatType(TreeSpecies species) {
|
||||
switch (species) {
|
||||
case REDWOOD:
|
||||
return EntityBoat.EnumBoatType.SPRUCE;
|
||||
case BIRCH:
|
||||
return EntityBoat.EnumBoatType.BIRCH;
|
||||
case JUNGLE:
|
||||
return EntityBoat.EnumBoatType.JUNGLE;
|
||||
case ACACIA:
|
||||
return EntityBoat.EnumBoatType.ACACIA;
|
||||
case DARK_OAK:
|
||||
return EntityBoat.EnumBoatType.DARK_OAK;
|
||||
case GENERIC:
|
||||
default:
|
||||
return EntityBoat.EnumBoatType.OAK;
|
||||
if (boatType == EntityTypes.BIRCH_BOAT || boatType == EntityTypes.BIRCH_CHEST_BOAT) {
|
||||
return TreeSpecies.BIRCH;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.JUNGLE_BOAT || boatType == EntityTypes.JUNGLE_CHEST_BOAT) {
|
||||
return TreeSpecies.JUNGLE;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.ACACIA_BOAT || boatType == EntityTypes.ACACIA_CHEST_BOAT) {
|
||||
return TreeSpecies.ACACIA;
|
||||
}
|
||||
|
||||
if (boatType == EntityTypes.DARK_OAK_BOAT || boatType == EntityTypes.DARK_OAK_CHEST_BOAT) {
|
||||
return TreeSpecies.DARK_OAK;
|
||||
}
|
||||
|
||||
return TreeSpecies.GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.ChestBoat;
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftLootTable;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.loot.LootTable;
|
||||
|
||||
public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.ChestBoat {
|
||||
public abstract class CraftChestBoat extends CraftBoat implements org.bukkit.entity.ChestBoat {
|
||||
|
||||
private final Inventory inventory;
|
||||
|
||||
public CraftChestBoat(CraftServer server, ChestBoat entity) {
|
||||
public CraftChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
inventory = new CraftInventory(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChestBoat getHandle() {
|
||||
return (ChestBoat) entity;
|
||||
public AbstractChestBoat getHandle() {
|
||||
return (AbstractChestBoat) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +38,7 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest
|
||||
|
||||
@Override
|
||||
public LootTable getLootTable() {
|
||||
return CraftLootTable.minecraftToBukkit(getHandle().getLootTable());
|
||||
return CraftLootTable.minecraftToBukkit(getHandle().getContainerLootTable());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,11 +48,11 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return getHandle().getLootTableSeed();
|
||||
return getHandle().getContainerLootTableSeed();
|
||||
}
|
||||
|
||||
private void setLootTable(LootTable table, long seed) {
|
||||
getHandle().setLootTable(CraftLootTable.bukkitToMinecraft(table));
|
||||
getHandle().setLootTableSeed(seed);
|
||||
getHandle().setContainerLootTable(CraftLootTable.bukkitToMinecraft(table));
|
||||
getHandle().setContainerLootTableSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.world.entity.monster.creaking.Creaking;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
public class CraftCreaking extends CraftMonster implements org.bukkit.entity.Creaking {
|
||||
|
||||
public CraftCreaking(CraftServer server, Creaking entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Creaking getHandle() {
|
||||
return (Creaking) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftCreaking";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.world.entity.monster.creaking.CreakingTransient;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
public class CraftCreakingTransient extends CraftCreaking implements org.bukkit.entity.CreakingTransient {
|
||||
|
||||
public CraftCreakingTransient(CraftServer server, CreakingTransient entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreakingTransient getHandle() {
|
||||
return (CreakingTransient) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftCreakingTransient";
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import net.minecraft.world.entity.animal.EntityDolphin;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Dolphin;
|
||||
|
||||
public class CraftDolphin extends CraftWaterMob implements Dolphin {
|
||||
public class CraftDolphin extends CraftAgeable implements Dolphin {
|
||||
|
||||
public CraftDolphin(CraftServer server, EntityDolphin entity) {
|
||||
super(server, entity);
|
||||
|
||||
@@ -16,12 +16,13 @@ import net.minecraft.server.level.PlayerChunkMap;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.boss.EntityComplexPart;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
import net.minecraft.world.entity.projectile.EntityArrow;
|
||||
import net.minecraft.world.level.portal.DimensionTransition;
|
||||
import net.minecraft.world.level.portal.TeleportTransition;
|
||||
import net.minecraft.world.phys.AxisAlignedBB;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.EntityEffect;
|
||||
@@ -153,7 +154,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
@Override
|
||||
public boolean isOnGround() {
|
||||
if (entity instanceof EntityArrow) {
|
||||
return ((EntityArrow) entity).inGround;
|
||||
return ((EntityArrow) entity).isInGround();
|
||||
}
|
||||
return entity.onGround();
|
||||
}
|
||||
@@ -204,7 +205,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
if (location.getWorld() != null && !location.getWorld().equals(getWorld())) {
|
||||
// Prevent teleportation to an other world during world generation
|
||||
Preconditions.checkState(!entity.generation, "Cannot teleport entity to an other world during world generation");
|
||||
entity.changeDimension(new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getPitch(), location.getYaw(), DimensionTransition.DO_NOTHING, TeleportCause.PLUGIN));
|
||||
entity.teleport(new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getPitch(), location.getYaw(), Set.of(), TeleportTransition.DO_NOTHING, TeleportCause.PLUGIN));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -703,7 +704,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerable() {
|
||||
return getHandle().isInvulnerableTo(getHandle().damageSources().generic());
|
||||
return getHandle().isInvulnerableToBase(getHandle().damageSources().generic());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -820,7 +821,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
NBTTagCompound compoundTag = new NBTTagCompound();
|
||||
getHandle().saveAsPassenger(compoundTag, false);
|
||||
|
||||
return EntityTypes.loadEntityRecursive(compoundTag, level, java.util.function.Function.identity());
|
||||
return EntityTypes.loadEntityRecursive(compoundTag, level, EntitySpawnReason.LOAD, java.util.function.Function.identity());
|
||||
}
|
||||
|
||||
public void storeBukkitValues(NBTTagCompound c) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.entity;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -49,9 +50,9 @@ public class CraftEntitySnapshot implements EntitySnapshot {
|
||||
|
||||
private net.minecraft.world.entity.Entity createInternal(World world) {
|
||||
net.minecraft.world.level.World nms = ((CraftWorld) world).getHandle();
|
||||
net.minecraft.world.entity.Entity internal = EntityTypes.loadEntityRecursive(data, nms, Function.identity());
|
||||
net.minecraft.world.entity.Entity internal = EntityTypes.loadEntityRecursive(data, nms, EntitySpawnReason.LOAD, Function.identity());
|
||||
if (internal == null) { // Try creating by type
|
||||
internal = CraftEntityType.bukkitToMinecraft(type).create(nms);
|
||||
internal = CraftEntityType.bukkitToMinecraft(type).create(nms, EntitySpawnReason.LOAD);
|
||||
}
|
||||
|
||||
Preconditions.checkArgument(internal != null, "Error creating new entity."); // This should only fail if the stored NBTTagCompound is malformed.
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.entity;
|
||||
|
||||
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.EntityTypes;
|
||||
@@ -33,6 +34,19 @@ public class CraftEntityType {
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<EntityTypes<?>> bukkitToMinecraftHolder(EntityType bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<EntityTypes<?>> registry = CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<EntityTypes<?>> 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.");
|
||||
}
|
||||
|
||||
public static String bukkitToString(EntityType bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.EnumDirection;
|
||||
import net.minecraft.world.entity.EntityAreaEffectCloud;
|
||||
import net.minecraft.world.entity.EntityExperienceOrb;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
|
||||
import net.minecraft.world.entity.decoration.EntityHanging;
|
||||
@@ -28,13 +29,8 @@ import net.minecraft.world.entity.projectile.EntityFireball;
|
||||
import net.minecraft.world.entity.projectile.EntityFireworks;
|
||||
import net.minecraft.world.entity.projectile.EntityPotion;
|
||||
import net.minecraft.world.entity.projectile.EntitySnowball;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartChest;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartCommandBlock;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartFurnace;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartHopper;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartMobSpawner;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartRideable;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartTNT;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartAbstract;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.GeneratorAccessSeed;
|
||||
import net.minecraft.world.level.World;
|
||||
@@ -44,11 +40,29 @@ import net.minecraft.world.phys.AxisAlignedBB;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftAcaciaBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftAcaciaChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftBambooChestRaft;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftBambooRaft;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftBirchBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftBirchChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftCherryBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftCherryChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftDarkOakBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftDarkOakChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftJungleBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftJungleChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftMangroveBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftMangroveChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftOakBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftOakChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftPaleOakBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftPaleOakChestBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftSpruceBoat;
|
||||
import org.bukkit.craftbukkit.entity.boat.CraftSpruceChestBoat;
|
||||
import org.bukkit.entity.Allay;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.Armadillo;
|
||||
@@ -59,17 +73,17 @@ import org.bukkit.entity.Bat;
|
||||
import org.bukkit.entity.Bee;
|
||||
import org.bukkit.entity.Blaze;
|
||||
import org.bukkit.entity.BlockDisplay;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Bogged;
|
||||
import org.bukkit.entity.Breeze;
|
||||
import org.bukkit.entity.BreezeWindCharge;
|
||||
import org.bukkit.entity.Camel;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.CaveSpider;
|
||||
import org.bukkit.entity.ChestBoat;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.Cod;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.Creaking;
|
||||
import org.bukkit.entity.CreakingTransient;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Dolphin;
|
||||
import org.bukkit.entity.Donkey;
|
||||
@@ -175,6 +189,26 @@ import org.bukkit.entity.Zoglin;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.entity.ZombieHorse;
|
||||
import org.bukkit.entity.ZombieVillager;
|
||||
import org.bukkit.entity.boat.AcaciaBoat;
|
||||
import org.bukkit.entity.boat.AcaciaChestBoat;
|
||||
import org.bukkit.entity.boat.BambooChestRaft;
|
||||
import org.bukkit.entity.boat.BambooRaft;
|
||||
import org.bukkit.entity.boat.BirchBoat;
|
||||
import org.bukkit.entity.boat.BirchChestBoat;
|
||||
import org.bukkit.entity.boat.CherryBoat;
|
||||
import org.bukkit.entity.boat.CherryChestBoat;
|
||||
import org.bukkit.entity.boat.DarkOakBoat;
|
||||
import org.bukkit.entity.boat.DarkOakChestBoat;
|
||||
import org.bukkit.entity.boat.JungleBoat;
|
||||
import org.bukkit.entity.boat.JungleChestBoat;
|
||||
import org.bukkit.entity.boat.MangroveBoat;
|
||||
import org.bukkit.entity.boat.MangroveChestBoat;
|
||||
import org.bukkit.entity.boat.OakBoat;
|
||||
import org.bukkit.entity.boat.OakChestBoat;
|
||||
import org.bukkit.entity.boat.PaleOakBoat;
|
||||
import org.bukkit.entity.boat.PaleOakChestBoat;
|
||||
import org.bukkit.entity.boat.SpruceBoat;
|
||||
import org.bukkit.entity.boat.SpruceChestBoat;
|
||||
import org.bukkit.entity.minecart.CommandMinecart;
|
||||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
import org.bukkit.entity.minecart.HopperMinecart;
|
||||
@@ -182,7 +216,6 @@ import org.bukkit.entity.minecart.PoweredMinecart;
|
||||
import org.bukkit.entity.minecart.RideableMinecart;
|
||||
import org.bukkit.entity.minecart.SpawnerMinecart;
|
||||
import org.bukkit.entity.minecart.StorageMinecart;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class CraftEntityTypes {
|
||||
@@ -317,6 +350,8 @@ public final class CraftEntityTypes {
|
||||
register(new EntityTypeData<>(EntityType.SNIFFER, Sniffer.class, CraftSniffer::new, createLiving(EntityTypes.SNIFFER)));
|
||||
register(new EntityTypeData<>(EntityType.BREEZE, Breeze.class, CraftBreeze::new, createLiving(EntityTypes.BREEZE)));
|
||||
register(new EntityTypeData<>(EntityType.ARMADILLO, Armadillo.class, CraftArmadillo::new, createLiving(EntityTypes.ARMADILLO)));
|
||||
register(new EntityTypeData<>(EntityType.CREAKING, Creaking.class, CraftCreaking::new, createLiving(EntityTypes.CREAKING)));
|
||||
register(new EntityTypeData<>(EntityType.CREAKING_TRANSIENT, CreakingTransient.class, CraftCreakingTransient::new, createLiving(EntityTypes.CREAKING_TRANSIENT)));
|
||||
|
||||
Function<SpawnData, EntityEnderDragon> dragonFunction = createLiving(EntityTypes.ENDER_DRAGON);
|
||||
register(new EntityTypeData<>(EntityType.ENDER_DRAGON, EnderDragon.class, CraftEnderDragon::new, spawnData -> {
|
||||
@@ -358,10 +393,29 @@ public final class CraftEntityTypes {
|
||||
|
||||
// Move
|
||||
register(new EntityTypeData<>(EntityType.SHULKER_BULLET, ShulkerBullet.class, CraftShulkerBullet::new, createAndMove(EntityTypes.SHULKER_BULLET)));
|
||||
register(new EntityTypeData<>(EntityType.BOAT, Boat.class, CraftBoat::new, createAndMove(EntityTypes.BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.LLAMA_SPIT, LlamaSpit.class, CraftLlamaSpit::new, createAndMove(EntityTypes.LLAMA_SPIT)));
|
||||
register(new EntityTypeData<>(EntityType.CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(EntityTypes.CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.OMINOUS_ITEM_SPAWNER, OminousItemSpawner.class, CraftOminousItemSpawner::new, createAndMove(EntityTypes.OMINOUS_ITEM_SPAWNER)));
|
||||
// Move (boats)
|
||||
register(new EntityTypeData<>(EntityType.ACACIA_BOAT, AcaciaBoat.class, CraftAcaciaBoat::new, createAndMove(EntityTypes.ACACIA_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.ACACIA_CHEST_BOAT, AcaciaChestBoat.class, CraftAcaciaChestBoat::new, createAndMove(EntityTypes.ACACIA_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.BAMBOO_RAFT, BambooRaft.class, CraftBambooRaft::new, createAndMove(EntityTypes.BAMBOO_RAFT)));
|
||||
register(new EntityTypeData<>(EntityType.BAMBOO_CHEST_RAFT, BambooChestRaft.class, CraftBambooChestRaft::new, createAndMove(EntityTypes.BAMBOO_CHEST_RAFT)));
|
||||
register(new EntityTypeData<>(EntityType.BIRCH_BOAT, BirchBoat.class, CraftBirchBoat::new, createAndMove(EntityTypes.BIRCH_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.BIRCH_CHEST_BOAT, BirchChestBoat.class, CraftBirchChestBoat::new, createAndMove(EntityTypes.BIRCH_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.CHERRY_BOAT, CherryBoat.class, CraftCherryBoat::new, createAndMove(EntityTypes.CHERRY_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.CHERRY_CHEST_BOAT, CherryChestBoat.class, CraftCherryChestBoat::new, createAndMove(EntityTypes.CHERRY_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.DARK_OAK_BOAT, DarkOakBoat.class, CraftDarkOakBoat::new, createAndMove(EntityTypes.DARK_OAK_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.DARK_OAK_CHEST_BOAT, DarkOakChestBoat.class, CraftDarkOakChestBoat::new, createAndMove(EntityTypes.DARK_OAK_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.JUNGLE_BOAT, JungleBoat.class, CraftJungleBoat::new, createAndMove(EntityTypes.JUNGLE_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.JUNGLE_CHEST_BOAT, JungleChestBoat.class, CraftJungleChestBoat::new, createAndMove(EntityTypes.JUNGLE_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.MANGROVE_BOAT, MangroveBoat.class, CraftMangroveBoat::new, createAndMove(EntityTypes.MANGROVE_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.MANGROVE_CHEST_BOAT, MangroveChestBoat.class, CraftMangroveChestBoat::new, createAndMove(EntityTypes.MANGROVE_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.OAK_BOAT, OakBoat.class, CraftOakBoat::new, createAndMove(EntityTypes.OAK_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.OAK_CHEST_BOAT, OakChestBoat.class, CraftOakChestBoat::new, createAndMove(EntityTypes.OAK_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.PALE_OAK_BOAT, PaleOakBoat.class, CraftPaleOakBoat::new, createAndMove(EntityTypes.PALE_OAK_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.PALE_OAK_CHEST_BOAT, PaleOakChestBoat.class, CraftPaleOakChestBoat::new, createAndMove(EntityTypes.PALE_OAK_CHEST_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.SPRUCE_BOAT, SpruceBoat.class, CraftSpruceBoat::new, createAndMove(EntityTypes.SPRUCE_BOAT)));
|
||||
register(new EntityTypeData<>(EntityType.SPRUCE_CHEST_BOAT, SpruceChestBoat.class, CraftSpruceChestBoat::new, createAndMove(EntityTypes.SPRUCE_CHEST_BOAT)));
|
||||
|
||||
// Set pos
|
||||
register(new EntityTypeData<>(EntityType.MARKER, Marker.class, CraftMarker::new, createAndSetPos(EntityTypes.MARKER)));
|
||||
@@ -384,13 +438,12 @@ public final class CraftEntityTypes {
|
||||
spawnData -> new EntityExperienceOrb(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), 0)
|
||||
));
|
||||
register(new EntityTypeData<>(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloud.class, CraftAreaEffectCloud::new, spawnData -> new EntityAreaEffectCloud(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.EGG, Egg.class, CraftEgg::new, spawnData -> new EntityEgg(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.EGG, Egg.class, CraftEgg::new, spawnData -> new EntityEgg(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), new net.minecraft.world.item.ItemStack(Items.EGG))));
|
||||
register(new EntityTypeData<>(EntityType.LEASH_KNOT, LeashHitch.class, CraftLeash::new, spawnData -> new EntityLeash(spawnData.minecraftWorld(), BlockPosition.containing(spawnData.x(), spawnData.y(), spawnData.z())))); // SPIGOT-5732: LeashHitch has no direction and is always centered at a block
|
||||
register(new EntityTypeData<>(EntityType.SNOWBALL, Snowball.class, CraftSnowball::new, spawnData -> new EntitySnowball(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.SNOWBALL, Snowball.class, CraftSnowball::new, spawnData -> new EntitySnowball(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), new net.minecraft.world.item.ItemStack(Items.SNOWBALL))));
|
||||
register(new EntityTypeData<>(EntityType.EYE_OF_ENDER, EnderSignal.class, CraftEnderSignal::new, spawnData -> new EntityEnderSignal(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.POTION, ThrownPotion.class, CraftThrownPotion::new, spawnData -> {
|
||||
EntityPotion entity = new EntityPotion(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z());
|
||||
entity.setItem(CraftItemStack.asNMSCopy(new ItemStack(Material.SPLASH_POTION, 1)));
|
||||
EntityPotion entity = new EntityPotion(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), new net.minecraft.world.item.ItemStack(Items.SPLASH_POTION));
|
||||
return entity;
|
||||
}));
|
||||
register(new EntityTypeData<>(EntityType.TNT, TNTPrimed.class, CraftTNTPrimed::new, spawnData -> new EntityTNTPrimed(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), null)));
|
||||
@@ -400,13 +453,13 @@ public final class CraftEntityTypes {
|
||||
}));
|
||||
register(new EntityTypeData<>(EntityType.FIREWORK_ROCKET, Firework.class, CraftFirework::new, spawnData -> new EntityFireworks(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), net.minecraft.world.item.ItemStack.EMPTY)));
|
||||
register(new EntityTypeData<>(EntityType.EVOKER_FANGS, EvokerFangs.class, CraftEvokerFangs::new, spawnData -> new EntityEvokerFangs(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), (float) Math.toRadians(spawnData.yaw()), 0, null)));
|
||||
register(new EntityTypeData<>(EntityType.COMMAND_BLOCK_MINECART, CommandMinecart.class, CraftMinecartCommand::new, spawnData -> new EntityMinecartCommandBlock(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.MINECART, RideableMinecart.class, CraftMinecartRideable::new, spawnData -> new EntityMinecartRideable(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.CHEST_MINECART, StorageMinecart.class, CraftMinecartChest::new, spawnData -> new EntityMinecartChest(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.FURNACE_MINECART, PoweredMinecart.class, CraftMinecartFurnace::new, spawnData -> new EntityMinecartFurnace(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.TNT_MINECART, ExplosiveMinecart.class, CraftMinecartTNT::new, spawnData -> new EntityMinecartTNT(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.HOPPER_MINECART, HopperMinecart.class, CraftMinecartHopper::new, spawnData -> new EntityMinecartHopper(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.SPAWNER_MINECART, SpawnerMinecart.class, CraftMinecartMobSpawner::new, spawnData -> new EntityMinecartMobSpawner(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z())));
|
||||
register(new EntityTypeData<>(EntityType.COMMAND_BLOCK_MINECART, CommandMinecart.class, CraftMinecartCommand::new, createMinecart(EntityTypes.COMMAND_BLOCK_MINECART)));
|
||||
register(new EntityTypeData<>(EntityType.MINECART, RideableMinecart.class, CraftMinecartRideable::new, createMinecart(EntityTypes.MINECART)));
|
||||
register(new EntityTypeData<>(EntityType.CHEST_MINECART, StorageMinecart.class, CraftMinecartChest::new, createMinecart(EntityTypes.CHEST_MINECART)));
|
||||
register(new EntityTypeData<>(EntityType.FURNACE_MINECART, PoweredMinecart.class, CraftMinecartFurnace::new, createMinecart(EntityTypes.FURNACE_MINECART)));
|
||||
register(new EntityTypeData<>(EntityType.TNT_MINECART, ExplosiveMinecart.class, CraftMinecartTNT::new, createMinecart(EntityTypes.TNT_MINECART)));
|
||||
register(new EntityTypeData<>(EntityType.HOPPER_MINECART, HopperMinecart.class, CraftMinecartHopper::new, createMinecart(EntityTypes.HOPPER_MINECART)));
|
||||
register(new EntityTypeData<>(EntityType.SPAWNER_MINECART, SpawnerMinecart.class, CraftMinecartMobSpawner::new, createMinecart(EntityTypes.SPAWNER_MINECART)));
|
||||
|
||||
// None spawn able
|
||||
register(new EntityTypeData<>(EntityType.FISHING_BOBBER, FishHook.class, CraftFishHook::new, null)); // Cannot spawn a fish hook
|
||||
@@ -426,7 +479,7 @@ public final class CraftEntityTypes {
|
||||
}
|
||||
|
||||
private static <R extends net.minecraft.world.entity.Entity> Function<SpawnData, R> fromEntityType(EntityTypes<R> entityTypes) {
|
||||
return spawnData -> entityTypes.create(spawnData.minecraftWorld());
|
||||
return spawnData -> entityTypes.create(spawnData.minecraftWorld(), EntitySpawnReason.COMMAND);
|
||||
}
|
||||
|
||||
private static <R extends net.minecraft.world.entity.EntityLiving> Function<SpawnData, R> createLiving(EntityTypes<R> entityTypes) {
|
||||
@@ -437,6 +490,10 @@ public final class CraftEntityTypes {
|
||||
return combine(createAndMove(entityTypes), DIRECTION);
|
||||
}
|
||||
|
||||
private static <R extends EntityMinecartAbstract> Function<SpawnData, R> createMinecart(EntityTypes<R> entityTypes) {
|
||||
return spawnData -> EntityMinecartAbstract.createMinecart(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), entityTypes, EntitySpawnReason.TRIGGERED, ItemStack.EMPTY, null);
|
||||
}
|
||||
|
||||
private static <R extends net.minecraft.world.entity.Entity> Function<SpawnData, R> createAndMove(EntityTypes<R> entityTypes) {
|
||||
return combine(fromEntityType(entityTypes), MOVE);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.network.protocol.game.PacketPlayInCloseWindow;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.world.ITileInventory;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.EnumMainHand;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
@@ -45,11 +47,10 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryLectern;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemType;
|
||||
import org.bukkit.craftbukkit.inventory.CraftMerchantCustom;
|
||||
import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Villager;
|
||||
@@ -493,7 +494,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
Preconditions.checkArgument(material != null, "Material cannot be null");
|
||||
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material);
|
||||
|
||||
return getHandle().getCooldowns().isOnCooldown(CraftItemType.bukkitToMinecraft(material));
|
||||
return hasCooldown(new ItemStack(material));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -501,17 +502,40 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
Preconditions.checkArgument(material != null, "Material cannot be null");
|
||||
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material);
|
||||
|
||||
ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(CraftItemType.bukkitToMinecraft(material));
|
||||
return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - getHandle().getCooldowns().tickCount);
|
||||
return getCooldown(new ItemStack(material));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCooldown(Material material, int ticks) {
|
||||
Preconditions.checkArgument(material != null, "Material cannot be null");
|
||||
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material);
|
||||
setCooldown(new ItemStack(material), ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCooldown(ItemStack item) {
|
||||
Preconditions.checkArgument(item != null, "Material cannot be null");
|
||||
|
||||
return getHandle().getCooldowns().isOnCooldown(CraftItemStack.asNMSCopy(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCooldown(ItemStack item) {
|
||||
Preconditions.checkArgument(item != null, "Material cannot be null");
|
||||
|
||||
MinecraftKey group = getHandle().getCooldowns().getCooldownGroup(CraftItemStack.asNMSCopy(item));
|
||||
if (group == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(group);
|
||||
return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - getHandle().getCooldowns().tickCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCooldown(ItemStack item, int ticks) {
|
||||
Preconditions.checkArgument(item != null, "Material cannot be null");
|
||||
Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown");
|
||||
|
||||
getHandle().getCooldowns().addCooldown(CraftItemType.bukkitToMinecraft(material), ticks);
|
||||
getHandle().getCooldowns().addCooldown(CraftItemStack.asNMSCopy(item), ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -549,7 +573,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
CraftingManager manager = getHandle().level().getServer().getRecipeManager();
|
||||
|
||||
for (NamespacedKey recipeKey : recipeKeys) {
|
||||
Optional<? extends RecipeHolder<?>> recipe = manager.byKey(CraftNamespacedKey.toMinecraft(recipeKey));
|
||||
Optional<? extends RecipeHolder<?>> recipe = manager.byKey(CraftRecipe.toMinecraft(recipeKey));
|
||||
if (!recipe.isPresent()) {
|
||||
continue;
|
||||
}
|
||||
@@ -563,7 +587,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getShoulderEntityLeft() {
|
||||
if (!getHandle().getShoulderEntityLeft().isEmpty()) {
|
||||
Optional<Entity> shoulder = EntityTypes.create(getHandle().getShoulderEntityLeft(), getHandle().level());
|
||||
Optional<Entity> shoulder = EntityTypes.create(getHandle().getShoulderEntityLeft(), getHandle().level(), EntitySpawnReason.LOAD);
|
||||
|
||||
return (!shoulder.isPresent()) ? null : shoulder.get().getBukkitEntity();
|
||||
}
|
||||
@@ -582,7 +606,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getShoulderEntityRight() {
|
||||
if (!getHandle().getShoulderEntityRight().isEmpty()) {
|
||||
Optional<Entity> shoulder = EntityTypes.create(getHandle().getShoulderEntityRight(), getHandle().level());
|
||||
Optional<Entity> shoulder = EntityTypes.create(getHandle().getShoulderEntityRight(), getHandle().level(), EntitySpawnReason.LOAD);
|
||||
|
||||
return (!shoulder.isPresent()) ? null : shoulder.get().getBukkitEntity();
|
||||
}
|
||||
|
||||
@@ -8,14 +8,17 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.sounds.SoundEffect;
|
||||
import net.minecraft.sounds.SoundEffects;
|
||||
import net.minecraft.world.EnumHand;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import net.minecraft.world.entity.EntityLiving;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.ai.attributes.GenericAttributes;
|
||||
import net.minecraft.world.entity.boss.wither.EntityWither;
|
||||
@@ -40,6 +43,8 @@ import net.minecraft.world.entity.projectile.EntityThrownExpBottle;
|
||||
import net.minecraft.world.entity.projectile.EntityThrownTrident;
|
||||
import net.minecraft.world.entity.projectile.EntityTippedArrow;
|
||||
import net.minecraft.world.entity.projectile.EntityWitherSkull;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.component.Consumable;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -296,6 +301,11 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
getHandle().getEntityData().set(EntityLiving.DATA_ARROW_COUNT_ID, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerable() {
|
||||
return getHandle().isInvulnerableTo((WorldServer) getHandle().level(), getHandle().damageSources().generic());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damage(double amount) {
|
||||
damage(amount, getHandle().damageSources().generic());
|
||||
@@ -454,13 +464,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
net.minecraft.world.entity.Entity launch = null;
|
||||
|
||||
if (Snowball.class.isAssignableFrom(projectile)) {
|
||||
launch = new EntitySnowball(world, getHandle());
|
||||
launch = new EntitySnowball(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.SNOWBALL));
|
||||
((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F); // ItemSnowball
|
||||
} else if (Egg.class.isAssignableFrom(projectile)) {
|
||||
launch = new EntityEgg(world, getHandle());
|
||||
launch = new EntityEgg(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.EGG));
|
||||
((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F); // ItemEgg
|
||||
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
|
||||
launch = new EntityEnderPearl(world, getHandle());
|
||||
launch = new EntityEnderPearl(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.ENDER_PEARL));
|
||||
((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F); // ItemEnderPearl
|
||||
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
|
||||
if (TippedArrow.class.isAssignableFrom(projectile)) {
|
||||
@@ -476,18 +486,16 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
((EntityArrow) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 3.0F, 1.0F); // ItemBow
|
||||
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
|
||||
if (LingeringPotion.class.isAssignableFrom(projectile)) {
|
||||
launch = new EntityPotion(world, getHandle());
|
||||
((EntityPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
|
||||
launch = new EntityPotion(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.LINGERING_POTION));
|
||||
} else {
|
||||
launch = new EntityPotion(world, getHandle());
|
||||
((EntityPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
|
||||
launch = new EntityPotion(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.SPLASH_POTION));
|
||||
}
|
||||
((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), -20.0F, 0.5F, 1.0F); // ItemSplashPotion
|
||||
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
|
||||
launch = new EntityThrownExpBottle(world, getHandle());
|
||||
launch = new EntityThrownExpBottle(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.EXPERIENCE_BOTTLE));
|
||||
((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), -20.0F, 0.7F, 1.0F); // ItemExpBottle
|
||||
} else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof EntityHuman) {
|
||||
launch = new EntityFishingHook((EntityHuman) getHandle(), world, 0, 0);
|
||||
launch = new EntityFishingHook((EntityHuman) getHandle(), world, 0, 0, new net.minecraft.world.item.ItemStack(Items.FISHING_ROD));
|
||||
} else if (Fireball.class.isAssignableFrom(projectile)) {
|
||||
Location location = getEyeLocation();
|
||||
Vector direction = location.getDirection().multiply(10);
|
||||
@@ -501,9 +509,9 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
launch = new EntityDragonFireball(world, getHandle(), vec);
|
||||
} else if (AbstractWindCharge.class.isAssignableFrom(projectile)) {
|
||||
if (BreezeWindCharge.class.isAssignableFrom(projectile)) {
|
||||
launch = EntityTypes.BREEZE_WIND_CHARGE.create(world);
|
||||
launch = EntityTypes.BREEZE_WIND_CHARGE.create(world, EntitySpawnReason.TRIGGERED);
|
||||
} else {
|
||||
launch = EntityTypes.WIND_CHARGE.create(world);
|
||||
launch = EntityTypes.WIND_CHARGE.create(world, EntitySpawnReason.TRIGGERED);
|
||||
}
|
||||
|
||||
((net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge) launch).setOwner(getHandle());
|
||||
@@ -518,7 +526,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
Location location = getEyeLocation();
|
||||
Vector direction = location.getDirection();
|
||||
|
||||
launch = EntityTypes.LLAMA_SPIT.create(world);
|
||||
launch = EntityTypes.LLAMA_SPIT.create(world, EntitySpawnReason.TRIGGERED);
|
||||
|
||||
((EntityLlamaSpit) launch).setOwner(getHandle());
|
||||
((EntityLlamaSpit) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F); // EntityLlama
|
||||
@@ -704,7 +712,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
if (getHandle() instanceof EntityHuman) {
|
||||
((EntityHuman) getHandle()).attack(((CraftEntity) target).getHandle());
|
||||
} else {
|
||||
getHandle().doHurtTarget(((CraftEntity) target).getHandle());
|
||||
getHandle().doHurtTarget((WorldServer) ((CraftEntity) target).getHandle().level(), ((CraftEntity) target).getHandle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,14 +798,26 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
|
||||
@Override
|
||||
public Sound getDrinkingSound(ItemStack itemStack) {
|
||||
Preconditions.checkArgument(itemStack != null, "itemStack must not be null");
|
||||
return CraftSound.minecraftToBukkit(getHandle().getDrinkingSound0(CraftItemStack.asNMSCopy(itemStack)));
|
||||
return getEatingSound(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getEatingSound(ItemStack itemStack) {
|
||||
Preconditions.checkArgument(itemStack != null, "itemStack must not be null");
|
||||
return CraftSound.minecraftToBukkit(getHandle().getEatingSound0(CraftItemStack.asNMSCopy(itemStack)));
|
||||
|
||||
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(itemStack);
|
||||
Consumable consumable = nms.get(DataComponents.CONSUMABLE);
|
||||
SoundEffect soundeffect = SoundEffects.GENERIC_DRINK.value();
|
||||
|
||||
if (consumable != null) {
|
||||
if (getHandle() instanceof Consumable.b consumable_b) {
|
||||
soundeffect = consumable_b.getConsumeSound(nms);
|
||||
} else {
|
||||
soundeffect = (SoundEffect) consumable.sound().value();
|
||||
}
|
||||
}
|
||||
|
||||
return CraftSound.minecraftToBukkit(soundeffect);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,26 @@ public final class CraftMinecartTNT extends CraftMinecart implements ExplosiveMi
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYield() {
|
||||
return getHandle().explosionPowerBase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncendiary() {
|
||||
return getHandle().isIncendiary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsIncendiary(boolean isIncendiary) {
|
||||
getHandle().isIncendiary = isIncendiary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setYield(float yield) {
|
||||
getHandle().explosionPowerBase = yield;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuseTicks(int ticks) {
|
||||
getHandle().fuse = ticks;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.sounds.SoundEffect;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import org.bukkit.Sound;
|
||||
@@ -63,12 +64,12 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
|
||||
|
||||
@Override
|
||||
public void setLootTable(LootTable table) {
|
||||
getHandle().lootTable = CraftLootTable.bukkitToMinecraft(table);
|
||||
getHandle().lootTable = Optional.ofNullable(CraftLootTable.bukkitToMinecraft(table));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LootTable getLootTable() {
|
||||
return CraftLootTable.minecraftToBukkit(getHandle().getLootTable());
|
||||
return CraftLootTable.minecraftToBukkit(getHandle().getLootTable().orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -160,6 +160,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.conversations.ConversationTracker;
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
import org.bukkit.craftbukkit.map.CraftMapCursor;
|
||||
import org.bukkit.craftbukkit.map.CraftMapView;
|
||||
import org.bukkit.craftbukkit.map.RenderData;
|
||||
@@ -418,6 +419,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerListOrder() {
|
||||
return getHandle().listOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerListOrder(int order) {
|
||||
Preconditions.checkArgument(order >= 0, "order cannot be negative");
|
||||
|
||||
getHandle().listOrder = order;
|
||||
}
|
||||
|
||||
private IChatBaseComponent playerListHeader;
|
||||
private IChatBaseComponent playerListFooter;
|
||||
|
||||
@@ -961,7 +974,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
}
|
||||
|
||||
PacketPlayOutMap packet = new PacketPlayOutMap(new MapId(map.getId()), map.getScale().getValue(), map.isLocked(), icons, new WorldMap.b(0, 0, 128, 128, data.buffer));
|
||||
PacketPlayOutMap packet = new PacketPlayOutMap(new MapId(map.getId()), map.getScale().getValue(), map.isLocked(), icons, new WorldMap.c(0, 0, 128, 128, data.buffer));
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -1184,13 +1197,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
@Override
|
||||
public boolean hasDiscoveredRecipe(NamespacedKey recipe) {
|
||||
Preconditions.checkArgument(recipe != null, "recipe cannot be null");
|
||||
return getHandle().getRecipeBook().contains(CraftNamespacedKey.toMinecraft(recipe));
|
||||
return getHandle().getRecipeBook().contains(CraftRecipe.toMinecraft(recipe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NamespacedKey> getDiscoveredRecipes() {
|
||||
ImmutableSet.Builder<NamespacedKey> bukkitRecipeKeys = ImmutableSet.builder();
|
||||
getHandle().getRecipeBook().known.forEach(key -> bukkitRecipeKeys.add(CraftNamespacedKey.fromMinecraft(key)));
|
||||
getHandle().getRecipeBook().known.forEach(key -> bukkitRecipeKeys.add(CraftNamespacedKey.fromMinecraft(key.location())));
|
||||
return bukkitRecipeKeys.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.entity.animal.EntitySalmon;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Salmon;
|
||||
@@ -19,4 +20,16 @@ public class CraftSalmon extends CraftFish implements Salmon {
|
||||
public String toString() {
|
||||
return "CraftSalmon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Variant getVariant() {
|
||||
return Variant.values()[getHandle().getVariant().ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVariant(Variant variant) {
|
||||
Preconditions.checkArgument(variant != null, "variant");
|
||||
|
||||
getHandle().setVariant(EntitySalmon.a.values()[variant.ordinal()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.minecraft.world.entity.animal.EntitySquid;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Squid;
|
||||
|
||||
public class CraftSquid extends CraftWaterMob implements Squid {
|
||||
public class CraftSquid extends CraftAgeable implements Squid {
|
||||
|
||||
public CraftSquid(CraftServer server, EntitySquid entity) {
|
||||
super(server, entity);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CraftTNTPrimed extends CraftEntity implements TNTPrimed {
|
||||
|
||||
@Override
|
||||
public float getYield() {
|
||||
return getHandle().yield;
|
||||
return getHandle().explosionPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,7 +30,7 @@ public class CraftTNTPrimed extends CraftEntity implements TNTPrimed {
|
||||
|
||||
@Override
|
||||
public void setYield(float yield) {
|
||||
getHandle().yield = yield;
|
||||
getHandle().explosionPower = yield;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.ZombieVillager;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityTransformEvent;
|
||||
|
||||
public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
|
||||
@@ -123,7 +124,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
|
||||
@Override
|
||||
public ZombieVillager zombify() {
|
||||
EntityZombieVillager entityzombievillager = EntityZombie.zombifyVillager(getHandle().level().getMinecraftWorld(), getHandle(), getHandle().blockPosition(), isSilent(), CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
EntityZombieVillager entityzombievillager = EntityZombie.convertVillagerToZombieVillager(getHandle().level().getMinecraftWorld(), getHandle(), getHandle().blockPosition(), isSilent(), EntityTransformEvent.TransformReason.INFECTION, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
return (entityzombievillager != null) ? (ZombieVillager) entityzombievillager.getBukkitEntity() : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
|
||||
|
||||
@Override
|
||||
public boolean isWet() {
|
||||
return getHandle().isWet();
|
||||
return getHandle().isWet;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.AcaciaBoat;
|
||||
|
||||
public class CraftAcaciaBoat extends CraftBoat implements AcaciaBoat {
|
||||
|
||||
public CraftAcaciaBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.AcaciaChestBoat;
|
||||
|
||||
public class CraftAcaciaChestBoat extends CraftChestBoat implements AcaciaChestBoat {
|
||||
|
||||
public CraftAcaciaChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.BambooChestRaft;
|
||||
|
||||
public class CraftBambooChestRaft extends CraftChestBoat implements BambooChestRaft {
|
||||
|
||||
public CraftBambooChestRaft(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.BambooRaft;
|
||||
|
||||
public class CraftBambooRaft extends CraftBoat implements BambooRaft {
|
||||
|
||||
public CraftBambooRaft(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.BirchBoat;
|
||||
|
||||
public class CraftBirchBoat extends CraftBoat implements BirchBoat {
|
||||
|
||||
public CraftBirchBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.BirchChestBoat;
|
||||
|
||||
public class CraftBirchChestBoat extends CraftChestBoat implements BirchChestBoat {
|
||||
|
||||
public CraftBirchChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.CherryBoat;
|
||||
|
||||
public class CraftCherryBoat extends CraftBoat implements CherryBoat {
|
||||
|
||||
public CraftCherryBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.CherryChestBoat;
|
||||
|
||||
public class CraftCherryChestBoat extends CraftChestBoat implements CherryChestBoat {
|
||||
|
||||
public CraftCherryChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.DarkOakBoat;
|
||||
|
||||
public class CraftDarkOakBoat extends CraftBoat implements DarkOakBoat {
|
||||
|
||||
public CraftDarkOakBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.DarkOakChestBoat;
|
||||
|
||||
public class CraftDarkOakChestBoat extends CraftChestBoat implements DarkOakChestBoat {
|
||||
|
||||
public CraftDarkOakChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.JungleBoat;
|
||||
|
||||
public class CraftJungleBoat extends CraftBoat implements JungleBoat {
|
||||
|
||||
public CraftJungleBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.JungleChestBoat;
|
||||
|
||||
public class CraftJungleChestBoat extends CraftChestBoat implements JungleChestBoat {
|
||||
|
||||
public CraftJungleChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.MangroveBoat;
|
||||
|
||||
public class CraftMangroveBoat extends CraftBoat implements MangroveBoat {
|
||||
|
||||
public CraftMangroveBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.MangroveChestBoat;
|
||||
|
||||
public class CraftMangroveChestBoat extends CraftChestBoat implements MangroveChestBoat {
|
||||
|
||||
public CraftMangroveChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.OakBoat;
|
||||
|
||||
public class CraftOakBoat extends CraftBoat implements OakBoat {
|
||||
|
||||
public CraftOakBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.OakChestBoat;
|
||||
|
||||
public class CraftOakChestBoat extends CraftChestBoat implements OakChestBoat {
|
||||
|
||||
public CraftOakChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.PaleOakBoat;
|
||||
|
||||
public class CraftPaleOakBoat extends CraftBoat implements PaleOakBoat {
|
||||
|
||||
public CraftPaleOakBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.PaleOakChestBoat;
|
||||
|
||||
public class CraftPaleOakChestBoat extends CraftChestBoat implements PaleOakChestBoat {
|
||||
|
||||
public CraftPaleOakChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||
import org.bukkit.entity.boat.SpruceBoat;
|
||||
|
||||
public class CraftSpruceBoat extends CraftBoat implements SpruceBoat {
|
||||
|
||||
public CraftSpruceBoat(CraftServer server, AbstractBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity.boat;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractChestBoat;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftChestBoat;
|
||||
import org.bukkit.entity.boat.SpruceChestBoat;
|
||||
|
||||
public class CraftSpruceChestBoat extends CraftChestBoat implements SpruceChestBoat {
|
||||
|
||||
public CraftSpruceChestBoat(CraftServer server, AbstractChestBoat entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,6 @@ import net.minecraft.world.entity.monster.EntitySlime;
|
||||
import net.minecraft.world.entity.monster.EntityStrider;
|
||||
import net.minecraft.world.entity.monster.piglin.EntityPiglin;
|
||||
import net.minecraft.world.entity.npc.EntityVillager;
|
||||
import net.minecraft.world.entity.npc.NPC;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
import net.minecraft.world.entity.projectile.EntityFireworks;
|
||||
import net.minecraft.world.entity.projectile.EntityPotion;
|
||||
@@ -668,10 +667,9 @@ public class CraftEventFactory {
|
||||
if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) {
|
||||
boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem;
|
||||
boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime;
|
||||
boolean isNpc = entity instanceof NPC;
|
||||
|
||||
if (spawnReason != SpawnReason.CUSTOM) {
|
||||
if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters() || isNpc && !world.getCraftServer().getServer().areNpcsEnabled()) {
|
||||
if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters()) {
|
||||
entity.discard(null); // Add Bukkit remove cause
|
||||
return false;
|
||||
}
|
||||
@@ -899,8 +897,8 @@ public class CraftEventFactory {
|
||||
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops) {
|
||||
CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
|
||||
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
|
||||
EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()));
|
||||
CraftWorld world = (CraftWorld) entity.getWorld();
|
||||
EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(world.getHandle(), damageSource.getEntity()));
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
victim.expToDrop = event.getDroppedExp();
|
||||
@@ -917,7 +915,7 @@ public class CraftEventFactory {
|
||||
public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
|
||||
CraftPlayer entity = victim.getBukkitEntity();
|
||||
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
|
||||
PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()), 0, deathMessage);
|
||||
PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage);
|
||||
event.setKeepInventory(keepInventory);
|
||||
event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
@@ -935,7 +933,7 @@ public class CraftEventFactory {
|
||||
victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for Player Inventory dropped items
|
||||
} else {
|
||||
victim.forceDrops = true;
|
||||
victim.spawnAtLocation(CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items
|
||||
victim.spawnAtLocation(victim.serverLevel(), CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items
|
||||
victim.forceDrops = false;
|
||||
}
|
||||
}
|
||||
@@ -1427,7 +1425,7 @@ public class CraftEventFactory {
|
||||
}
|
||||
|
||||
public static BlockIgniteEvent callBlockIgniteEvent(World world, BlockPosition blockposition, Explosion explosion) {
|
||||
org.bukkit.entity.Entity igniter = explosion.source == null ? null : explosion.source.getBukkitEntity();
|
||||
org.bukkit.entity.Entity igniter = explosion.getDirectSourceEntity() == null ? null : explosion.getDirectSourceEntity().getBukkitEntity();
|
||||
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(CraftBlock.at(world, blockposition), IgniteCause.EXPLOSION, igniter);
|
||||
world.getCraftServer().getPluginManager().callEvent(event);
|
||||
@@ -1780,7 +1778,7 @@ public class CraftEventFactory {
|
||||
|
||||
public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootTableInfo lootInfo, List<ItemStack> loot, boolean plugin) {
|
||||
CraftWorld world = lootInfo.getLevel().getWorld();
|
||||
Entity entity = lootInfo.getParamOrNull(LootContextParameters.THIS_ENTITY);
|
||||
Entity entity = lootInfo.getOptionalParameter(LootContextParameters.THIS_ENTITY);
|
||||
List<org.bukkit.inventory.ItemStack> bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), inventory.getOwner(), lootTable.craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin);
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.function.Consumer;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.GeneratorAccessSeed;
|
||||
@@ -84,7 +85,7 @@ public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRe
|
||||
for (int z = -(buffer >> 4); z <= (buffer >> 4); z++) {
|
||||
ProtoChunk chunk = (ProtoChunk) access.getChunk(centerChunkX + x, centerChunkZ + z);
|
||||
for (NBTTagCompound compound : chunk.getEntities()) {
|
||||
EntityTypes.loadEntityRecursive(compound, access.getMinecraftWorld(), (entity) -> {
|
||||
EntityTypes.loadEntityRecursive(compound, access.getMinecraftWorld(), EntitySpawnReason.LOAD, (entity) -> {
|
||||
if (region.contains(entity.getX(), entity.getY(), entity.getZ())) {
|
||||
entity.generation = true;
|
||||
entities.add(entity);
|
||||
|
||||
@@ -31,7 +31,6 @@ import net.minecraft.world.level.levelgen.HeightMap;
|
||||
import net.minecraft.world.level.levelgen.LegacyRandomSource;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.SeededRandom;
|
||||
import net.minecraft.world.level.levelgen.WorldGenStage;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
||||
import org.bukkit.block.Biome;
|
||||
@@ -224,14 +223,14 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, RandomState randomstate, BiomeManager biomemanager, StructureManager structuremanager, IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) {
|
||||
public void applyCarvers(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, RandomState randomstate, BiomeManager biomemanager, StructureManager structuremanager, IChunkAccess ichunkaccess) {
|
||||
SeededRandom random = getSeededRandom();
|
||||
int x = ichunkaccess.getPos().x;
|
||||
int z = ichunkaccess.getPos().z;
|
||||
|
||||
random.setSeed(MathHelper.getSeed(x, "should-caves".hashCode(), z) ^ regionlimitedworldaccess.getSeed());
|
||||
if (generator.shouldGenerateCaves(this.world.getWorld(), new RandomSourceWrapper.RandomWrapper(random), x, z)) {
|
||||
delegate.applyCarvers(regionlimitedworldaccess, seed, randomstate, biomemanager, structuremanager, ichunkaccess, worldgenstage_features);
|
||||
delegate.applyCarvers(regionlimitedworldaccess, seed, randomstate, biomemanager, structuremanager, ichunkaccess);
|
||||
}
|
||||
|
||||
// Minecraft removed the LIQUID_CARVERS stage from world generation, without removing the LIQUID Carving enum.
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.BlastingRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
@@ -27,6 +26,6 @@ public class CraftBlastingRecipe extends BlastingRecipe implements CraftRecipe {
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeBlasting(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeBlasting(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.CampfireRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
@@ -27,6 +26,6 @@ public class CraftCampfireRecipe extends CampfireRecipe implements CraftRecipe {
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeCampfire(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeCampfire(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.IRecipeComplex;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ComplexRecipe;
|
||||
import org.bukkit.inventory.CraftingRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -20,6 +19,6 @@ public class CraftComplexRecipe extends CraftingRecipe implements CraftRecipe, C
|
||||
|
||||
@Override
|
||||
public void addToCraftingManager() {
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), recipe));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), recipe));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
@@ -27,6 +26,6 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.FurnaceRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.FurnaceRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,11 @@ import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftEquippableComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftFoodComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftJukeboxComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftToolComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftUseCooldownComponent;
|
||||
import org.bukkit.craftbukkit.util.CraftLegacy;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -43,11 +45,12 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
static {
|
||||
instance = new CraftItemFactory();
|
||||
ConfigurationSerialization.registerClass(SerializableMeta.class);
|
||||
ConfigurationSerialization.registerClass(CraftEquippableComponent.class);
|
||||
ConfigurationSerialization.registerClass(CraftFoodComponent.class);
|
||||
ConfigurationSerialization.registerClass(CraftFoodComponent.CraftFoodEffect.class);
|
||||
ConfigurationSerialization.registerClass(CraftToolComponent.class);
|
||||
ConfigurationSerialization.registerClass(CraftToolComponent.CraftToolRule.class);
|
||||
ConfigurationSerialization.registerClass(CraftJukeboxComponent.class);
|
||||
ConfigurationSerialization.registerClass(CraftUseCooldownComponent.class);
|
||||
}
|
||||
|
||||
private CraftItemFactory() {
|
||||
@@ -204,7 +207,7 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
itemStack = CraftItemStack.asCraftCopy(itemStack);
|
||||
CraftItemStack craft = (CraftItemStack) itemStack;
|
||||
IRegistryCustom registry = CraftRegistry.getMinecraftRegistry();
|
||||
Optional<HolderSet.Named<Enchantment>> optional = (allowTreasures) ? Optional.empty() : registry.registryOrThrow(Registries.ENCHANTMENT).getTag(EnchantmentTags.IN_ENCHANTING_TABLE);
|
||||
Optional<HolderSet.Named<Enchantment>> optional = (allowTreasures) ? Optional.empty() : registry.lookupOrThrow(Registries.ENCHANTMENT).get(EnchantmentTags.IN_ENCHANTING_TABLE);
|
||||
return CraftItemStack.asCraftMirror(EnchantmentManager.enchantItem(source, craft.handle, level, registry, optional));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.world.item.BundleItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemBanner;
|
||||
import net.minecraft.world.item.ItemBlock;
|
||||
@@ -244,7 +245,8 @@ public final class CraftItemMetas {
|
||||
|| itemType == ItemType.CALIBRATED_SCULK_SENSOR || itemType == ItemType.CHISELED_BOOKSHELF
|
||||
|| itemType == ItemType.DECORATED_POT || itemType == ItemType.SUSPICIOUS_SAND
|
||||
|| itemType == ItemType.SUSPICIOUS_GRAVEL || itemType == ItemType.CRAFTER
|
||||
|| itemType == ItemType.TRIAL_SPAWNER || itemType == ItemType.VAULT) {
|
||||
|| itemType == ItemType.TRIAL_SPAWNER || itemType == ItemType.VAULT
|
||||
|| itemType == ItemType.CREAKING_HEART) {
|
||||
return asType(BLOCK_STATE_META_DATA);
|
||||
}
|
||||
if (itemType == ItemType.SHIELD) {
|
||||
@@ -270,7 +272,7 @@ public final class CraftItemMetas {
|
||||
if (itemType == ItemType.COMPASS) {
|
||||
return asType(COMPASS_META_DATA);
|
||||
}
|
||||
if (itemType == ItemType.BUNDLE) {
|
||||
if (itemHandle instanceof BundleItem) {
|
||||
return asType(BUNDLE_META_DATA);
|
||||
}
|
||||
if (itemType == ItemType.GOAT_HORN) {
|
||||
|
||||
@@ -2,10 +2,18 @@ package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.advancements.critereon.CriterionConditionItem;
|
||||
import net.minecraft.advancements.critereon.CriterionConditionValue;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponentPatch;
|
||||
import net.minecraft.core.component.DataComponentPredicate;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.component.PatchedDataComponentMap;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentManager;
|
||||
import net.minecraft.world.item.enchantment.ItemEnchantments;
|
||||
@@ -85,6 +93,13 @@ public final class CraftItemStack extends ItemStack {
|
||||
return new CraftItemStack(CraftItemType.minecraftToBukkit(item), amount, (short) 0, null);
|
||||
}
|
||||
|
||||
public static CriterionConditionItem asCriterionConditionItem(ItemStack original) {
|
||||
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(original);
|
||||
DataComponentPredicate predicate = DataComponentPredicate.allOf(PatchedDataComponentMap.fromPatch(DataComponentMap.EMPTY, nms.getComponentsPatch()));
|
||||
|
||||
return new CriterionConditionItem(Optional.of(HolderSet.direct(nms.getItemHolder())), CriterionConditionValue.IntegerRange.ANY, predicate, Collections.emptyMap());
|
||||
}
|
||||
|
||||
net.minecraft.world.item.ItemStack handle;
|
||||
private boolean isForInventoryDrop;
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemBlock;
|
||||
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||
import net.minecraft.world.level.block.BlockComposter;
|
||||
import net.minecraft.world.level.block.entity.TileEntityFurnace;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
@@ -172,7 +172,7 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
|
||||
|
||||
@Override
|
||||
public boolean isFuel() {
|
||||
return TileEntityFurnace.isFuel(new net.minecraft.world.item.ItemStack(item));
|
||||
return MinecraftServer.getServer().fuelValues().isFuel(new net.minecraft.world.item.ItemStack(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,8 +188,8 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
|
||||
|
||||
@Override
|
||||
public ItemType getCraftingRemainingItem() {
|
||||
Item expectedItem = item.getCraftingRemainingItem();
|
||||
return expectedItem == null ? null : minecraftToBukkitNew(expectedItem);
|
||||
net.minecraft.world.item.ItemStack expectedItem = item.getCraftingRemainder();
|
||||
return expectedItem.isEmpty() ? null : minecraftToBukkitNew(expectedItem.getItem());
|
||||
}
|
||||
|
||||
// @Override
|
||||
@@ -202,9 +202,6 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
|
||||
ImmutableMultimap.Builder<Attribute, AttributeModifier> defaultAttributes = ImmutableMultimap.builder();
|
||||
|
||||
ItemAttributeModifiers nmsDefaultAttributes = item.components().getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
||||
if (nmsDefaultAttributes.modifiers().isEmpty()) {
|
||||
nmsDefaultAttributes = item.getDefaultAttributeModifiers();
|
||||
}
|
||||
|
||||
nmsDefaultAttributes.forEach(CraftEquipmentSlot.getNMS(slot), (key, value) -> {
|
||||
Attribute attribute = CraftAttribute.minecraftToBukkit(key.value());
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
@DelegateDeserialization(SerializableMeta.class)
|
||||
public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta {
|
||||
|
||||
static final ItemMetaKeyType<net.minecraft.world.item.armortrim.ArmorTrim> TRIM = new ItemMetaKeyType<>(DataComponents.TRIM, "trim");
|
||||
static final ItemMetaKeyType<net.minecraft.world.item.equipment.trim.ArmorTrim> TRIM = new ItemMetaKeyType<>(DataComponents.TRIM, "trim");
|
||||
static final ItemMetaKey TRIM_MATERIAL = new ItemMetaKey("material");
|
||||
static final ItemMetaKey TRIM_PATTERN = new ItemMetaKey("pattern");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta {
|
||||
|
||||
this.trim = new ArmorTrim(trimMaterial, trimPattern);
|
||||
|
||||
if (!trimCompound.showInTooltip) {
|
||||
if (!trimCompound.showInTooltip()) {
|
||||
addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
|
||||
}
|
||||
});
|
||||
@@ -78,7 +78,7 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta {
|
||||
super.applyToItem(itemTag);
|
||||
|
||||
if (hasTrim()) {
|
||||
itemTag.put(TRIM, new net.minecraft.world.item.armortrim.ArmorTrim(CraftTrimMaterial.bukkitToMinecraftHolder(trim.getMaterial()), CraftTrimPattern.bukkitToMinecraftHolder(trim.getPattern()), !hasItemFlag(ItemFlag.HIDE_ARMOR_TRIM)));
|
||||
itemTag.put(TRIM, new net.minecraft.world.item.equipment.trim.ArmorTrim(CraftTrimMaterial.bukkitToMinecraftHolder(trim.getMaterial()), CraftTrimPattern.bukkitToMinecraftHolder(trim.getPattern()), !hasItemFlag(ItemFlag.HIDE_ARMOR_TRIM)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ import net.minecraft.nbt.SnbtPrinterTagVisitor;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.world.entity.EnumItemSlot;
|
||||
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||
@@ -69,13 +70,21 @@ import net.minecraft.world.item.JukeboxSongs;
|
||||
import net.minecraft.world.item.component.BlockItemStateProperties;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.item.component.CustomModelData;
|
||||
import net.minecraft.world.item.component.DamageResistant;
|
||||
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||
import net.minecraft.world.item.component.ItemLore;
|
||||
import net.minecraft.world.item.component.Tool;
|
||||
import net.minecraft.world.item.component.Unbreakable;
|
||||
import net.minecraft.world.item.component.UseCooldown;
|
||||
import net.minecraft.world.item.component.UseRemainder;
|
||||
import net.minecraft.world.item.enchantment.Enchantable;
|
||||
import net.minecraft.world.item.enchantment.ItemEnchantments;
|
||||
import net.minecraft.world.item.equipment.Equippable;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -89,28 +98,37 @@ import org.bukkit.craftbukkit.block.CraftBlockType;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.enchantments.CraftEnchantment;
|
||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftEquippableComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftFoodComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftJukeboxComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftToolComponent;
|
||||
import org.bukkit.craftbukkit.inventory.components.CraftUseCooldownComponent;
|
||||
import org.bukkit.craftbukkit.inventory.tags.DeprecatedCustomTagContainer;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
|
||||
import org.bukkit.craftbukkit.tag.CraftDamageTag;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNBTTagConfigSerializer;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemRarity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.Repairable;
|
||||
import org.bukkit.inventory.meta.components.EquippableComponent;
|
||||
import org.bukkit.inventory.meta.components.FoodComponent;
|
||||
import org.bukkit.inventory.meta.components.JukeboxPlayableComponent;
|
||||
import org.bukkit.inventory.meta.components.ToolComponent;
|
||||
import org.bukkit.inventory.meta.components.UseCooldownComponent;
|
||||
import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.tag.DamageTypeTags;
|
||||
|
||||
/**
|
||||
* Children must include the following:
|
||||
@@ -207,6 +225,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
static final ItemMetaKeyType<IChatBaseComponent> ITEM_NAME = new ItemMetaKeyType(DataComponents.ITEM_NAME, "item-name");
|
||||
static final ItemMetaKeyType<ItemLore> LORE = new ItemMetaKeyType<>(DataComponents.LORE, "lore");
|
||||
static final ItemMetaKeyType<CustomModelData> CUSTOM_MODEL_DATA = new ItemMetaKeyType<>(DataComponents.CUSTOM_MODEL_DATA, "custom-model-data");
|
||||
static final ItemMetaKeyType<Enchantable> ENCHANTABLE = new ItemMetaKeyType<>(DataComponents.ENCHANTABLE, "enchantable");
|
||||
static final ItemMetaKeyType<ItemEnchantments> ENCHANTMENTS = new ItemMetaKeyType<>(DataComponents.ENCHANTMENTS, "enchants");
|
||||
static final ItemMetaKeyType<Integer> REPAIR = new ItemMetaKeyType<>(DataComponents.REPAIR_COST, "repair-cost");
|
||||
static final ItemMetaKeyType<ItemAttributeModifiers> ATTRIBUTES = new ItemMetaKeyType<>(DataComponents.ATTRIBUTE_MODIFIERS, "attribute-modifiers");
|
||||
@@ -219,20 +238,32 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Unit> HIDE_TOOLTIP = new ItemMetaKeyType<>(DataComponents.HIDE_TOOLTIP, "hide-tool-tip");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<MinecraftKey> TOOLTIP_STYLE = new ItemMetaKeyType<>(DataComponents.TOOLTIP_STYLE, "tool-tip-style");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<MinecraftKey> ITEM_MODEL = new ItemMetaKeyType<>(DataComponents.ITEM_MODEL, "item-model");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Unbreakable> UNBREAKABLE = new ItemMetaKeyType<>(DataComponents.UNBREAKABLE, "Unbreakable");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Boolean> ENCHANTMENT_GLINT_OVERRIDE = new ItemMetaKeyType<>(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, "enchantment-glint-override");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Unit> FIRE_RESISTANT = new ItemMetaKeyType<>(DataComponents.FIRE_RESISTANT, "fire-resistant");
|
||||
static final ItemMetaKeyType<Unit> GLIDER = new ItemMetaKeyType<>(DataComponents.GLIDER, "glider");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<DamageResistant> DAMAGE_RESISTANT = new ItemMetaKeyType<>(DataComponents.DAMAGE_RESISTANT, "damage-resistant");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Integer> MAX_STACK_SIZE = new ItemMetaKeyType<>(DataComponents.MAX_STACK_SIZE, "max-stack-size");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<EnumItemRarity> RARITY = new ItemMetaKeyType<>(DataComponents.RARITY, "rarity");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<UseRemainder> USE_REMAINDER = new ItemMetaKeyType<>(DataComponents.USE_REMAINDER, "use-remainder");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<UseCooldown> USE_COOLDOWN = new ItemMetaKeyType<>(DataComponents.USE_COOLDOWN, "use-cooldown");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<FoodInfo> FOOD = new ItemMetaKeyType<>(DataComponents.FOOD, "food");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Tool> TOOL = new ItemMetaKeyType<>(DataComponents.TOOL, "tool");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Equippable> EQUIPPABLE = new ItemMetaKeyType<>(DataComponents.EQUIPPABLE, "equippable");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<JukeboxPlayable> JUKEBOX_PLAYABLE = new ItemMetaKeyType<>(DataComponents.JUKEBOX_PLAYABLE, "jukebox-playable");
|
||||
@Specific(Specific.To.NBT)
|
||||
static final ItemMetaKeyType<Integer> DAMAGE = new ItemMetaKeyType<>(DataComponents.DAMAGE, "Damage");
|
||||
@@ -251,19 +282,26 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
private IChatBaseComponent itemName;
|
||||
private List<IChatBaseComponent> lore; // null and empty are two different states internally
|
||||
private Integer customModelData;
|
||||
private Integer enchantableValue;
|
||||
private Map<String, String> blockData;
|
||||
private Map<Enchantment, Integer> enchantments;
|
||||
private Multimap<Attribute, AttributeModifier> attributeModifiers;
|
||||
private int repairCost;
|
||||
private int hideFlag;
|
||||
private boolean hideTooltip;
|
||||
private NamespacedKey tooltipStyle;
|
||||
private NamespacedKey itemModel;
|
||||
private boolean unbreakable;
|
||||
private Boolean enchantmentGlintOverride;
|
||||
private boolean fireResistant;
|
||||
private boolean glider;
|
||||
private TagKey<net.minecraft.world.damagesource.DamageType> damageResistant;
|
||||
private Integer maxStackSize;
|
||||
private ItemRarity rarity;
|
||||
private ItemStack useRemainder;
|
||||
private CraftUseCooldownComponent useCooldown;
|
||||
private CraftFoodComponent food;
|
||||
private CraftToolComponent tool;
|
||||
private CraftEquippableComponent equippable;
|
||||
private CraftJukeboxComponent jukebox;
|
||||
private int damage;
|
||||
private Integer maxDamage;
|
||||
@@ -291,6 +329,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
}
|
||||
|
||||
this.customModelData = meta.customModelData;
|
||||
this.enchantableValue = meta.enchantableValue;
|
||||
this.blockData = meta.blockData;
|
||||
|
||||
if (meta.enchantments != null) {
|
||||
@@ -304,17 +343,29 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.repairCost = meta.repairCost;
|
||||
this.hideFlag = meta.hideFlag;
|
||||
this.hideTooltip = meta.hideTooltip;
|
||||
this.tooltipStyle = meta.tooltipStyle;
|
||||
this.itemModel = meta.itemModel;
|
||||
this.unbreakable = meta.unbreakable;
|
||||
this.enchantmentGlintOverride = meta.enchantmentGlintOverride;
|
||||
this.fireResistant = meta.fireResistant;
|
||||
this.glider = meta.glider;
|
||||
this.damageResistant = meta.damageResistant;
|
||||
this.maxStackSize = meta.maxStackSize;
|
||||
this.rarity = meta.rarity;
|
||||
if (meta.hasUseRemainder()) {
|
||||
this.useRemainder = meta.useRemainder.clone();
|
||||
}
|
||||
if (meta.hasUseCooldown()) {
|
||||
this.useCooldown = new CraftUseCooldownComponent(meta.useCooldown);
|
||||
}
|
||||
if (meta.hasFood()) {
|
||||
this.food = new CraftFoodComponent(meta.food);
|
||||
}
|
||||
if (meta.hasTool()) {
|
||||
this.tool = new CraftToolComponent(meta.tool);
|
||||
}
|
||||
if (meta.hasEquippable()) {
|
||||
this.equippable = new CraftEquippableComponent(meta.equippable);
|
||||
}
|
||||
if (meta.hasJukeboxPlayable()) {
|
||||
this.jukebox = new CraftJukeboxComponent(meta.jukebox);
|
||||
}
|
||||
@@ -349,6 +400,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
getOrEmpty(tag, CUSTOM_MODEL_DATA).ifPresent((i) -> {
|
||||
customModelData = i.value();
|
||||
});
|
||||
getOrEmpty(tag, ENCHANTABLE).ifPresent((i) -> {
|
||||
enchantableValue = i.value();
|
||||
});
|
||||
getOrEmpty(tag, BLOCK_DATA).ifPresent((t) -> {
|
||||
blockData = t.properties();
|
||||
});
|
||||
@@ -376,6 +430,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
getOrEmpty(tag, HIDE_TOOLTIP).ifPresent((u) -> {
|
||||
hideTooltip = true;
|
||||
});
|
||||
getOrEmpty(tag, TOOLTIP_STYLE).ifPresent((key) -> {
|
||||
tooltipStyle = CraftNamespacedKey.fromMinecraft(key);
|
||||
});
|
||||
getOrEmpty(tag, ITEM_MODEL).ifPresent((key) -> {
|
||||
itemModel = CraftNamespacedKey.fromMinecraft(key);
|
||||
});
|
||||
getOrEmpty(tag, UNBREAKABLE).ifPresent((u) -> {
|
||||
unbreakable = true;
|
||||
if (!u.showInTooltip()) {
|
||||
@@ -385,8 +445,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
getOrEmpty(tag, ENCHANTMENT_GLINT_OVERRIDE).ifPresent((override) -> {
|
||||
enchantmentGlintOverride = override;
|
||||
});
|
||||
getOrEmpty(tag, FIRE_RESISTANT).ifPresent((u) -> {
|
||||
fireResistant = true;
|
||||
getOrEmpty(tag, GLIDER).ifPresent((u) -> {
|
||||
glider = true;
|
||||
});
|
||||
getOrEmpty(tag, DAMAGE_RESISTANT).ifPresent((tags) -> {
|
||||
damageResistant = tags.types();
|
||||
});
|
||||
getOrEmpty(tag, MAX_STACK_SIZE).ifPresent((i) -> {
|
||||
maxStackSize = i;
|
||||
@@ -394,12 +457,21 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
getOrEmpty(tag, RARITY).ifPresent((enumItemRarity) -> {
|
||||
rarity = ItemRarity.valueOf(enumItemRarity.name());
|
||||
});
|
||||
getOrEmpty(tag, USE_REMAINDER).ifPresent((remainder) -> {
|
||||
useRemainder = CraftItemStack.asCraftMirror(remainder.convertInto());
|
||||
});
|
||||
getOrEmpty(tag, USE_COOLDOWN).ifPresent((cooldown) -> {
|
||||
useCooldown = new CraftUseCooldownComponent(cooldown);
|
||||
});
|
||||
getOrEmpty(tag, FOOD).ifPresent((foodInfo) -> {
|
||||
food = new CraftFoodComponent(foodInfo);
|
||||
});
|
||||
getOrEmpty(tag, TOOL).ifPresent((toolInfo) -> {
|
||||
tool = new CraftToolComponent(toolInfo);
|
||||
});
|
||||
getOrEmpty(tag, EQUIPPABLE).ifPresent((equippableInfo) -> {
|
||||
equippable = new CraftEquippableComponent(equippableInfo);
|
||||
});
|
||||
getOrEmpty(tag, JUKEBOX_PLAYABLE).ifPresent((jukeboxPlayable) -> {
|
||||
jukebox = new CraftJukeboxComponent(jukeboxPlayable);
|
||||
});
|
||||
@@ -514,6 +586,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
if (customModelData != null) {
|
||||
setCustomModelData(customModelData);
|
||||
}
|
||||
Integer enchantmentValue = SerializableMeta.getObject(Integer.class, map, ENCHANTABLE.BUKKIT, true);
|
||||
if (enchantmentValue != null) {
|
||||
setEnchantable(enchantmentValue);
|
||||
}
|
||||
|
||||
Object blockData = SerializableMeta.getObject(Object.class, map, BLOCK_DATA.BUKKIT, true);
|
||||
if (blockData != null) {
|
||||
@@ -560,6 +636,16 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
setHideTooltip(hideTooltip);
|
||||
}
|
||||
|
||||
String tooltipStyle = SerializableMeta.getString(map, TOOLTIP_STYLE.BUKKIT, true);
|
||||
if (tooltipStyle != null) {
|
||||
setTooltipStyle(NamespacedKey.fromString(tooltipStyle));
|
||||
}
|
||||
|
||||
String itemModel = SerializableMeta.getString(map, ITEM_MODEL.BUKKIT, true);
|
||||
if (itemModel != null) {
|
||||
setItemModel(NamespacedKey.fromString(itemModel));
|
||||
}
|
||||
|
||||
Boolean unbreakable = SerializableMeta.getObject(Boolean.class, map, UNBREAKABLE.BUKKIT, true);
|
||||
if (unbreakable != null) {
|
||||
setUnbreakable(unbreakable);
|
||||
@@ -570,9 +656,17 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
setEnchantmentGlintOverride(enchantmentGlintOverride);
|
||||
}
|
||||
|
||||
Boolean fireResistant = SerializableMeta.getObject(Boolean.class, map, FIRE_RESISTANT.BUKKIT, true);
|
||||
if (fireResistant != null) {
|
||||
setFireResistant(fireResistant);
|
||||
Boolean glider = SerializableMeta.getObject(Boolean.class, map, GLIDER.BUKKIT, true);
|
||||
if (glider != null) {
|
||||
setGlider(glider);
|
||||
}
|
||||
|
||||
String damageResistant = SerializableMeta.getString(map, DAMAGE_RESISTANT.BUKKIT, true);
|
||||
if (damageResistant != null) {
|
||||
Tag<DamageType> tag = Bukkit.getTag(DamageTypeTags.REGISTRY_DAMAGE_TYPES, NamespacedKey.fromString(damageResistant), DamageType.class);
|
||||
if (tag != null) {
|
||||
setDamageResistant(tag);
|
||||
}
|
||||
}
|
||||
|
||||
Integer maxStackSize = SerializableMeta.getObject(Integer.class, map, MAX_STACK_SIZE.BUKKIT, true);
|
||||
@@ -585,6 +679,16 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
setRarity(ItemRarity.valueOf(rarity));
|
||||
}
|
||||
|
||||
ItemStack remainder = SerializableMeta.getObject(ItemStack.class, map, USE_REMAINDER.BUKKIT, true);
|
||||
if (remainder != null) {
|
||||
setUseRemainder(remainder);
|
||||
}
|
||||
|
||||
CraftUseCooldownComponent cooldown = SerializableMeta.getObject(CraftUseCooldownComponent.class, map, USE_COOLDOWN.BUKKIT, true);
|
||||
if (cooldown != null) {
|
||||
setUseCooldown(cooldown);
|
||||
}
|
||||
|
||||
CraftFoodComponent food = SerializableMeta.getObject(CraftFoodComponent.class, map, FOOD.BUKKIT, true);
|
||||
if (food != null) {
|
||||
setFood(food);
|
||||
@@ -595,6 +699,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
setTool(tool);
|
||||
}
|
||||
|
||||
CraftEquippableComponent equippable = SerializableMeta.getObject(CraftEquippableComponent.class, map, EQUIPPABLE.BUKKIT, true);
|
||||
if (equippable != null) {
|
||||
setEquippable(equippable);
|
||||
}
|
||||
|
||||
CraftJukeboxComponent jukeboxPlayable = SerializableMeta.getObject(CraftJukeboxComponent.class, map, JUKEBOX_PLAYABLE.BUKKIT, true);
|
||||
if (jukeboxPlayable != null) {
|
||||
setJukeboxPlayable(jukeboxPlayable);
|
||||
@@ -646,12 +755,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
Iterable<?> removed = SerializableMeta.getObject(Iterable.class, map, "removed", true);
|
||||
if (removed != null) {
|
||||
IRegistryCustom registryAccess = CraftRegistry.getMinecraftRegistry();
|
||||
IRegistry<DataComponentType<?>> componentTypeRegistry = registryAccess.registryOrThrow(Registries.DATA_COMPONENT_TYPE);
|
||||
IRegistry<DataComponentType<?>> componentTypeRegistry = registryAccess.lookupOrThrow(Registries.DATA_COMPONENT_TYPE);
|
||||
|
||||
for (Object removedObject : removed) {
|
||||
String removedString = (String) removedObject;
|
||||
|
||||
DataComponentType<?> component = componentTypeRegistry.get(MinecraftKey.parse(removedString));
|
||||
DataComponentType<?> component = componentTypeRegistry.getValue(MinecraftKey.parse(removedString));
|
||||
if (component != null) {
|
||||
this.removedTags.add(component);
|
||||
}
|
||||
@@ -809,6 +918,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
itemTag.put(CUSTOM_MODEL_DATA, new CustomModelData(customModelData));
|
||||
}
|
||||
|
||||
if (hasEnchantable()) {
|
||||
itemTag.put(ENCHANTABLE, new Enchantable(enchantableValue));
|
||||
}
|
||||
|
||||
if (hasBlockData()) {
|
||||
itemTag.put(BLOCK_DATA, new BlockItemStateProperties(blockData));
|
||||
}
|
||||
@@ -830,6 +943,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
itemTag.put(HIDE_TOOLTIP, Unit.INSTANCE);
|
||||
}
|
||||
|
||||
if (hasTooltipStyle()) {
|
||||
itemTag.put(TOOLTIP_STYLE, CraftNamespacedKey.toMinecraft(getTooltipStyle()));
|
||||
}
|
||||
|
||||
if (hasItemModel()) {
|
||||
itemTag.put(ITEM_MODEL, CraftNamespacedKey.toMinecraft(getItemModel()));
|
||||
}
|
||||
|
||||
if (isUnbreakable()) {
|
||||
itemTag.put(UNBREAKABLE, new Unbreakable(!hasItemFlag(ItemFlag.HIDE_UNBREAKABLE)));
|
||||
}
|
||||
@@ -838,8 +959,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
itemTag.put(ENCHANTMENT_GLINT_OVERRIDE, getEnchantmentGlintOverride());
|
||||
}
|
||||
|
||||
if (isFireResistant()) {
|
||||
itemTag.put(FIRE_RESISTANT, Unit.INSTANCE);
|
||||
if (isGlider()) {
|
||||
itemTag.put(GLIDER, Unit.INSTANCE);
|
||||
}
|
||||
|
||||
if (hasDamageResistant()) {
|
||||
itemTag.put(DAMAGE_RESISTANT, new DamageResistant(damageResistant));
|
||||
}
|
||||
|
||||
if (hasMaxStackSize()) {
|
||||
@@ -850,6 +975,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
itemTag.put(RARITY, EnumItemRarity.valueOf(rarity.name()));
|
||||
}
|
||||
|
||||
if (hasUseRemainder()) {
|
||||
itemTag.put(USE_REMAINDER, new UseRemainder(CraftItemStack.asNMSCopy(useRemainder)));
|
||||
}
|
||||
|
||||
if (hasUseCooldown()) {
|
||||
itemTag.put(USE_COOLDOWN, useCooldown.getHandle());
|
||||
}
|
||||
|
||||
if (hasFood()) {
|
||||
itemTag.put(FOOD, food.getHandle());
|
||||
}
|
||||
@@ -858,6 +991,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
itemTag.put(TOOL, tool.getHandle());
|
||||
}
|
||||
|
||||
if (hasEquippable()) {
|
||||
itemTag.put(EQUIPPABLE, equippable.getHandle());
|
||||
}
|
||||
|
||||
if (hasJukeboxPlayable()) {
|
||||
itemTag.put(JUKEBOX_PLAYABLE, jukebox.getHandle());
|
||||
}
|
||||
@@ -960,7 +1097,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
|
||||
@Overridden
|
||||
boolean isEmpty() {
|
||||
return !(hasDisplayName() || hasItemName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.build().isEmpty() || !removedTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isHideTooltip() || isUnbreakable() || hasEnchantmentGlintOverride() || isFireResistant() || hasMaxStackSize() || hasRarity() || hasFood() || hasTool() || hasJukeboxPlayable() || hasDamage() || hasMaxDamage() || hasAttributeModifiers() || customTag != null);
|
||||
return !(hasDisplayName() || hasItemName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasEnchantable() || hasBlockData() || hasRepairCost() || !unhandledTags.build().isEmpty() || !removedTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isHideTooltip() || hasTooltipStyle() || hasItemModel() || isUnbreakable() || hasEnchantmentGlintOverride() || isGlider() || hasDamageResistant() || hasMaxStackSize() || hasRarity() || hasUseRemainder() || hasUseCooldown() || hasFood() || hasTool() || hasJukeboxPlayable() || hasEquippable() || hasDamage() || hasMaxDamage() || hasAttributeModifiers() || customTag != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1152,6 +1289,22 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.customModelData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEnchantable() {
|
||||
return enchantableValue != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantable() {
|
||||
Preconditions.checkState(hasEnchantable(), "We don't have Enchantable! Check hasEnchantable first!");
|
||||
return enchantableValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnchantable(Integer data) {
|
||||
this.enchantableValue = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBlockData() {
|
||||
return this.blockData != null;
|
||||
@@ -1188,6 +1341,36 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.hideTooltip = hideTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTooltipStyle() {
|
||||
return this.tooltipStyle != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getTooltipStyle() {
|
||||
return this.tooltipStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTooltipStyle(NamespacedKey tooltipStyle) {
|
||||
this.tooltipStyle = tooltipStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasItemModel() {
|
||||
return this.itemModel != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getItemModel() {
|
||||
return this.itemModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemModel(NamespacedKey itemModel) {
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnbreakable() {
|
||||
return unbreakable;
|
||||
@@ -1214,14 +1397,39 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.enchantmentGlintOverride = override;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlider() {
|
||||
return this.glider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlider(boolean glider) {
|
||||
this.glider = glider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFireResistant() {
|
||||
return this.fireResistant;
|
||||
return hasDamageResistant() && DamageTypeTags.IS_FIRE.equals(getDamageResistant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFireResistant(boolean fireResistant) {
|
||||
this.fireResistant = fireResistant;
|
||||
setDamageResistant(DamageTypeTags.IS_FIRE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDamageResistant() {
|
||||
return this.damageResistant != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<DamageType> getDamageResistant() {
|
||||
return (hasDamageResistant()) ? Bukkit.getTag(DamageTypeTags.REGISTRY_DAMAGE_TYPES, CraftNamespacedKey.fromMinecraft(this.damageResistant.location()), DamageType.class) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamageResistant(Tag<DamageType> tag) {
|
||||
this.damageResistant = (tag != null) ? ((CraftDamageTag) tag).getHandle().key() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1258,6 +1466,36 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.rarity = rarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUseRemainder() {
|
||||
return this.useRemainder != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getUseRemainder() {
|
||||
return this.useRemainder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseRemainder(ItemStack useRemainder) {
|
||||
this.useRemainder = useRemainder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUseCooldown() {
|
||||
return this.useCooldown != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UseCooldownComponent getUseCooldown() {
|
||||
return (this.hasUseCooldown()) ? new CraftUseCooldownComponent(this.useCooldown) : new CraftUseCooldownComponent(new UseCooldown(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseCooldown(UseCooldownComponent cooldown) {
|
||||
this.useCooldown = (cooldown == null) ? null : new CraftUseCooldownComponent((CraftUseCooldownComponent) cooldown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFood() {
|
||||
return this.food != null;
|
||||
@@ -1265,7 +1503,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
|
||||
@Override
|
||||
public FoodComponent getFood() {
|
||||
return (this.hasFood()) ? new CraftFoodComponent(this.food) : new CraftFoodComponent(new FoodInfo(0, 0, false, 0, Optional.empty(), Collections.emptyList()));
|
||||
return (this.hasFood()) ? new CraftFoodComponent(this.food) : new CraftFoodComponent(new FoodInfo(0, 0, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1288,6 +1526,21 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.tool = (tool == null) ? null : new CraftToolComponent((CraftToolComponent) tool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEquippable() {
|
||||
return this.equippable != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EquippableComponent getEquippable() {
|
||||
return (this.hasEquippable()) ? new CraftEquippableComponent(this.equippable) : new CraftEquippableComponent(Equippable.builder(EnumItemSlot.HEAD).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEquippable(EquippableComponent equippable) {
|
||||
this.equippable = (equippable == null) ? null : new CraftEquippableComponent((CraftEquippableComponent) this.equippable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasJukeboxPlayable() {
|
||||
return this.jukebox != null;
|
||||
@@ -1436,7 +1689,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
|
||||
IRegistryCustom registryAccess = CraftRegistry.getMinecraftRegistry();
|
||||
DynamicOps<NBTBase> ops = registryAccess.createSerializationContext(DynamicOpsNBT.INSTANCE);
|
||||
IRegistry<DataComponentType<?>> componentTypeRegistry = registryAccess.registryOrThrow(Registries.DATA_COMPONENT_TYPE);
|
||||
IRegistry<DataComponentType<?>> componentTypeRegistry = registryAccess.lookupOrThrow(Registries.DATA_COMPONENT_TYPE);
|
||||
|
||||
StringJoiner componentString = new StringJoiner(",", "[", "]");
|
||||
for (Entry<DataComponentType<?>, Optional<?>> entry : patch.entrySet()) {
|
||||
@@ -1540,6 +1793,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
&& (this.hasEnchants() ? that.hasEnchants() && this.enchantments.equals(that.enchantments) : !that.hasEnchants())
|
||||
&& (Objects.equals(this.lore, that.lore))
|
||||
&& (this.hasCustomModelData() ? that.hasCustomModelData() && this.customModelData.equals(that.customModelData) : !that.hasCustomModelData())
|
||||
&& (this.hasEnchantable() ? that.hasEnchantable() && this.enchantableValue.equals(that.enchantableValue) : !that.hasEnchantable())
|
||||
&& (this.hasBlockData() ? that.hasBlockData() && this.blockData.equals(that.blockData) : !that.hasBlockData())
|
||||
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
|
||||
&& (this.hasAttributeModifiers() ? that.hasAttributeModifiers() && compareModifiers(this.attributeModifiers, that.attributeModifiers) : !that.hasAttributeModifiers())
|
||||
@@ -1549,13 +1803,19 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
&& (this.persistentDataContainer.equals(that.persistentDataContainer))
|
||||
&& (this.hideFlag == that.hideFlag)
|
||||
&& (this.isHideTooltip() == that.isHideTooltip())
|
||||
&& (this.hasTooltipStyle() ? that.hasTooltipStyle() && this.tooltipStyle.equals(that.tooltipStyle) : !that.hasTooltipStyle())
|
||||
&& (this.hasItemModel() ? that.hasItemModel() && this.itemModel.equals(that.itemModel) : !that.hasItemModel())
|
||||
&& (this.isUnbreakable() == that.isUnbreakable())
|
||||
&& (this.hasEnchantmentGlintOverride() ? that.hasEnchantmentGlintOverride() && this.enchantmentGlintOverride.equals(that.enchantmentGlintOverride) : !that.hasEnchantmentGlintOverride())
|
||||
&& (this.fireResistant == that.fireResistant)
|
||||
&& (this.glider == that.glider)
|
||||
&& (this.hasDamageResistant() ? that.hasDamageResistant() && this.damageResistant.equals(that.damageResistant) : !that.hasDamageResistant())
|
||||
&& (this.hasMaxStackSize() ? that.hasMaxStackSize() && this.maxStackSize.equals(that.maxStackSize) : !that.hasMaxStackSize())
|
||||
&& (this.rarity == that.rarity)
|
||||
&& (this.hasUseRemainder() ? that.hasUseRemainder() && this.useRemainder.equals(that.useRemainder) : !that.hasUseRemainder())
|
||||
&& (this.hasUseCooldown() ? that.hasUseCooldown() && this.useCooldown.equals(that.useCooldown) : !that.hasUseCooldown())
|
||||
&& (this.hasFood() ? that.hasFood() && this.food.equals(that.food) : !that.hasFood())
|
||||
&& (this.hasTool() ? that.hasTool() && this.tool.equals(that.tool) : !that.hasTool())
|
||||
&& (this.hasEquippable() ? that.hasEquippable() && this.equippable.equals(that.equippable) : !that.hasEquippable())
|
||||
&& (this.hasJukeboxPlayable() ? that.hasJukeboxPlayable() && this.jukebox.equals(that.jukebox) : !that.hasJukeboxPlayable())
|
||||
&& (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage())
|
||||
&& (this.hasMaxDamage() ? that.hasMaxDamage() && this.maxDamage.equals(that.maxDamage) : !that.hasMaxDamage())
|
||||
@@ -1584,6 +1844,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
hash = 61 * hash + (hasItemName() ? this.itemName.hashCode() : 0);
|
||||
hash = 61 * hash + ((lore != null) ? this.lore.hashCode() : 0);
|
||||
hash = 61 * hash + (hasCustomModelData() ? this.customModelData.hashCode() : 0);
|
||||
hash = 61 * hash + (hasEnchantable() ? this.enchantableValue.hashCode() : 0);
|
||||
hash = 61 * hash + (hasBlockData() ? this.blockData.hashCode() : 0);
|
||||
hash = 61 * hash + (hasEnchants() ? this.enchantments.hashCode() : 0);
|
||||
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
|
||||
@@ -1593,14 +1854,20 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
hash = 61 * hash + (!persistentDataContainer.isEmpty() ? persistentDataContainer.hashCode() : 0);
|
||||
hash = 61 * hash + hideFlag;
|
||||
hash = 61 * hash + (isHideTooltip() ? 1231 : 1237);
|
||||
hash = 61 * hash + (hasTooltipStyle() ? this.tooltipStyle.hashCode() : 0);
|
||||
hash = 61 * hash + (hasItemModel() ? this.itemModel.hashCode() : 0);
|
||||
hash = 61 * hash + (isUnbreakable() ? 1231 : 1237);
|
||||
hash = 61 * hash + (hasEnchantmentGlintOverride() ? this.enchantmentGlintOverride.hashCode() : 0);
|
||||
hash = 61 * hash + (isFireResistant() ? 1231 : 1237);
|
||||
hash = 61 * hash + (isGlider() ? 1231 : 1237);
|
||||
hash = 61 * hash + (hasDamageResistant() ? this.damageResistant.hashCode() : 0);
|
||||
hash = 61 * hash + (hasMaxStackSize() ? this.maxStackSize.hashCode() : 0);
|
||||
hash = 61 * hash + (hasRarity() ? this.rarity.hashCode() : 0);
|
||||
hash = 61 * hash + (hasUseRemainder() ? this.useRemainder.hashCode() : 0);
|
||||
hash = 61 * hash + (hasUseCooldown() ? this.useCooldown.hashCode() : 0);
|
||||
hash = 61 * hash + (hasFood() ? this.food.hashCode() : 0);
|
||||
hash = 61 * hash + (hasTool() ? this.tool.hashCode() : 0);
|
||||
hash = 61 * hash + (hasJukeboxPlayable() ? this.jukebox.hashCode() : 0);
|
||||
hash = 61 * hash + (hasEquippable() ? this.equippable.hashCode() : 0);
|
||||
hash = 61 * hash + (hasDamage() ? this.damage : 0);
|
||||
hash = 61 * hash + (hasMaxDamage() ? 1231 : 1237);
|
||||
hash = 61 * hash + (hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0);
|
||||
@@ -1617,6 +1884,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
clone.lore = new ArrayList<IChatBaseComponent>(this.lore);
|
||||
}
|
||||
clone.customModelData = this.customModelData;
|
||||
clone.enchantableValue = this.enchantableValue;
|
||||
clone.blockData = this.blockData;
|
||||
if (this.enchantments != null) {
|
||||
clone.enchantments = new LinkedHashMap<Enchantment, Integer>(this.enchantments);
|
||||
@@ -1631,17 +1899,29 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), DATA_TYPE_REGISTRY);
|
||||
clone.hideFlag = this.hideFlag;
|
||||
clone.hideTooltip = this.hideTooltip;
|
||||
clone.tooltipStyle = this.tooltipStyle;
|
||||
clone.itemModel = this.itemModel;
|
||||
clone.unbreakable = this.unbreakable;
|
||||
clone.enchantmentGlintOverride = this.enchantmentGlintOverride;
|
||||
clone.fireResistant = fireResistant;
|
||||
clone.glider = glider;
|
||||
clone.damageResistant = damageResistant;
|
||||
clone.maxStackSize = maxStackSize;
|
||||
clone.rarity = rarity;
|
||||
if (this.hasUseRemainder()) {
|
||||
clone.useRemainder = useRemainder.clone();
|
||||
}
|
||||
if (this.hasUseCooldown()) {
|
||||
clone.useCooldown = new CraftUseCooldownComponent(useCooldown);
|
||||
}
|
||||
if (this.hasFood()) {
|
||||
clone.food = new CraftFoodComponent(food);
|
||||
}
|
||||
if (this.hasTool()) {
|
||||
clone.tool = new CraftToolComponent(tool);
|
||||
}
|
||||
if (this.hasEquippable()) {
|
||||
clone.equippable = new CraftEquippableComponent(equippable);
|
||||
}
|
||||
if (this.hasJukeboxPlayable()) {
|
||||
clone.jukebox = new CraftJukeboxComponent(jukebox);
|
||||
}
|
||||
@@ -1686,6 +1966,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
if (hasCustomModelData()) {
|
||||
builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData);
|
||||
}
|
||||
if (hasEnchantable()) {
|
||||
builder.put(ENCHANTABLE.BUKKIT, enchantableValue);
|
||||
}
|
||||
if (hasBlockData()) {
|
||||
builder.put(BLOCK_DATA.BUKKIT, blockData);
|
||||
}
|
||||
@@ -1709,6 +1992,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
builder.put(HIDE_TOOLTIP.BUKKIT, hideTooltip);
|
||||
}
|
||||
|
||||
if (hasTooltipStyle()) {
|
||||
builder.put(TOOLTIP_STYLE.BUKKIT, tooltipStyle.toString());
|
||||
}
|
||||
|
||||
if (hasItemModel()) {
|
||||
builder.put(ITEM_MODEL.BUKKIT, itemModel.toString());
|
||||
}
|
||||
|
||||
if (isUnbreakable()) {
|
||||
builder.put(UNBREAKABLE.BUKKIT, unbreakable);
|
||||
}
|
||||
@@ -1717,8 +2008,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
builder.put(ENCHANTMENT_GLINT_OVERRIDE.BUKKIT, enchantmentGlintOverride);
|
||||
}
|
||||
|
||||
if (isFireResistant()) {
|
||||
builder.put(FIRE_RESISTANT.BUKKIT, fireResistant);
|
||||
if (isGlider()) {
|
||||
builder.put(GLIDER.BUKKIT, glider);
|
||||
}
|
||||
|
||||
if (hasDamageResistant()) {
|
||||
builder.put(DAMAGE_RESISTANT.BUKKIT, damageResistant.location().toString());
|
||||
}
|
||||
|
||||
if (hasMaxStackSize()) {
|
||||
@@ -1729,6 +2024,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
builder.put(RARITY.BUKKIT, rarity.name());
|
||||
}
|
||||
|
||||
if (hasUseRemainder()) {
|
||||
builder.put(USE_REMAINDER.BUKKIT, useRemainder);
|
||||
}
|
||||
|
||||
if (hasUseCooldown()) {
|
||||
builder.put(USE_COOLDOWN.BUKKIT, useCooldown);
|
||||
}
|
||||
|
||||
if (hasFood()) {
|
||||
builder.put(FOOD.BUKKIT, food);
|
||||
}
|
||||
@@ -1737,6 +2040,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
builder.put(TOOL.BUKKIT, tool);
|
||||
}
|
||||
|
||||
if (hasEquippable()) {
|
||||
builder.put(EQUIPPABLE.BUKKIT, equippable);
|
||||
}
|
||||
|
||||
if (hasJukeboxPlayable()) {
|
||||
builder.put(JUKEBOX_PLAYABLE.BUKKIT, jukebox);
|
||||
}
|
||||
@@ -1778,7 +2085,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
|
||||
if (!this.removedTags.isEmpty()) {
|
||||
IRegistryCustom registryAccess = CraftRegistry.getMinecraftRegistry();
|
||||
IRegistry<DataComponentType<?>> componentTypeRegistry = registryAccess.registryOrThrow(Registries.DATA_COMPONENT_TYPE);
|
||||
IRegistry<DataComponentType<?>> componentTypeRegistry = registryAccess.lookupOrThrow(Registries.DATA_COMPONENT_TYPE);
|
||||
|
||||
List<String> removedTags = new ArrayList<>();
|
||||
for (DataComponentType<?> removed : this.removedTags) {
|
||||
@@ -1906,18 +2213,25 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
ITEM_NAME.TYPE,
|
||||
LORE.TYPE,
|
||||
CUSTOM_MODEL_DATA.TYPE,
|
||||
ENCHANTABLE.TYPE,
|
||||
BLOCK_DATA.TYPE,
|
||||
REPAIR.TYPE,
|
||||
ENCHANTMENTS.TYPE,
|
||||
HIDE_ADDITIONAL_TOOLTIP.TYPE,
|
||||
HIDE_TOOLTIP.TYPE,
|
||||
TOOLTIP_STYLE.TYPE,
|
||||
ITEM_MODEL.TYPE,
|
||||
UNBREAKABLE.TYPE,
|
||||
ENCHANTMENT_GLINT_OVERRIDE.TYPE,
|
||||
FIRE_RESISTANT.TYPE,
|
||||
GLIDER.TYPE,
|
||||
DAMAGE_RESISTANT.TYPE,
|
||||
MAX_STACK_SIZE.TYPE,
|
||||
RARITY.TYPE,
|
||||
USE_REMAINDER.TYPE,
|
||||
USE_COOLDOWN.TYPE,
|
||||
FOOD.TYPE,
|
||||
TOOL.TYPE,
|
||||
EQUIPPABLE.TYPE,
|
||||
JUKEBOX_PLAYABLE.TYPE,
|
||||
DAMAGE.TYPE,
|
||||
MAX_DAMAGE.TYPE,
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.util.Map;
|
||||
import net.minecraft.core.component.DataComponentPatch;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.crafting.IRecipe;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
@@ -16,7 +18,7 @@ import org.bukkit.inventory.meta.KnowledgeBookMeta;
|
||||
@DelegateDeserialization(SerializableMeta.class)
|
||||
public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBookMeta {
|
||||
|
||||
static final ItemMetaKeyType<List<MinecraftKey>> BOOK_RECIPES = new ItemMetaKeyType<>(DataComponents.RECIPES, "Recipes");
|
||||
static final ItemMetaKeyType<List<ResourceKey<IRecipe<?>>>> BOOK_RECIPES = new ItemMetaKeyType<>(DataComponents.RECIPES, "Recipes");
|
||||
static final int MAX_RECIPES = Short.MAX_VALUE;
|
||||
|
||||
protected List<NamespacedKey> recipes = new ArrayList<NamespacedKey>();
|
||||
@@ -35,7 +37,7 @@ public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBo
|
||||
|
||||
getOrEmpty(tag, BOOK_RECIPES).ifPresent((pages) -> {
|
||||
for (int i = 0; i < pages.size(); i++) {
|
||||
MinecraftKey recipe = pages.get(i);
|
||||
MinecraftKey recipe = pages.get(i).location();
|
||||
|
||||
addRecipe(CraftNamespacedKey.fromMinecraft(recipe));
|
||||
}
|
||||
@@ -60,9 +62,9 @@ public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBo
|
||||
super.applyToItem(itemData);
|
||||
|
||||
if (hasRecipes()) {
|
||||
List<MinecraftKey> list = new ArrayList<>();
|
||||
List<ResourceKey<IRecipe<?>>> list = new ArrayList<>();
|
||||
for (NamespacedKey recipe : this.recipes) {
|
||||
list.add(CraftNamespacedKey.toMinecraft(recipe));
|
||||
list.add(CraftRecipe.toMinecraft(recipe));
|
||||
}
|
||||
itemData.put(BOOK_RECIPES, list);
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import com.google.common.collect.ImmutableMap.Builder;
|
||||
import java.util.Map;
|
||||
import net.minecraft.core.component.DataComponentPatch;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.world.item.component.OminousBottleAmplifier;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
import org.bukkit.inventory.meta.OminousBottleMeta;
|
||||
|
||||
@DelegateDeserialization(SerializableMeta.class)
|
||||
public class CraftMetaOminousBottle extends CraftMetaItem implements OminousBottleMeta {
|
||||
|
||||
static final ItemMetaKeyType<Integer> OMINOUS_BOTTLE_AMPLIFIER = new ItemMetaKeyType<>(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, "ominous-bottle-amplifier");
|
||||
static final ItemMetaKeyType<OminousBottleAmplifier> OMINOUS_BOTTLE_AMPLIFIER = new ItemMetaKeyType<>(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, "ominous-bottle-amplifier");
|
||||
private Integer ominousBottleAmplifier;
|
||||
|
||||
CraftMetaOminousBottle(CraftMetaItem meta) {
|
||||
@@ -26,7 +27,7 @@ public class CraftMetaOminousBottle extends CraftMetaItem implements OminousBott
|
||||
CraftMetaOminousBottle(DataComponentPatch tag) {
|
||||
super(tag);
|
||||
getOrEmpty(tag, OMINOUS_BOTTLE_AMPLIFIER).ifPresent((amplifier) -> {
|
||||
ominousBottleAmplifier = amplifier;
|
||||
ominousBottleAmplifier = amplifier.value();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ public class CraftMetaOminousBottle extends CraftMetaItem implements OminousBott
|
||||
super.applyToItem(tag);
|
||||
|
||||
if (hasAmplifier()) {
|
||||
tag.put(OMINOUS_BOTTLE_AMPLIFIER, ominousBottleAmplifier);
|
||||
tag.put(OMINOUS_BOTTLE_AMPLIFIER, new OminousBottleAmplifier(ominousBottleAmplifier));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,13 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
static final ItemMetaKeyType<PotionContents> POTION_CONTENTS = new ItemMetaKeyType<>(DataComponents.POTION_CONTENTS);
|
||||
static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("custom-effects");
|
||||
static final ItemMetaKey POTION_COLOR = new ItemMetaKey("custom-color");
|
||||
static final ItemMetaKey CUSTOM_NAME = new ItemMetaKey("custom-name");
|
||||
static final ItemMetaKey DEFAULT_POTION = new ItemMetaKey("potion-type");
|
||||
|
||||
private PotionType type;
|
||||
private List<PotionEffect> customEffects;
|
||||
private Color color;
|
||||
private String customName;
|
||||
|
||||
CraftMetaPotion(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
@@ -46,6 +48,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
this.type = potionMeta.type;
|
||||
this.color = potionMeta.color;
|
||||
this.customName = potionMeta.customName;
|
||||
if (potionMeta.hasCustomEffects()) {
|
||||
this.customEffects = new ArrayList<>(potionMeta.customEffects);
|
||||
}
|
||||
@@ -66,6 +69,10 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
});
|
||||
|
||||
potionContents.customName().ifPresent((name) -> {
|
||||
customName = name;
|
||||
});
|
||||
|
||||
List<MobEffect> list = potionContents.customEffects();
|
||||
int length = list.size();
|
||||
customEffects = new ArrayList<>(length);
|
||||
@@ -100,6 +107,11 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
String name = SerializableMeta.getString(map, CUSTOM_NAME.BUKKIT, true);
|
||||
if (name != null) {
|
||||
setCustomName(name);
|
||||
}
|
||||
|
||||
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, POTION_EFFECTS.BUKKIT, true);
|
||||
if (rawEffectList == null) {
|
||||
return;
|
||||
@@ -121,6 +133,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
|
||||
Optional<Holder<PotionRegistry>> defaultPotion = (hasBasePotionType()) ? Optional.of(CraftPotionType.bukkitToMinecraftHolder(type)) : Optional.empty();
|
||||
Optional<Integer> potionColor = (hasColor()) ? Optional.of(this.color.asRGB()) : Optional.empty();
|
||||
Optional<String> customName = Optional.ofNullable(this.customName);
|
||||
|
||||
List<MobEffect> effectList = new ArrayList<>();
|
||||
if (customEffects != null) {
|
||||
@@ -129,7 +142,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
}
|
||||
|
||||
tag.put(POTION_CONTENTS, new PotionContents(defaultPotion, potionColor, effectList));
|
||||
tag.put(POTION_CONTENTS, new PotionContents(defaultPotion, potionColor, effectList, customName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,7 +151,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
|
||||
boolean isPotionEmpty() {
|
||||
return (type == null) && !(hasCustomEffects() || hasColor());
|
||||
return (type == null) && !(hasCustomEffects() || hasColor() || hasCustomName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,6 +305,21 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return this.customName != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
return this.customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
int applyHash() {
|
||||
final int original;
|
||||
@@ -302,6 +330,9 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
if (hasColor()) {
|
||||
hash = 73 * hash + color.hashCode();
|
||||
}
|
||||
if (hasCustomName()) {
|
||||
hash = 73 * hash + customName.hashCode();
|
||||
}
|
||||
if (hasCustomEffects()) {
|
||||
hash = 73 * hash + customEffects.hashCode();
|
||||
}
|
||||
@@ -318,7 +349,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
|
||||
return Objects.equals(type, that.type)
|
||||
&& (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects())
|
||||
&& (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor());
|
||||
&& (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor())
|
||||
&& (this.hasCustomName() ? that.hasCustomName() && this.customName.equals(that.customName) : !that.hasCustomName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -339,6 +371,10 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
builder.put(POTION_COLOR.BUKKIT, getColor());
|
||||
}
|
||||
|
||||
if (hasCustomName()) {
|
||||
builder.put(CUSTOM_NAME.BUKKIT, getCustomName());
|
||||
}
|
||||
|
||||
if (hasCustomEffects()) {
|
||||
builder.put(POTION_EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects));
|
||||
}
|
||||
|
||||
@@ -3,8 +3,15 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.crafting.IRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.recipe.CookingBookCategory;
|
||||
@@ -14,47 +21,53 @@ public interface CraftRecipe extends Recipe {
|
||||
|
||||
void addToCraftingManager();
|
||||
|
||||
default Optional<RecipeItemStack> toNMSOptional(RecipeChoice bukkit, boolean requireNotEmpty) {
|
||||
return (bukkit == null) ? Optional.empty() : Optional.of(toNMS(bukkit, requireNotEmpty));
|
||||
}
|
||||
|
||||
default RecipeItemStack toNMS(RecipeChoice bukkit, boolean requireNotEmpty) {
|
||||
RecipeItemStack stack;
|
||||
|
||||
if (bukkit == null) {
|
||||
stack = RecipeItemStack.EMPTY;
|
||||
stack = RecipeItemStack.of();
|
||||
} else if (bukkit instanceof RecipeChoice.MaterialChoice) {
|
||||
stack = new RecipeItemStack(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.world.item.crafting.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(new ItemStack(mat)))));
|
||||
stack = RecipeItemStack.of(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> CraftItemType.bukkitToMinecraft(mat)));
|
||||
} else if (bukkit instanceof RecipeChoice.ExactChoice) {
|
||||
stack = new RecipeItemStack(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.world.item.crafting.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(mat))));
|
||||
stack.exact = true;
|
||||
stack = RecipeItemStack.ofStacks(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> CraftItemStack.asNMSCopy(mat)));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit);
|
||||
}
|
||||
|
||||
stack.getItems();
|
||||
List<Holder<Item>> items = stack.items();
|
||||
if (requireNotEmpty) {
|
||||
Preconditions.checkArgument(stack.itemStacks.length != 0, "Recipe requires at least one non-air choice");
|
||||
Preconditions.checkArgument(!items.isEmpty(), "Recipe requires at least one non-air choice");
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static RecipeChoice toBukkit(RecipeItemStack list) {
|
||||
list.getItems();
|
||||
public static RecipeChoice toBukkit(Optional<RecipeItemStack> list) {
|
||||
return list.map(CraftRecipe::toBukkit).orElse(null);
|
||||
}
|
||||
|
||||
if (list.itemStacks.length == 0) {
|
||||
public static RecipeChoice toBukkit(RecipeItemStack list) {
|
||||
List<Holder<Item>> items = list.items();
|
||||
|
||||
if (items.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (list.exact) {
|
||||
List<org.bukkit.inventory.ItemStack> choices = new ArrayList<>(list.itemStacks.length);
|
||||
for (net.minecraft.world.item.ItemStack i : list.itemStacks) {
|
||||
if (list.isExact()) {
|
||||
List<org.bukkit.inventory.ItemStack> choices = new ArrayList<>(list.itemStacks().size());
|
||||
for (net.minecraft.world.item.ItemStack i : list.itemStacks()) {
|
||||
choices.add(CraftItemStack.asBukkitCopy(i));
|
||||
}
|
||||
|
||||
return new RecipeChoice.ExactChoice(choices);
|
||||
} else {
|
||||
|
||||
List<org.bukkit.Material> choices = new ArrayList<>(list.itemStacks.length);
|
||||
for (net.minecraft.world.item.ItemStack i : list.itemStacks) {
|
||||
choices.add(CraftItemType.minecraftToBukkit(i.getItem()));
|
||||
List<org.bukkit.Material> choices = new ArrayList<>(items.size());
|
||||
for (Holder<Item> i : items) {
|
||||
choices.add(CraftItemType.minecraftToBukkit(i.value()));
|
||||
}
|
||||
|
||||
return new RecipeChoice.MaterialChoice(choices);
|
||||
@@ -76,4 +89,8 @@ public interface CraftRecipe extends Recipe {
|
||||
public static CookingBookCategory getCategory(net.minecraft.world.item.crafting.CookingBookCategory nms) {
|
||||
return CookingBookCategory.valueOf(nms.name());
|
||||
}
|
||||
|
||||
public static ResourceKey<IRecipe<?>> toMinecraft(NamespacedKey key) {
|
||||
return ResourceKey.create(Registries.RECIPE, CraftNamespacedKey.toMinecraft(key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.world.item.crafting.RecipeItemStack;
|
||||
import net.minecraft.world.item.crafting.ShapedRecipePattern;
|
||||
import net.minecraft.world.item.crafting.ShapedRecipes;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
@@ -54,7 +53,7 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||
Map<Character, RecipeItemStack> data = Maps.transformValues(ingred, (bukkit) -> toNMS(bukkit, false));
|
||||
|
||||
ShapedRecipePattern pattern = ShapedRecipePattern.of(data, shape);
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), pattern, CraftItemStack.asNMSCopy(this.getResult()))));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), pattern, CraftItemStack.asNMSCopy(this.getResult()))));
|
||||
}
|
||||
|
||||
private static String[] replaceUndefinedIngredientsWithEmpty(String[] shape, Map<Character, org.bukkit.inventory.RecipeChoice> ingredients) {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.item.crafting.RecipeItemStack;
|
||||
import net.minecraft.world.item.crafting.ShapelessRecipes;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
@@ -41,11 +40,11 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
|
||||
@Override
|
||||
public void addToCraftingManager() {
|
||||
List<org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceList();
|
||||
NonNullList<RecipeItemStack> data = NonNullList.withSize(ingred.size(), RecipeItemStack.EMPTY);
|
||||
List<RecipeItemStack> data = new ArrayList<>(ingred.size());
|
||||
for (int i = 0; i < ingred.size(); i++) {
|
||||
data.set(i, toNMS(ingred.get(i), true));
|
||||
}
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapelessRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data)));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new ShapelessRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.SmithingTransformRecipe;
|
||||
@@ -25,6 +24,6 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(toNMS(this.getTemplate(), false), toNMS(this.getBase(), false), toNMS(this.getAddition(), false), CraftItemStack.asNMSCopy(result))));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(toNMSOptional(this.getTemplate(), false), toNMSOptional(this.getBase(), false), toNMSOptional(this.getAddition(), false), CraftItemStack.asNMSCopy(result))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.SmithingTrimRecipe;
|
||||
|
||||
@@ -23,6 +22,6 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft
|
||||
|
||||
@Override
|
||||
public void addToCraftingManager() {
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(toNMS(this.getTemplate(), false), toNMS(this.getBase(), false), toNMS(this.getAddition(), false))));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(toNMSOptional(this.getTemplate(), false), toNMSOptional(this.getBase(), false), toNMSOptional(this.getAddition(), false))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.SmokingRecipe;
|
||||
@@ -27,6 +26,6 @@ public class CraftSmokingRecipe extends SmokingRecipe implements CraftRecipe {
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeSmoking(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeSmoking(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.StonecuttingRecipe;
|
||||
@@ -26,6 +25,6 @@ public class CraftStonecuttingRecipe extends StonecuttingRecipe implements Craft
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeStonecutting(this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result))));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeStonecutting(this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.TransmuteRecipe;
|
||||
|
||||
public class CraftTransmuteRecipe extends TransmuteRecipe implements CraftRecipe {
|
||||
|
||||
public CraftTransmuteRecipe(NamespacedKey key, Material result, RecipeChoice input, RecipeChoice material) {
|
||||
super(key, result, input, material);
|
||||
}
|
||||
|
||||
public static CraftTransmuteRecipe fromBukkitRecipe(TransmuteRecipe recipe) {
|
||||
if (recipe instanceof CraftTransmuteRecipe) {
|
||||
return (CraftTransmuteRecipe) recipe;
|
||||
}
|
||||
CraftTransmuteRecipe ret = new CraftTransmuteRecipe(recipe.getKey(), recipe.getResult().getType(), recipe.getInput(), recipe.getMaterial());
|
||||
ret.setGroup(recipe.getGroup());
|
||||
ret.setCategory(recipe.getCategory());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToCraftingManager() {
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(
|
||||
new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()),
|
||||
new net.minecraft.world.item.crafting.TransmuteRecipe(this.getGroup(),
|
||||
CraftRecipe.getCategory(this.getCategory()),
|
||||
toNMS(this.getInput(), true),
|
||||
toNMS(this.getMaterial(), true),
|
||||
Holder.direct(CraftItemType.bukkitToMinecraft(this.getResult().getType()))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class RecipeIterator implements Iterator<Recipe> {
|
||||
private final Iterator<Map.Entry<Recipes<?>, RecipeHolder<?>>> recipes;
|
||||
|
||||
public RecipeIterator() {
|
||||
this.recipes = MinecraftServer.getServer().getRecipeManager().byType.entries().iterator();
|
||||
this.recipes = MinecraftServer.getServer().getRecipeManager().recipes.byType.entries().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
package org.bukkit.craftbukkit.inventory.components;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.sounds.SoundEffects;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.EnumItemSlot;
|
||||
import net.minecraft.world.item.equipment.Equippable;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftSound;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.inventory.SerializableMeta;
|
||||
import org.bukkit.craftbukkit.tag.CraftEntityTag;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.meta.components.EquippableComponent;
|
||||
|
||||
@SerializableAs("Equippable")
|
||||
public final class CraftEquippableComponent implements EquippableComponent {
|
||||
|
||||
private Equippable handle;
|
||||
|
||||
public CraftEquippableComponent(Equippable handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
public CraftEquippableComponent(CraftEquippableComponent craft) {
|
||||
this.handle = craft.handle;
|
||||
}
|
||||
|
||||
public CraftEquippableComponent(Map<String, Object> map) {
|
||||
EnumItemSlot slot = CraftEquipmentSlot.getNMS(EquipmentSlot.valueOf(SerializableMeta.getString(map, "slot", false)));
|
||||
|
||||
Sound equipSound = null;
|
||||
String snd = SerializableMeta.getString(map, "equip-sound", true);
|
||||
if (snd != null) {
|
||||
equipSound = Registry.SOUNDS.get(NamespacedKey.fromString(snd));
|
||||
}
|
||||
|
||||
String model = SerializableMeta.getString(map, "model", true);
|
||||
String cameraOverlay = SerializableMeta.getString(map, "camera-overlay", true);
|
||||
|
||||
HolderSet<EntityTypes<?>> allowedEntities = null;
|
||||
Object allowed = SerializableMeta.getObject(Object.class, map, "allowed-entities", true);
|
||||
if (allowed != null) {
|
||||
allowedEntities = CraftHolderUtil.parse(allowed, Registries.ENTITY_TYPE, BuiltInRegistries.ENTITY_TYPE);
|
||||
}
|
||||
|
||||
Boolean dispensable = SerializableMeta.getObject(Boolean.class, map, "dispensable", true);
|
||||
Boolean swappable = SerializableMeta.getObject(Boolean.class, map, "swappable", true);
|
||||
Boolean damageOnHurt = SerializableMeta.getObject(Boolean.class, map, "damage-on-hurt", true);
|
||||
|
||||
this.handle = new Equippable(slot,
|
||||
(equipSound != null) ? CraftSound.bukkitToMinecraftHolder(equipSound) : SoundEffects.ARMOR_EQUIP_GENERIC,
|
||||
Optional.ofNullable(model).map(MinecraftKey::parse),
|
||||
Optional.ofNullable(cameraOverlay).map(MinecraftKey::parse),
|
||||
Optional.ofNullable(allowedEntities),
|
||||
(dispensable != null) ? dispensable : true,
|
||||
(swappable != null) ? swappable : true,
|
||||
(damageOnHurt != null) ? damageOnHurt : true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("slot", getSlot().name());
|
||||
result.put("equip-sound", getEquipSound().getKey().toString());
|
||||
|
||||
NamespacedKey model = getModel();
|
||||
if (model != null) {
|
||||
result.put("model", model.toString());
|
||||
}
|
||||
|
||||
NamespacedKey cameraOverlay = getCameraOverlay();
|
||||
if (cameraOverlay != null) {
|
||||
result.put("camera-overlay", cameraOverlay.toString());
|
||||
}
|
||||
|
||||
Optional<HolderSet<EntityTypes<?>>> allowed = handle.allowedEntities();
|
||||
if (allowed.isPresent()) {
|
||||
CraftHolderUtil.serialize(result, "allowed-entities", allowed.get());
|
||||
}
|
||||
|
||||
result.put("dispensable", isDispensable());
|
||||
result.put("swappable", isSwappable());
|
||||
result.put("damage-on-hurt", isDamageOnHurt());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Equippable getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EquipmentSlot getSlot() {
|
||||
return CraftEquipmentSlot.getSlot(handle.slot());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSlot(EquipmentSlot slot) {
|
||||
handle = new Equippable(CraftEquipmentSlot.getNMS(slot), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getEquipSound() {
|
||||
return CraftSound.minecraftToBukkit(handle.equipSound().value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEquipSound(Sound sound) {
|
||||
handle = new Equippable(handle.slot(), (sound != null) ? CraftSound.bukkitToMinecraftHolder(sound) : SoundEffects.ARMOR_EQUIP_GENERIC, handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getModel() {
|
||||
return handle.model().map(CraftNamespacedKey::fromMinecraft).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(NamespacedKey key) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), Optional.ofNullable(key).map(CraftNamespacedKey::toMinecraft), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getCameraOverlay() {
|
||||
return handle.cameraOverlay().map(CraftNamespacedKey::fromMinecraft).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCameraOverlay(NamespacedKey key) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), Optional.ofNullable(key).map(CraftNamespacedKey::toMinecraft), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityType> getAllowedEntities() {
|
||||
return handle.allowedEntities().map(HolderSet::stream).map((stream) -> stream.map(Holder::value).map(CraftEntityType::minecraftToBukkit).collect(Collectors.toList())).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowedEntities(EntityType entities) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(),
|
||||
(entities != null) ? Optional.of(HolderSet.direct(CraftEntityType.bukkitToMinecraftHolder(entities))) : Optional.empty(),
|
||||
handle.dispensable(), handle.swappable(), handle.damageOnHurt()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowedEntities(Collection<EntityType> entities) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(),
|
||||
(entities != null) ? Optional.of(HolderSet.direct(entities.stream().map(CraftEntityType::bukkitToMinecraftHolder).collect(Collectors.toList()))) : Optional.empty(),
|
||||
handle.dispensable(), handle.swappable(), handle.damageOnHurt()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowedEntities(Tag<EntityType> tag) {
|
||||
Preconditions.checkArgument(tag instanceof CraftEntityTag, "tag must be an entity tag");
|
||||
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(),
|
||||
(tag != null) ? Optional.of(((CraftEntityTag) tag).getHandle()) : Optional.empty(),
|
||||
handle.dispensable(), handle.swappable(), handle.damageOnHurt()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDispensable() {
|
||||
return handle.dispensable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDispensable(boolean dispensable) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), dispensable, handle.swappable(), handle.damageOnHurt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSwappable() {
|
||||
return handle.swappable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSwappable(boolean swappable) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), swappable, handle.damageOnHurt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageOnHurt() {
|
||||
return handle.damageOnHurt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamageOnHurt(boolean damage) {
|
||||
handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CraftEquippableComponent other = (CraftEquippableComponent) obj;
|
||||
return Objects.equals(this.handle, other.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 19 * hash + Objects.hashCode(this.handle);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftEquippableComponent{" + "handle=" + handle + '}';
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,13 @@
|
||||
package org.bukkit.craftbukkit.inventory.components;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.world.food.FoodInfo;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.SerializableMeta;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.components.FoodComponent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
@SerializableAs("Food")
|
||||
public final class CraftFoodComponent implements FoodComponent {
|
||||
@@ -36,23 +27,7 @@ public final class CraftFoodComponent implements FoodComponent {
|
||||
Float saturationModifier = SerializableMeta.getObject(Float.class, map, "saturation", false);
|
||||
Boolean canAlwaysEat = SerializableMeta.getBoolean(map, "can-always-eat");
|
||||
|
||||
Float eatSeconds = SerializableMeta.getObject(Float.class, map, "eat-seconds", true);
|
||||
if (eatSeconds == null) {
|
||||
eatSeconds = 1.6f;
|
||||
}
|
||||
|
||||
ItemStack usingConvertsTo = SerializableMeta.getObject(ItemStack.class, map, "using-converts-to", true);
|
||||
|
||||
ImmutableList.Builder<FoodEffect> effects = ImmutableList.builder();
|
||||
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, "effects", true);
|
||||
if (rawEffectList != null) {
|
||||
for (Object obj : rawEffectList) {
|
||||
Preconditions.checkArgument(obj instanceof FoodEffect, "Object (%s) in effect list is not valid", obj.getClass());
|
||||
effects.add(new CraftFoodEffect((FoodEffect) obj));
|
||||
}
|
||||
}
|
||||
|
||||
this.handle = new FoodInfo(nutrition, saturationModifier, canAlwaysEat, eatSeconds, Optional.ofNullable(usingConvertsTo).map(CraftItemStack::asNMSCopy), effects.build().stream().map(CraftFoodEffect::new).map(CraftFoodEffect::getHandle).toList());
|
||||
this.handle = new FoodInfo(nutrition, saturationModifier, canAlwaysEat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,14 +36,7 @@ public final class CraftFoodComponent implements FoodComponent {
|
||||
result.put("nutrition", getNutrition());
|
||||
result.put("saturation", getSaturation());
|
||||
result.put("can-always-eat", canAlwaysEat());
|
||||
result.put("eat-seconds", getEatSeconds());
|
||||
|
||||
ItemStack usingConvertsTo = getUsingConvertsTo();
|
||||
if (usingConvertsTo != null) {
|
||||
result.put("using-converts-to", usingConvertsTo);
|
||||
}
|
||||
|
||||
result.put("effects", getEffects());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -84,7 +52,7 @@ public final class CraftFoodComponent implements FoodComponent {
|
||||
@Override
|
||||
public void setNutrition(int nutrition) {
|
||||
Preconditions.checkArgument(nutrition >= 0, "Nutrition cannot be negative");
|
||||
handle = new FoodInfo(nutrition, handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), handle.effects());
|
||||
handle = new FoodInfo(nutrition, handle.saturation(), handle.canAlwaysEat());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,7 +62,7 @@ public final class CraftFoodComponent implements FoodComponent {
|
||||
|
||||
@Override
|
||||
public void setSaturation(float saturation) {
|
||||
handle = new FoodInfo(handle.nutrition(), saturation, handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), handle.effects());
|
||||
handle = new FoodInfo(handle.nutrition(), saturation, handle.canAlwaysEat());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,49 +72,7 @@ public final class CraftFoodComponent implements FoodComponent {
|
||||
|
||||
@Override
|
||||
public void setCanAlwaysEat(boolean canAlwaysEat) {
|
||||
handle = new FoodInfo(handle.nutrition(), handle.saturation(), canAlwaysEat, handle.eatSeconds(), handle.usingConvertsTo(), handle.effects());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEatSeconds() {
|
||||
return handle.eatSeconds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEatSeconds(float eatSeconds) {
|
||||
handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), eatSeconds, handle.usingConvertsTo(), handle.effects());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getUsingConvertsTo() {
|
||||
return handle.usingConvertsTo().map(CraftItemStack::asBukkitCopy).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsingConvertsTo(ItemStack item) {
|
||||
handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), Optional.ofNullable(item).map(CraftItemStack::asNMSCopy), handle.effects());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FoodEffect> getEffects() {
|
||||
return handle.effects().stream().map(CraftFoodEffect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEffects(List<FoodEffect> effects) {
|
||||
handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), effects.stream().map(CraftFoodEffect::new).map(CraftFoodEffect::getHandle).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FoodEffect addEffect(PotionEffect effect, float probability) {
|
||||
List<FoodInfo.b> effects = new ArrayList<>(handle.effects());
|
||||
|
||||
FoodInfo.b newEffect = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(effect), probability);
|
||||
effects.add(newEffect);
|
||||
|
||||
handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), effects);
|
||||
|
||||
return new CraftFoodEffect(newEffect);
|
||||
handle = new FoodInfo(handle.nutrition(), handle.saturation(), canAlwaysEat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,89 +101,4 @@ public final class CraftFoodComponent implements FoodComponent {
|
||||
public String toString() {
|
||||
return "CraftFoodComponent{" + "handle=" + handle + '}';
|
||||
}
|
||||
|
||||
@SerializableAs("FoodEffect")
|
||||
public static class CraftFoodEffect implements FoodEffect {
|
||||
|
||||
private FoodInfo.b handle;
|
||||
|
||||
public CraftFoodEffect(FoodInfo.b handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
public CraftFoodEffect(FoodEffect bukkit) {
|
||||
this.handle = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(bukkit.getEffect()), bukkit.getProbability());
|
||||
}
|
||||
|
||||
public CraftFoodEffect(Map<String, Object> map) {
|
||||
PotionEffect effect = SerializableMeta.getObject(PotionEffect.class, map, "effect", false);
|
||||
|
||||
Float probability = SerializableMeta.getObject(Float.class, map, "probability", true);
|
||||
if (probability == null) {
|
||||
probability = 1.0f;
|
||||
}
|
||||
|
||||
this.handle = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(effect), probability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("effect", getEffect());
|
||||
result.put("probability", getProbability());
|
||||
return result;
|
||||
}
|
||||
|
||||
public FoodInfo.b getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffect getEffect() {
|
||||
return CraftPotionUtil.toBukkit(handle.effect());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEffect(PotionEffect effect) {
|
||||
handle = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(effect), handle.probability());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProbability() {
|
||||
return handle.probability();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProbability(float probability) {
|
||||
Preconditions.checkArgument(0 <= probability && probability <= 1, "Probability cannot be outside range [0,1]");
|
||||
handle = new net.minecraft.world.food.FoodInfo.b(handle.effect(), probability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 97 * hash + Objects.hashCode(this.handle);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CraftFoodEffect other = (CraftFoodEffect) obj;
|
||||
return Objects.equals(this.handle, other.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftFoodEffect{" + "handle=" + handle + '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.bukkit.craftbukkit.inventory.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
||||
final class CraftHolderUtil {
|
||||
|
||||
private CraftHolderUtil() {
|
||||
}
|
||||
|
||||
public static void serialize(Map<String, Object> result, String key, HolderSet<?> handle) {
|
||||
handle.unwrap()
|
||||
.ifLeft(tag -> result.put(key, "#" + tag.location().toString())) // Tag
|
||||
.ifRight(list -> result.put(key, list.stream().map((entry) -> entry.unwrapKey().orElseThrow().location().toString()).toList())); // List
|
||||
}
|
||||
|
||||
public static <T> HolderSet<T> parse(Object parseObject, ResourceKey<IRegistry<T>> registryKey, IRegistry<T> registry) {
|
||||
HolderSet<T> holderSet = null;
|
||||
|
||||
if (parseObject instanceof String parseString && parseString.startsWith("#")) { // Tag
|
||||
parseString = parseString.substring(1);
|
||||
MinecraftKey key = MinecraftKey.tryParse(parseString);
|
||||
if (key != null) {
|
||||
holderSet = registry.get(TagKey.create(registryKey, key)).orElse(null);
|
||||
}
|
||||
} else if (parseObject instanceof List parseList) { // List
|
||||
List<Holder.c<T>> holderList = new ArrayList<>(parseList.size());
|
||||
|
||||
for (Object entry : parseList) {
|
||||
MinecraftKey key = MinecraftKey.tryParse(entry.toString());
|
||||
if (key == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registry.get(key).ifPresent(holderList::add);
|
||||
}
|
||||
|
||||
holderSet = HolderSet.direct(holderList);
|
||||
} else {
|
||||
throw new IllegalArgumentException("(" + parseObject + ") is not a valid String or List");
|
||||
}
|
||||
|
||||
if (holderSet == null) {
|
||||
holderSet = HolderSet.empty();
|
||||
}
|
||||
|
||||
return holderSet;
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,6 @@ import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.component.Tool;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.bukkit.Material;
|
||||
@@ -197,35 +195,7 @@ public final class CraftToolComponent implements ToolComponent {
|
||||
public CraftToolRule(Map<String, Object> map) {
|
||||
Float speed = SerializableMeta.getObject(Float.class, map, "speed", true);
|
||||
Boolean correct = SerializableMeta.getObject(Boolean.class, map, "correct-for-drops", true);
|
||||
|
||||
HolderSet<Block> blocks = null;
|
||||
Object blocksObject = SerializableMeta.getObject(Object.class, map, "blocks", false);
|
||||
if (blocksObject instanceof String blocksString && blocksString.startsWith("#")) { // Tag
|
||||
blocksString = blocksString.substring(1);
|
||||
MinecraftKey key = MinecraftKey.tryParse(blocksString);
|
||||
if (key != null) {
|
||||
blocks = BuiltInRegistries.BLOCK.getTag(TagKey.create(Registries.BLOCK, key)).orElse(null);
|
||||
}
|
||||
} else if (blocksObject instanceof List blocksList) { // List of blocks
|
||||
List<Holder.c<Block>> blockHolders = new ArrayList<>(blocksList.size());
|
||||
|
||||
for (Object entry : blocksList) {
|
||||
MinecraftKey key = MinecraftKey.tryParse(entry.toString());
|
||||
if (key == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BuiltInRegistries.BLOCK.getHolder(key).ifPresent(blockHolders::add);
|
||||
}
|
||||
|
||||
blocks = HolderSet.direct(blockHolders);
|
||||
} else {
|
||||
throw new IllegalArgumentException("blocks" + "(" + blocksObject + ") is not a valid String or List");
|
||||
}
|
||||
|
||||
if (blocks == null) {
|
||||
blocks = HolderSet.empty();
|
||||
}
|
||||
HolderSet<Block> blocks = CraftHolderUtil.parse(SerializableMeta.getObject(Object.class, map, "blocks", false), Registries.BLOCK, BuiltInRegistries.BLOCK);
|
||||
|
||||
this.handle = new Tool.a(blocks, Optional.ofNullable(speed), Optional.ofNullable(correct));
|
||||
}
|
||||
@@ -234,9 +204,7 @@ public final class CraftToolComponent implements ToolComponent {
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
handle.blocks().unwrap()
|
||||
.ifLeft(key -> result.put("blocks", "#" + key.location().toString())) // Tag
|
||||
.ifRight(blocks -> result.put("blocks", blocks.stream().map((block) -> block.unwrapKey().orElseThrow().location().toString()).toList())); // List of blocks
|
||||
CraftHolderUtil.serialize(result, "blocks", handle.blocks());
|
||||
|
||||
Float speed = getSpeed();
|
||||
if (speed != null) {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.bukkit.craftbukkit.inventory.components;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.world.item.component.UseCooldown;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.craftbukkit.inventory.SerializableMeta;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.meta.components.UseCooldownComponent;
|
||||
|
||||
@SerializableAs("UseCooldown")
|
||||
public final class CraftUseCooldownComponent implements UseCooldownComponent {
|
||||
|
||||
private UseCooldown handle;
|
||||
|
||||
public CraftUseCooldownComponent(UseCooldown cooldown) {
|
||||
this.handle = cooldown;
|
||||
}
|
||||
|
||||
public CraftUseCooldownComponent(CraftUseCooldownComponent food) {
|
||||
this.handle = food.handle;
|
||||
}
|
||||
|
||||
public CraftUseCooldownComponent(Map<String, Object> map) {
|
||||
Float seconds = SerializableMeta.getObject(Float.class, map, "seconds", false);
|
||||
String cooldownGroup = SerializableMeta.getString(map, "cooldown-group", true);
|
||||
|
||||
this.handle = new UseCooldown(seconds, Optional.ofNullable(cooldownGroup).map(MinecraftKey::parse));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("seconds", getCooldownSeconds());
|
||||
if (getCooldownGroup() != null) {
|
||||
result.put("cooldown-group", getCooldownGroup());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public UseCooldown getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCooldownSeconds() {
|
||||
return handle.seconds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCooldownSeconds(float eatSeconds) {
|
||||
Preconditions.checkArgument(eatSeconds >= 0, "eatSeconds cannot be less than 0");
|
||||
|
||||
handle = new UseCooldown(eatSeconds, handle.cooldownGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getCooldownGroup() {
|
||||
return handle.cooldownGroup().map(CraftNamespacedKey::fromMinecraft).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCooldownGroup(NamespacedKey song) {
|
||||
handle = new UseCooldown(handle.seconds(), Optional.ofNullable(song).map(CraftNamespacedKey::toMinecraft));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 73 * hash + Objects.hashCode(this.handle);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CraftUseCooldownComponent other = (CraftUseCooldownComponent) obj;
|
||||
return Objects.equals(this.handle, other.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftUseCooldownComponent{" + "handle=" + handle + '}';
|
||||
}
|
||||
}
|
||||
@@ -12,26 +12,26 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft.world.item.armortrim.TrimMaterial> {
|
||||
public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft.world.item.equipment.trim.TrimMaterial> {
|
||||
|
||||
public static TrimMaterial minecraftToBukkit(net.minecraft.world.item.armortrim.TrimMaterial minecraft) {
|
||||
public static TrimMaterial minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimMaterial minecraft) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_MATERIAL, Registry.TRIM_MATERIAL);
|
||||
}
|
||||
|
||||
public static TrimMaterial minecraftHolderToBukkit(Holder<net.minecraft.world.item.armortrim.TrimMaterial> minecraft) {
|
||||
public static TrimMaterial minecraftHolderToBukkit(Holder<net.minecraft.world.item.equipment.trim.TrimMaterial> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.world.item.armortrim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) {
|
||||
public static net.minecraft.world.item.equipment.trim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||
}
|
||||
|
||||
public static Holder<net.minecraft.world.item.armortrim.TrimMaterial> bukkitToMinecraftHolder(TrimMaterial bukkit) {
|
||||
public static Holder<net.minecraft.world.item.equipment.trim.TrimMaterial> bukkitToMinecraftHolder(TrimMaterial bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<net.minecraft.world.item.armortrim.TrimMaterial> registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_MATERIAL);
|
||||
IRegistry<net.minecraft.world.item.equipment.trim.TrimMaterial> registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_MATERIAL);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<net.minecraft.world.item.armortrim.TrimMaterial> holder) {
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<net.minecraft.world.item.equipment.trim.TrimMaterial> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final net.minecraft.world.item.armortrim.TrimMaterial handle;
|
||||
private final net.minecraft.world.item.equipment.trim.TrimMaterial handle;
|
||||
|
||||
public CraftTrimMaterial(NamespacedKey key, net.minecraft.world.item.armortrim.TrimMaterial handle) {
|
||||
public CraftTrimMaterial(NamespacedKey key, net.minecraft.world.item.equipment.trim.TrimMaterial handle) {
|
||||
this.key = key;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.world.item.armortrim.TrimMaterial getHandle() {
|
||||
public net.minecraft.world.item.equipment.trim.TrimMaterial getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,26 +12,26 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.world.item.armortrim.TrimPattern> {
|
||||
public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.world.item.equipment.trim.TrimPattern> {
|
||||
|
||||
public static TrimPattern minecraftToBukkit(net.minecraft.world.item.armortrim.TrimPattern minecraft) {
|
||||
public static TrimPattern minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimPattern minecraft) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_PATTERN, Registry.TRIM_PATTERN);
|
||||
}
|
||||
|
||||
public static TrimPattern minecraftHolderToBukkit(Holder<net.minecraft.world.item.armortrim.TrimPattern> minecraft) {
|
||||
public static TrimPattern minecraftHolderToBukkit(Holder<net.minecraft.world.item.equipment.trim.TrimPattern> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.world.item.armortrim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) {
|
||||
public static net.minecraft.world.item.equipment.trim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||
}
|
||||
|
||||
public static Holder<net.minecraft.world.item.armortrim.TrimPattern> bukkitToMinecraftHolder(TrimPattern bukkit) {
|
||||
public static Holder<net.minecraft.world.item.equipment.trim.TrimPattern> bukkitToMinecraftHolder(TrimPattern bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<net.minecraft.world.item.armortrim.TrimPattern> registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_PATTERN);
|
||||
IRegistry<net.minecraft.world.item.equipment.trim.TrimPattern> registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_PATTERN);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<net.minecraft.world.item.armortrim.TrimPattern> holder) {
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<net.minecraft.world.item.equipment.trim.TrimPattern> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.w
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final net.minecraft.world.item.armortrim.TrimPattern handle;
|
||||
private final net.minecraft.world.item.equipment.trim.TrimPattern handle;
|
||||
|
||||
public CraftTrimPattern(NamespacedKey key, net.minecraft.world.item.armortrim.TrimPattern handle) {
|
||||
public CraftTrimPattern(NamespacedKey key, net.minecraft.world.item.equipment.trim.TrimPattern handle) {
|
||||
this.key = key;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.world.item.armortrim.TrimPattern getHandle() {
|
||||
public net.minecraft.world.item.equipment.trim.TrimPattern getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user