Update to Minecraft 1.20.5

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-04-24 01:15:00 +10:00
parent 4deda9501f
commit 65bc2541a3
524 changed files with 7788 additions and 6181 deletions

View File

@@ -51,7 +51,7 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac
@Override
public double getJumpStrength() {
return getHandle().getCustomJump();
return getHandle().getAttributeValue(GenericAttributes.JUMP_STRENGTH);
}
@Override

View File

@@ -0,0 +1,27 @@
package org.bukkit.craftbukkit.entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.AbstractWindCharge;
import org.bukkit.event.entity.EntityRemoveEvent;
public abstract class CraftAbstractWindCharge extends CraftFireball implements AbstractWindCharge {
public CraftAbstractWindCharge(CraftServer server, net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge entity) {
super(server, entity);
}
@Override
public void explode() {
this.getHandle().explode();
this.getHandle().discard(EntityRemoveEvent.Cause.EXPLODE); // SPIGOT-7577 - explode doesn't discard the entity, this happens only in tick and onHitBlock
}
@Override
public net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge getHandle() {
return (net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge) this.entity;
}
@Override
public String toString() {
return "CraftAbstractWindCharge";
}
}

View File

@@ -3,10 +3,13 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.EntityAreaEffectCloud;
import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.item.alchemy.PotionContents;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.craftbukkit.CraftParticle;
@@ -16,12 +19,10 @@ import org.bukkit.craftbukkit.potion.CraftPotionType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud {
@@ -131,28 +132,22 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public Color getColor() {
return Color.fromRGB(getHandle().getColor());
return Color.fromRGB(getHandle().potionContents.getColor());
}
@Override
public void setColor(Color color) {
getHandle().setFixedColor(color.asRGB());
PotionContents old = getHandle().potionContents;
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(color.asRGB()), old.customEffects()));
}
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
if (existing != null) {
if (hasCustomEffect(effect.getType())) {
if (!override) {
return false;
}
getHandle().effects.remove(existing);
removeCustomEffect(effect.getType());
}
getHandle().addEffect(CraftPotionUtil.fromBukkit(effect));
getHandle().updateColor();
@@ -161,14 +156,15 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public void clearCustomEffects() {
getHandle().effects.clear();
PotionContents old = getHandle().potionContents;
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of()));
getHandle().updateColor();
}
@Override
public List<PotionEffect> getCustomEffects() {
ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
for (MobEffect effect : getHandle().effects) {
for (MobEffect effect : getHandle().potionContents.customEffects()) {
builder.add(CraftPotionUtil.toBukkit(effect));
}
return builder.build();
@@ -176,7 +172,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public boolean hasCustomEffect(PotionEffectType type) {
for (MobEffect effect : getHandle().effects) {
for (MobEffect effect : getHandle().potionContents.customEffects()) {
if (CraftPotionUtil.equals(effect.getEffect(), type)) {
return true;
}
@@ -186,50 +182,34 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public boolean hasCustomEffects() {
return !getHandle().effects.isEmpty();
return !getHandle().potionContents.customEffects().isEmpty();
}
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect);
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
if (existing == null) {
if (!hasCustomEffect(effect)) {
return false;
}
getHandle().effects.remove(existing);
getHandle().updateColor();
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()));
return true;
}
@Override
public void setBasePotionData(PotionData data) {
Preconditions.checkArgument(data != null, "PotionData cannot be null");
getHandle().setPotion(CraftPotionType.bukkitToMinecraft(CraftPotionUtil.fromBukkit(data)));
public void setBasePotionType(PotionType potionType) {
if (potionType != null) {
getHandle().setPotionContents(getHandle().potionContents.withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType)));
} else {
PotionContents old = getHandle().potionContents;
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects()));
}
}
@Override
public PotionData getBasePotionData() {
return CraftPotionUtil.toBukkit(CraftPotionType.minecraftToBukkit(getHandle().getPotion()));
}
@Override
public void setBasePotionType(@NotNull PotionType potionType) {
// TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message
Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead.");
getHandle().setPotion(CraftPotionType.bukkitToMinecraft(potionType));
}
@NotNull
@Override
public PotionType getBasePotionType() {
return CraftPotionType.minecraftToBukkit(getHandle().getPotion());
return getHandle().potionContents.potion().map(CraftPotionType::minecraftHolderToBukkit).orElse(null);
}
@Override

View File

@@ -0,0 +1,21 @@
package org.bukkit.craftbukkit.entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Armadillo;
public class CraftArmadillo extends CraftAnimals implements Armadillo {
public CraftArmadillo(CraftServer server, net.minecraft.world.entity.animal.armadillo.Armadillo entity) {
super(server, entity);
}
@Override
public net.minecraft.world.entity.animal.armadillo.Armadillo getHandle() {
return (net.minecraft.world.entity.animal.armadillo.Armadillo) super.getHandle();
}
@Override
public String toString() {
return "CraftArmadillo";
}
}

View File

@@ -0,0 +1,27 @@
package org.bukkit.craftbukkit.entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Bogged;
import org.bukkit.entity.Skeleton;
public class CraftBogged extends CraftAbstractSkeleton implements Bogged {
public CraftBogged(CraftServer server, net.minecraft.world.entity.monster.Bogged entity) {
super(server, entity);
}
@Override
public net.minecraft.world.entity.monster.Bogged getHandle() {
return (net.minecraft.world.entity.monster.Bogged) entity;
}
@Override
public String toString() {
return "CraftBogged";
}
@Override
public Skeleton.SkeletonType getSkeletonType() {
return Skeleton.SkeletonType.BOGGED;
}
}

View File

@@ -0,0 +1,20 @@
package org.bukkit.craftbukkit.entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.BreezeWindCharge;
public class CraftBreezeWindCharge extends CraftAbstractWindCharge implements BreezeWindCharge {
public CraftBreezeWindCharge(CraftServer server, net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge entity) {
super(server, entity);
}
@Override
public net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge getHandle() {
return (net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge) this.entity;
}
@Override
public String toString() {
return "CraftBreezeWindCharge";
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.CatVariant;
@@ -31,14 +32,14 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
@Override
public Type getCatType() {
return CraftType.minecraftToBukkit(getHandle().getVariant());
return CraftType.minecraftHolderToBukkit(getHandle().getVariant());
}
@Override
public void setCatType(Type type) {
Preconditions.checkArgument(type != null, "Cannot have null Type");
getHandle().setVariant(CraftType.bukkitToMinecraft(type));
getHandle().setVariant(CraftType.bukkitToMinecraftHolder(type));
}
@Override
@@ -61,6 +62,10 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
return Registry.CAT_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getKey(minecraft)));
}
public static Type minecraftHolderToBukkit(Holder<CatVariant> minecraft) {
return minecraftToBukkit(minecraft.value());
}
public static CatVariant bukkitToMinecraft(Type bukkit) {
Preconditions.checkArgument(bukkit != null);
@@ -68,5 +73,18 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
return registry.get(CraftNamespacedKey.toMinecraft(bukkit.getKey()));
}
public static Holder<CatVariant> bukkitToMinecraftHolder(Type bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<CatVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<CatVariant> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own cat variant with out properly registering it.");
}
}
}

View File

@@ -1,12 +1,9 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.entity.vehicle.ChestBoat;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftLootTable;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.Inventory;
import org.bukkit.loot.LootTable;
@@ -41,13 +38,7 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest
@Override
public LootTable getLootTable() {
MinecraftKey nmsTable = getHandle().getLootTable();
if (nmsTable == null) {
return null; // return empty loot table?
}
NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable);
return Bukkit.getLootTable(key);
return CraftLootTable.minecraftToBukkit(getHandle().getLootTable());
}
@Override
@@ -61,8 +52,7 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest
}
private void setLootTable(LootTable table, long seed) {
MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
getHandle().setLootTable(newKey);
getHandle().setLootTable(CraftLootTable.bukkitToMinecraft(table));
getHandle().setLootTableSeed(seed);
}
}

View File

@@ -50,6 +50,7 @@ import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Allay;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Armadillo;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Axolotl;
@@ -58,7 +59,9 @@ 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;
@@ -115,6 +118,7 @@ import org.bukkit.entity.Marker;
import org.bukkit.entity.Mule;
import org.bukkit.entity.MushroomCow;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.OminousItemSpawner;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Panda;
import org.bukkit.entity.Parrot;
@@ -223,7 +227,7 @@ public final class CraftEntityTypes {
private static final BiConsumer<SpawnData, net.minecraft.world.entity.Entity> MOVE_EMPTY_ROT = (spawnData, entity) -> entity.moveTo(spawnData.x(), spawnData.y(), spawnData.z(), 0, 0);
private static final BiConsumer<SpawnData, EntityFireball> DIRECTION = (spawnData, entity) -> {
Vector direction = spawnData.location().getDirection().multiply(10);
entity.setDirection(direction.getX(), direction.getY(), direction.getZ());
entity.assignPower(direction.getX(), direction.getY(), direction.getZ());
};
private static final Map<Class<?>, EntityTypeData<?, ?>> CLASS_TYPE_DATA = new HashMap<>();
private static final Map<EntityType, EntityTypeData<?, ?>> ENTITY_TYPE_DATA = new HashMap<>();
@@ -233,6 +237,7 @@ public final class CraftEntityTypes {
register(new EntityTypeData<>(EntityType.ELDER_GUARDIAN, ElderGuardian.class, CraftElderGuardian::new, createLiving(EntityTypes.ELDER_GUARDIAN)));
register(new EntityTypeData<>(EntityType.WITHER_SKELETON, WitherSkeleton.class, CraftWitherSkeleton::new, createLiving(EntityTypes.WITHER_SKELETON)));
register(new EntityTypeData<>(EntityType.STRAY, Stray.class, CraftStray::new, createLiving(EntityTypes.STRAY)));
register(new EntityTypeData<>(EntityType.BOGGED, Bogged.class, CraftBogged::new, createLiving(EntityTypes.BOGGED)));
register(new EntityTypeData<>(EntityType.HUSK, Husk.class, CraftHusk::new, createLiving(EntityTypes.HUSK)));
register(new EntityTypeData<>(EntityType.ZOMBIE_VILLAGER, ZombieVillager.class, CraftVillagerZombie::new, createLiving(EntityTypes.ZOMBIE_VILLAGER)));
register(new EntityTypeData<>(EntityType.SKELETON_HORSE, SkeletonHorse.class, CraftSkeletonHorse::new, createLiving(EntityTypes.SKELETON_HORSE)));
@@ -310,6 +315,7 @@ public final class CraftEntityTypes {
register(new EntityTypeData<>(EntityType.CAMEL, Camel.class, CraftCamel::new, createLiving(EntityTypes.CAMEL)));
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)));
Function<SpawnData, EntityEnderDragon> dragonFunction = createLiving(EntityTypes.ENDER_DRAGON);
register(new EntityTypeData<>(EntityType.ENDER_DRAGON, EnderDragon.class, CraftEnderDragon::new, spawnData -> {
@@ -323,6 +329,7 @@ public final class CraftEntityTypes {
register(new EntityTypeData<>(EntityType.WITHER_SKULL, WitherSkull.class, CraftWitherSkull::new, createFireball(EntityTypes.WITHER_SKULL)));
register(new EntityTypeData<>(EntityType.DRAGON_FIREBALL, DragonFireball.class, CraftDragonFireball::new, createFireball(EntityTypes.DRAGON_FIREBALL)));
register(new EntityTypeData<>(EntityType.WIND_CHARGE, WindCharge.class, CraftWindCharge::new, createFireball(EntityTypes.WIND_CHARGE)));
register(new EntityTypeData<>(EntityType.BREEZE_WIND_CHARGE, BreezeWindCharge.class, CraftBreezeWindCharge::new, createFireball(EntityTypes.BREEZE_WIND_CHARGE)));
// Hanging
register(new EntityTypeData<>(EntityType.PAINTING, Painting.class, CraftPainting::new, createHanging(Painting.class, (spawnData, hangingData) -> {
@@ -353,6 +360,7 @@ public final class CraftEntityTypes {
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)));
// Set pos
register(new EntityTypeData<>(EntityType.MARKER, Marker.class, CraftMarker::new, createAndSetPos(EntityTypes.MARKER)));

View File

@@ -55,7 +55,7 @@ public class CraftFireball extends AbstractProjectile implements Fireball {
@Override
public void setDirection(Vector direction) {
Preconditions.checkArgument(direction != null, "Vector direction cannot be null");
getHandle().setDirection(direction.getX(), direction.getY(), direction.getZ());
getHandle().assignPower(direction.getX(), direction.getY(), direction.getZ());
update(); // SPIGOT-6579
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.FrogVariant;
@@ -43,14 +44,14 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
@Override
public Variant getVariant() {
return CraftVariant.minecraftToBukkit(getHandle().getVariant());
return CraftVariant.minecraftHolderToBukkit(getHandle().getVariant());
}
@Override
public void setVariant(Variant variant) {
Preconditions.checkArgument(variant != null, "variant");
getHandle().setVariant(CraftVariant.bukkitToMinecraft(variant));
getHandle().setVariant(CraftVariant.bukkitToMinecraftHolder(variant));
}
public static class CraftVariant {
@@ -66,11 +67,28 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
return bukkit;
}
public static Variant minecraftHolderToBukkit(Holder<FrogVariant> minecraft) {
return minecraftToBukkit(minecraft.value());
}
public static FrogVariant bukkitToMinecraft(Variant bukkit) {
Preconditions.checkArgument(bukkit != null);
return CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT)
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
}
public static Holder<FrogVariant> bukkitToMinecraftHolder(Variant bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<FrogVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<FrogVariant> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own frog variant with out properly registering it.");
}
}
}

View File

@@ -26,8 +26,6 @@ import net.minecraft.world.item.crafting.CraftingManager;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.trading.IMerchant;
import net.minecraft.world.level.block.BlockBed;
import net.minecraft.world.level.block.BlockEnchantmentTable;
import net.minecraft.world.level.block.BlockWorkbench;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.state.IBlockData;
@@ -342,7 +340,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
return null;
}
}
getHandle().openMenu(((BlockWorkbench) Blocks.CRAFTING_TABLE).getMenuProvider(null, getHandle().level(), CraftLocation.toBlockPosition(location)));
getHandle().openMenu(Blocks.CRAFTING_TABLE.defaultBlockState().getMenuProvider(getHandle().level(), CraftLocation.toBlockPosition(location)));
if (force) {
getHandle().containerMenu.checkReachable = false;
}
@@ -363,7 +361,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
// If there isn't an enchant table we can force create one, won't be very useful though.
BlockPosition pos = CraftLocation.toBlockPosition(location);
getHandle().openMenu(((BlockEnchantmentTable) Blocks.ENCHANTING_TABLE).getMenuProvider(null, getHandle().level(), pos));
getHandle().openMenu(Blocks.ENCHANTING_TABLE.defaultBlockState().getMenuProvider(getHandle().level(), pos));
if (force) {
getHandle().containerMenu.checkReachable = false;

View File

@@ -17,7 +17,6 @@ import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.EntityInsentient;
import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.EnumMonsterType;
import net.minecraft.world.entity.ai.attributes.GenericAttributes;
import net.minecraft.world.entity.boss.wither.EntityWither;
import net.minecraft.world.entity.decoration.EntityArmorStand;
@@ -159,7 +158,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public void resetMaxHealth() {
setMaxHealth(getHandle().getAttribute(GenericAttributes.MAX_HEALTH).getAttribute().getDefaultValue());
setMaxHealth(getHandle().getAttribute(GenericAttributes.MAX_HEALTH).getAttribute().value().getDefaultValue());
}
@Override
@@ -401,7 +400,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public boolean addPotionEffect(PotionEffect effect, boolean force) {
getHandle().addEffect(new MobEffect(CraftPotionEffectType.bukkitToMinecraft(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
getHandle().addEffect(new MobEffect(CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
return true;
}
@@ -416,25 +415,25 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public boolean hasPotionEffect(PotionEffectType type) {
return getHandle().hasEffect(CraftPotionEffectType.bukkitToMinecraft(type));
return getHandle().hasEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type));
}
@Override
public PotionEffect getPotionEffect(PotionEffectType type) {
MobEffect handle = getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraft(type));
return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
MobEffect handle = getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type));
return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftHolderToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
}
@Override
public void removePotionEffect(PotionEffectType type) {
getHandle().removeEffect(CraftPotionEffectType.bukkitToMinecraft(type), EntityPotionEffectEvent.Cause.PLUGIN);
getHandle().removeEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type), EntityPotionEffectEvent.Cause.PLUGIN);
}
@Override
public Collection<PotionEffect> getActivePotionEffects() {
List<PotionEffect> effects = new ArrayList<PotionEffect>();
for (MobEffect handle : getHandle().activeEffects.values()) {
effects.add(new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
effects.add(new PotionEffect(CraftPotionEffectType.minecraftHolderToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
}
return effects;
}
@@ -499,8 +498,8 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
launch = new EntityDragonFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else if (WindCharge.class.isAssignableFrom(projectile)) {
launch = EntityTypes.WIND_CHARGE.create(world);
((net.minecraft.world.entity.projectile.WindCharge) launch).setOwner(getHandle());
((net.minecraft.world.entity.projectile.WindCharge) launch).setDirection(direction.getX(), direction.getY(), direction.getZ());
((net.minecraft.world.entity.projectile.windcharge.WindCharge) launch).setOwner(getHandle());
((net.minecraft.world.entity.projectile.windcharge.WindCharge) launch).assignPower(direction.getX(), direction.getY(), direction.getZ());
} else {
launch = new EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ(), 1);
}
@@ -795,21 +794,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public EntityCategory getCategory() {
EnumMonsterType type = getHandle().getMobType(); // Not actually an enum?
if (type == EnumMonsterType.UNDEFINED) {
return EntityCategory.NONE;
} else if (type == EnumMonsterType.UNDEAD) {
return EntityCategory.UNDEAD;
} else if (type == EnumMonsterType.ARTHROPOD) {
return EntityCategory.ARTHROPOD;
} else if (type == EnumMonsterType.ILLAGER) {
return EntityCategory.ILLAGER;
} else if (type == EnumMonsterType.WATER) {
return EntityCategory.WATER;
}
throw new UnsupportedOperationException("Unsupported monster type: " + type + ". This is a bug, report this to Spigot.");
throw new UnsupportedOperationException("Method longer applicable. Use Tags instead.");
}
@Override

View File

@@ -38,7 +38,7 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca
@Override
public void setName(String name) {
getHandle().getCommandBlock().setName(CraftChatMessage.fromStringOrNull(name));
getHandle().getCommandBlock().setCustomName(CraftChatMessage.fromStringOrNull(name));
}
@Override

View File

@@ -1,12 +1,9 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.entity.vehicle.EntityMinecartAbstract;
import net.minecraft.world.entity.vehicle.EntityMinecartContainer;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftLootTable;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.loot.LootTable;
import org.bukkit.loot.Lootable;
@@ -28,13 +25,7 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo
@Override
public LootTable getLootTable() {
MinecraftKey nmsTable = getHandle().lootTable;
if (nmsTable == null) {
return null; // return empty loot table?
}
NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable);
return Bukkit.getLootTable(key);
return CraftLootTable.minecraftToBukkit(getHandle().lootTable);
}
@Override
@@ -48,7 +39,6 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo
}
private void setLootTable(LootTable table, long seed) {
MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
getHandle().setLootTable(newKey, seed);
getHandle().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed);
}
}

View File

@@ -3,12 +3,10 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import net.minecraft.sounds.SoundEffect;
import net.minecraft.world.entity.EntityInsentient;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftLootTable;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.loot.LootTable;
@@ -65,13 +63,12 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
@Override
public void setLootTable(LootTable table) {
getHandle().lootTable = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
getHandle().lootTable = CraftLootTable.bukkitToMinecraft(table);
}
@Override
public LootTable getLootTable() {
NamespacedKey key = CraftNamespacedKey.fromMinecraft(getHandle().getLootTable());
return Bukkit.getLootTable(key);
return CraftLootTable.minecraftToBukkit(getHandle().getLootTable());
}
@Override

View File

@@ -2,12 +2,12 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.animal.EntityMushroomCow;
import net.minecraft.world.level.block.SuspiciousEffectHolder;
import net.minecraft.world.item.component.SuspiciousStewEffects;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
@@ -22,13 +22,15 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow {
@Override
public boolean hasEffectsForNextStew() {
return this.getHandle().stewEffects != null && !this.getHandle().stewEffects.isEmpty();
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
return stewEffects != null && !stewEffects.effects().isEmpty();
}
@Override
public List<PotionEffect> getEffectsForNextStew() {
if (this.hasEffectsForNextStew()) {
return this.getHandle().stewEffects.stream().map(recordSuspiciousEffect -> CraftPotionUtil.toBukkit(recordSuspiciousEffect.createEffectInstance())).toList();
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
if (stewEffects != null) {
return stewEffects.effects().stream().map(recordSuspiciousEffect -> CraftPotionUtil.toBukkit(recordSuspiciousEffect.createEffectInstance())).toList();
}
return ImmutableList.of();
}
@@ -40,32 +42,42 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow {
if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) {
return false;
}
if (this.getHandle().stewEffects == null) {
this.getHandle().stewEffects = new ArrayList<>();
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
if (stewEffects == null) {
stewEffects = SuspiciousStewEffects.EMPTY;
}
SuspiciousEffectHolder.a recordSuspiciousEffect = new SuspiciousEffectHolder.a(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration());
SuspiciousStewEffects.a recordSuspiciousEffect = new SuspiciousStewEffects.a(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration());
this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects
return this.getHandle().stewEffects.add(recordSuspiciousEffect);
getHandle().stewEffects = stewEffects.withEffectAdded(recordSuspiciousEffect);
return true;
}
@Override
public boolean removeEffectFromNextStew(PotionEffectType potionEffectType) {
Preconditions.checkArgument(potionEffectType != null, "potionEffectType cannot be null");
if (!this.hasEffectsForNextStew()) {
if (!hasEffectForNextStew(potionEffectType)) {
return false;
}
MobEffectList minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType);
return this.getHandle().stewEffects.removeIf(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType));
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
if (stewEffects == null) {
return false;
}
Holder<MobEffectList> minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraftHolder(potionEffectType);
getHandle().stewEffects = new SuspiciousStewEffects(stewEffects.effects().stream().filter((effect) -> !effect.effect().equals(minecraftPotionEffectType)).toList());
return true;
}
@Override
public boolean hasEffectForNextStew(PotionEffectType potionEffectType) {
Preconditions.checkArgument(potionEffectType != null, "potionEffectType cannot be null");
if (!this.hasEffectsForNextStew()) {
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
if (stewEffects == null) {
return false;
}
MobEffectList minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType);
return this.getHandle().stewEffects.stream().anyMatch(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType));
Holder<MobEffectList> minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraftHolder(potionEffectType);
return stewEffects.effects().stream().anyMatch(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType));
}
@Override

View File

@@ -0,0 +1,43 @@
package org.bukkit.craftbukkit.entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.OminousItemSpawner;
import org.bukkit.inventory.ItemStack;
public class CraftOminousItemSpawner extends CraftEntity implements OminousItemSpawner {
public CraftOminousItemSpawner(CraftServer server, net.minecraft.world.entity.OminousItemSpawner entity) {
super(server, entity);
}
@Override
public net.minecraft.world.entity.OminousItemSpawner getHandle() {
return (net.minecraft.world.entity.OminousItemSpawner) entity;
}
@Override
public String toString() {
return "CraftOminousItemSpawner";
}
@Override
public ItemStack getItem() {
return CraftItemStack.asBukkitCopy(getHandle().getItem());
}
@Override
public void setItem(ItemStack item) {
getHandle().setItem(CraftItemStack.asNMSCopy(item));
}
@Override
public long getSpawnItemAfterTicks() {
return getHandle().spawnItemAfterTicks;
}
@Override
public void setSpawnItemAfterTicks(long ticks) {
getHandle().spawnItemAfterTicks = ticks;
}
}

View File

@@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.io.BaseEncoding;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.shorts.ShortArraySet;
import it.unimi.dsi.fastutil.shorts.ShortSet;
import java.io.ByteArrayOutputStream;
@@ -22,12 +23,15 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
@@ -36,13 +40,18 @@ import net.minecraft.core.BlockPosition;
import net.minecraft.core.Holder;
import net.minecraft.core.SectionPosition;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketDataSerializer;
import net.minecraft.network.EnumProtocol;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket;
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.common.ClientboundStoreCookiePacket;
import net.minecraft.network.protocol.common.ClientboundTransferPacket;
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
import net.minecraft.network.protocol.cookie.ClientboundCookieRequestPacket;
import net.minecraft.network.protocol.cookie.ServerboundCookieResponsePacket;
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
@@ -99,6 +108,7 @@ import net.minecraft.world.level.block.entity.TileEntitySign;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.border.IWorldBorderListener;
import net.minecraft.world.level.saveddata.maps.MapIcon;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.WorldMap;
import net.minecraft.world.phys.Vec3D;
import org.bukkit.BanEntry;
@@ -148,6 +158,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.map.CraftMapCursor;
import org.bukkit.craftbukkit.map.CraftMapView;
import org.bukkit.craftbukkit.map.RenderData;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
@@ -244,7 +255,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public InetSocketAddress getAddress() {
if (getHandle().connection == null) return null;
if (getHandle().connection.protocol() == null) return null;
SocketAddress addr = getHandle().connection.getRemoteAddress();
if (addr instanceof InetSocketAddress) {
@@ -254,6 +265,74 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
public interface TransferCookieConnection {
boolean isTransferred();
EnumProtocol protocol();
void send(Packet<?> packet);
}
public record CookieFuture(MinecraftKey key, CompletableFuture<byte[]> future) {
}
private final Queue<CookieFuture> requestedCookies = new LinkedList<>();
public boolean isAwaitingCookies() {
return !requestedCookies.isEmpty();
}
public boolean handleCookieResponse(ServerboundCookieResponsePacket response) {
CookieFuture future = requestedCookies.peek();
if (future != null) {
if (future.key.equals(response.key())) {
Preconditions.checkState(future == requestedCookies.poll(), "requestedCookies queue mismatch");
future.future().complete(response.payload());
return true;
}
}
return false;
}
@Override
public boolean isTransferred() {
return getHandle().transferCookieConnection.isTransferred();
}
@Override
public CompletableFuture<byte[]> retrieveCookie(NamespacedKey key) {
Preconditions.checkArgument(key != null, "Cookie key cannot be null");
CompletableFuture<byte[]> future = new CompletableFuture<>();
MinecraftKey nms = CraftNamespacedKey.toMinecraft(key);
requestedCookies.add(new CookieFuture(nms, future));
getHandle().transferCookieConnection.send(new ClientboundCookieRequestPacket(nms));
return future;
}
@Override
public void storeCookie(NamespacedKey key, byte[] value) {
Preconditions.checkArgument(key != null, "Cookie key cannot be null");
Preconditions.checkArgument(value != null, "Cookie value cannot be null");
Preconditions.checkArgument(value.length <= 5120, "Cookie value too large, must be smaller than 5120 bytes");
Preconditions.checkState(getHandle().transferCookieConnection.protocol() == EnumProtocol.CONFIGURATION || getHandle().transferCookieConnection.protocol() == EnumProtocol.PLAY, "Can only store cookie in CONFIGURATION or PLAY protocol.");
getHandle().transferCookieConnection.send(new ClientboundStoreCookiePacket(CraftNamespacedKey.toMinecraft(key), value));
}
@Override
public void transfer(String host, int port) {
Preconditions.checkArgument(host != null, "Host cannot be null");
Preconditions.checkState(getHandle().transferCookieConnection.protocol() == EnumProtocol.CONFIGURATION || getHandle().transferCookieConnection.protocol() == EnumProtocol.PLAY, "Can only transfer in CONFIGURATION or PLAY protocol.");
getHandle().transferCookieConnection.send(new ClientboundTransferPacket(host, port));
}
@Override
public double getEyeHeight(boolean ignorePose) {
if (ignorePose) {
@@ -777,7 +856,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return;
}
getHandle().connection.send(new PacketPlayOutEntityEffect(entity.getEntityId(), CraftPotionUtil.fromBukkit(effect)));
getHandle().connection.send(new PacketPlayOutEntityEffect(entity.getEntityId(), CraftPotionUtil.fromBukkit(effect), true));
}
@Override
@@ -789,7 +868,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return;
}
getHandle().connection.send(new PacketPlayOutRemoveEntityEffect(entity.getEntityId(), CraftPotionEffectType.bukkitToMinecraft(type)));
getHandle().connection.send(new PacketPlayOutRemoveEntityEffect(entity.getEntityId(), CraftPotionEffectType.bukkitToMinecraftHolder(type)));
}
@Override
@@ -876,11 +955,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
Collection<MapIcon> icons = new ArrayList<MapIcon>();
for (MapCursor cursor : data.cursors) {
if (cursor.isVisible()) {
icons.add(new MapIcon(MapIcon.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption())));
icons.add(new MapIcon(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrOptional(cursor.getCaption())));
}
}
PacketPlayOutMap packet = new PacketPlayOutMap(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.b(0, 0, 128, 128, data.buffer));
getHandle().connection.send(packet);
}
@@ -1716,17 +1795,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
private void sendCustomPayload(MinecraftKey id, byte[] message) {
ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(new CustomPacketPayload() {
@Override
public void write(PacketDataSerializer pds) {
pds.writeBytes(message);
}
@Override
public MinecraftKey id() {
return id;
}
});
ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(new DiscardedPayload(id, Unpooled.wrappedBuffer(message)));
getHandle().connection.send(packet);
}
@@ -1773,7 +1842,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
hashStr = BaseEncoding.base16().lowerCase().encode(hash);
}
this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrNull(prompt, true)), true);
this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrOptional(prompt, true)), true);
}
@Override
@@ -1786,7 +1855,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
hashStr = BaseEncoding.base16().lowerCase().encode(hash);
}
this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrNull(prompt, true)), false);
this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrOptional(prompt, true)), false);
}
@Override

View File

@@ -15,10 +15,10 @@ public class CraftSizedFireball extends CraftFireball implements SizedFireball {
@Override
public ItemStack getDisplayItem() {
if (getHandle().getItemRaw().isEmpty()) {
if (getHandle().getItem().isEmpty()) {
return new ItemStack(Material.FIRE_CHARGE);
} else {
return CraftItemStack.asBukkitCopy(getHandle().getItemRaw());
return CraftItemStack.asBukkitCopy(getHandle().getItem());
}
}

View File

@@ -62,7 +62,7 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat
@Override
public void setTamed(boolean tame) {
getHandle().setTame(tame);
getHandle().setTame(tame, true);
if (!tame) {
setOwnerUUID(null);
}

View File

@@ -14,10 +14,10 @@ public abstract class CraftThrowableProjectile extends CraftProjectile implement
@Override
public ItemStack getItem() {
if (getHandle().getItemRaw().isEmpty()) {
if (getHandle().getItem().isEmpty()) {
return CraftItemStack.asBukkitCopy(new net.minecraft.world.item.ItemStack(getHandle().getDefaultItemPublic()));
} else {
return CraftItemStack.asBukkitCopy(getHandle().getItemRaw());
return CraftItemStack.asBukkitCopy(getHandle().getItem());
}
}

View File

@@ -3,9 +3,10 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.projectile.EntityPotion;
import net.minecraft.world.item.alchemy.PotionUtil;
import net.minecraft.world.item.alchemy.PotionContents;
import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
@@ -22,7 +23,7 @@ public class CraftThrownPotion extends CraftThrowableProjectile implements Throw
@Override
public Collection<PotionEffect> getEffects() {
ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
for (MobEffect effect : PotionUtil.getMobEffects(getHandle().getItemRaw())) {
for (MobEffect effect : getHandle().getItem().getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).customEffects()) {
builder.add(CraftPotionUtil.toBukkit(effect));
}
return builder.build();
@@ -30,7 +31,7 @@ public class CraftThrownPotion extends CraftThrowableProjectile implements Throw
@Override
public ItemStack getItem() {
return CraftItemStack.asBukkitCopy(getHandle().getItemRaw());
return CraftItemStack.asBukkitCopy(getHandle().getItem());
}
@Override

View File

@@ -1,22 +1,22 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.projectile.EntityTippedArrow;
import net.minecraft.world.item.alchemy.PotionContents;
import org.bukkit.Color;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
public class CraftTippedArrow extends CraftArrow implements Arrow {
@@ -36,18 +36,11 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
if (existing != null) {
if (hasCustomEffect(effect.getType())) {
if (!override) {
return false;
}
getHandle().effects.remove(existing);
removeCustomEffect(effect.getType());
}
getHandle().addEffect(CraftPotionUtil.fromBukkit(effect));
getHandle().updateColor();
@@ -56,14 +49,15 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public void clearCustomEffects() {
getHandle().effects.clear();
PotionContents old = getHandle().getPotionContents();
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of()));
getHandle().updateColor();
}
@Override
public List<PotionEffect> getCustomEffects() {
ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
for (MobEffect effect : getHandle().effects) {
for (MobEffect effect : getHandle().getPotionContents().customEffects()) {
builder.add(CraftPotionUtil.toBukkit(effect));
}
return builder.build();
@@ -71,7 +65,7 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean hasCustomEffect(PotionEffectType type) {
for (MobEffect effect : getHandle().effects) {
for (MobEffect effect : getHandle().getPotionContents().customEffects()) {
if (CraftPotionUtil.equals(effect.getEffect(), type)) {
return true;
}
@@ -81,55 +75,41 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean hasCustomEffects() {
return !getHandle().effects.isEmpty();
return !getHandle().getPotionContents().customEffects().isEmpty();
}
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect);
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
if (existing == null) {
if (!hasCustomEffect(effect)) {
return false;
}
getHandle().effects.remove(existing);
getHandle().updateColor();
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()));
return true;
}
@Override
public void setBasePotionData(PotionData data) {
Preconditions.checkArgument(data != null, "PotionData cannot be null");
this.getHandle().potion = CraftPotionType.bukkitToMinecraft(CraftPotionUtil.fromBukkit(data));
public void setBasePotionType(PotionType potionType) {
if (potionType != null) {
getHandle().setPotionContents(getHandle().getPotionContents().withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType)));
} else {
PotionContents old = getHandle().getPotionContents();
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects()));
}
}
@Override
public PotionData getBasePotionData() {
return CraftPotionUtil.toBukkit(CraftPotionType.minecraftToBukkit(getHandle().potion));
}
@Override
public void setBasePotionType(@NotNull PotionType potionType) {
// TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message
Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead.");
getHandle().potion = CraftPotionType.bukkitToMinecraft(potionType);
}
@NotNull
@Override
public PotionType getBasePotionType() {
return CraftPotionType.minecraftToBukkit(getHandle().potion);
return getHandle().getPotionContents().potion().map(CraftPotionType::minecraftHolderToBukkit).orElse(null);
}
@Override
public void setColor(Color color) {
int colorRGB = (color == null) ? -1 : color.asRGB();
getHandle().setFixedColor(colorRGB);
PotionContents old = getHandle().getPotionContents();
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects()));
}
@Override

View File

@@ -2,22 +2,15 @@ package org.bukkit.craftbukkit.entity;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.WindCharge;
import org.bukkit.event.entity.EntityRemoveEvent;
public class CraftWindCharge extends CraftFireball implements WindCharge {
public CraftWindCharge(CraftServer server, net.minecraft.world.entity.projectile.WindCharge entity) {
public class CraftWindCharge extends CraftAbstractWindCharge implements WindCharge {
public CraftWindCharge(CraftServer server, net.minecraft.world.entity.projectile.windcharge.WindCharge entity) {
super(server, entity);
}
@Override
public void explode() {
this.getHandle().explode();
this.getHandle().discard(EntityRemoveEvent.Cause.EXPLODE); // SPIGOT-7577 - explode doesn't discard the entity, this happens only in tick and onHitBlock
}
@Override
public net.minecraft.world.entity.projectile.WindCharge getHandle() {
return (net.minecraft.world.entity.projectile.WindCharge) this.entity;
public net.minecraft.world.entity.projectile.windcharge.WindCharge getHandle() {
return (net.minecraft.world.entity.projectile.windcharge.WindCharge) this.entity;
}
@Override

View File

@@ -1,9 +1,17 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.EntityWolf;
import net.minecraft.world.entity.animal.WolfVariant;
import net.minecraft.world.item.EnumColor;
import org.bukkit.DyeColor;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.Wolf;
public class CraftWolf extends CraftTameableAnimal implements Wolf {
@@ -59,4 +67,54 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
public void setInterested(boolean flag) {
getHandle().setIsInterested(flag);
}
@Override
public Variant getVariant() {
return CraftVariant.minecraftHolderToBukkit(getHandle().getVariant());
}
@Override
public void setVariant(Variant variant) {
Preconditions.checkArgument(variant != null, "variant");
getHandle().setVariant(CraftVariant.bukkitToMinecraftHolder(variant));
}
public static class CraftVariant {
public static Variant minecraftToBukkit(WolfVariant minecraft) {
Preconditions.checkArgument(minecraft != null);
IRegistry<WolfVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT);
Variant bukkit = Registry.WOLF_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
Preconditions.checkArgument(bukkit != null);
return bukkit;
}
public static Variant minecraftHolderToBukkit(Holder<WolfVariant> minecraft) {
return minecraftToBukkit(minecraft.value());
}
public static WolfVariant bukkitToMinecraft(Variant bukkit) {
Preconditions.checkArgument(bukkit != null);
return CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT)
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
}
public static Holder<WolfVariant> bukkitToMinecraftHolder(Variant bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<WolfVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<WolfVariant> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own wolf variant with out properly registering it.");
}
}
}