Update to Minecraft 1.20.2

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2023-09-22 02:40:00 +10:00
parent 193398c0ff
commit 8a3c8cfcd4
238 changed files with 2448 additions and 2344 deletions

View File

@@ -13,6 +13,7 @@ import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.craftbukkit.CraftParticle;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.LivingEntity;
@@ -134,10 +135,10 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
int effectId = effect.getType().getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
@@ -184,10 +185,10 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
int effectId = effect.getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect);
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}

View File

@@ -45,12 +45,12 @@ public class CraftDisplay extends CraftEntity implements Display {
@Override
public int getInterpolationDuration() {
return getHandle().getInterpolationDuration();
return getHandle().getTransformationInterpolationDuration();
}
@Override
public void setInterpolationDuration(int duration) {
getHandle().setInterpolationDuration(duration);
getHandle().setTransformationInterpolationDuration(duration);
}
@Override
@@ -105,12 +105,12 @@ public class CraftDisplay extends CraftEntity implements Display {
@Override
public int getInterpolationDelay() {
return getHandle().getInterpolationDelay();
return getHandle().getTransformationInterpolationDelay();
}
@Override
public void setInterpolationDelay(int ticks) {
getHandle().setInterpolationDelay(ticks);
getHandle().setTransformationInterpolationDelay(ticks);
}
@Override

View File

@@ -7,7 +7,6 @@ import com.google.common.collect.Lists;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import net.minecraft.core.Position;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.chat.IChatBaseComponent;
@@ -545,7 +544,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.teleportTo(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toPosition(location));
entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location));
return true;
}

View File

@@ -24,6 +24,7 @@ import net.minecraft.world.inventory.Containers;
import net.minecraft.world.item.ItemCooldown;
import net.minecraft.world.item.crafting.CraftingManager;
import net.minecraft.world.item.crafting.IRecipe;
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;
@@ -540,12 +541,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
return ImmutableSet.of();
}
private Collection<IRecipe<?>> bukkitKeysToMinecraftRecipes(Collection<NamespacedKey> recipeKeys) {
Collection<IRecipe<?>> recipes = new ArrayList<>();
private Collection<RecipeHolder<?>> bukkitKeysToMinecraftRecipes(Collection<NamespacedKey> recipeKeys) {
Collection<RecipeHolder<?>> recipes = new ArrayList<>();
CraftingManager manager = getHandle().level().getServer().getRecipeManager();
for (NamespacedKey recipeKey : recipeKeys) {
Optional<? extends IRecipe<?>> recipe = manager.byKey(CraftNamespacedKey.toMinecraft(recipeKey));
Optional<? extends RecipeHolder<?>> recipe = manager.byKey(CraftNamespacedKey.toMinecraft(recipeKey));
if (!recipe.isPresent()) {
continue;
}

View File

@@ -56,6 +56,7 @@ import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey;
import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper;
import org.bukkit.craftbukkit.inventory.CraftEntityEquipment;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
@@ -373,7 +374,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public boolean addPotionEffect(PotionEffect effect, boolean force) {
getHandle().addEffect(new MobEffect(MobEffectList.byId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
getHandle().addEffect(new MobEffect(CraftPotionEffectType.bukkitToMinecraft(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
return true;
}
@@ -388,25 +389,25 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public boolean hasPotionEffect(PotionEffectType type) {
return getHandle().hasEffect(MobEffectList.byId(type.getId()));
return getHandle().hasEffect(CraftPotionEffectType.bukkitToMinecraft(type));
}
@Override
public PotionEffect getPotionEffect(PotionEffectType type) {
MobEffect handle = getHandle().getEffect(MobEffectList.byId(type.getId()));
return (handle == null) ? null : new PotionEffect(PotionEffectType.getById(MobEffectList.getId(handle.getEffect())), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
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());
}
@Override
public void removePotionEffect(PotionEffectType type) {
getHandle().removeEffect(MobEffectList.byId(type.getId()), EntityPotionEffectEvent.Cause.PLUGIN);
getHandle().removeEffect(CraftPotionEffectType.bukkitToMinecraft(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(PotionEffectType.getById(MobEffectList.getId(handle.getEffect())), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
effects.add(new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
}
return effects;
}

View File

@@ -41,6 +41,9 @@ import net.minecraft.network.PacketDataSerializer;
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.ClientboundResourcePackPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
@@ -56,7 +59,6 @@ import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
import net.minecraft.network.protocol.game.PacketPlayOutBlockBreakAnimation;
import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
import net.minecraft.network.protocol.game.PacketPlayOutCustomPayload;
import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
import net.minecraft.network.protocol.game.PacketPlayOutEntitySound;
import net.minecraft.network.protocol.game.PacketPlayOutExperience;
@@ -1659,12 +1661,26 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (getHandle().connection == null) return;
if (channels.contains(channel)) {
channel = StandardMessenger.validateAndCorrectChannel(channel);
PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload(new MinecraftKey(channel), new PacketDataSerializer(Unpooled.wrappedBuffer(message)));
getHandle().connection.send(packet);
MinecraftKey id = new MinecraftKey(StandardMessenger.validateAndCorrectChannel(channel));
sendCustomPayload(id, message);
}
}
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;
}
});
getHandle().connection.send(packet);
}
@Override
public void setTexturePack(String url) {
setResourcePack(url);
@@ -1697,9 +1713,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (hash != null) {
Preconditions.checkArgument(hash.length == 20, "Resource pack hash should be 20 bytes long but was %s", hash.length);
getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), force, CraftChatMessage.fromStringOrNull(prompt, true));
getHandle().connection.send(new ClientboundResourcePackPacket(url, BaseEncoding.base16().lowerCase().encode(hash), force, CraftChatMessage.fromStringOrNull(prompt, true)));
} else {
getHandle().sendTexturePack(url, "", force, CraftChatMessage.fromStringOrNull(prompt, true));
getHandle().connection.send(new ClientboundResourcePackPacket(url, "", force, CraftChatMessage.fromStringOrNull(prompt, true)));
}
}
@@ -1739,7 +1755,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
getHandle().connection.send(new PacketPlayOutCustomPayload(new MinecraftKey("register"), new PacketDataSerializer(Unpooled.wrappedBuffer(stream.toByteArray()))));
sendCustomPayload(new MinecraftKey("register"), stream.toByteArray());
}
}
@@ -2085,17 +2101,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public int getClientViewDistance() {
return (getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : getHandle().clientViewDistance;
return (getHandle().requestedViewDistance() == 0) ? Bukkit.getViewDistance() : getHandle().requestedViewDistance();
}
@Override
public int getPing() {
return getHandle().latency;
return getHandle().connection.latency();
}
@Override
public String getLocale() {
return getHandle().locale;
return getHandle().language;
}
@Override

View File

@@ -10,6 +10,7 @@ import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.projectile.EntityTippedArrow;
import org.bukkit.Color;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.potion.PotionData;
@@ -34,10 +35,10 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
int effectId = effect.getType().getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
@@ -84,10 +85,10 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
int effectId = effect.getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect);
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}