components

This commit is contained in:
Lulu13022002 2024-12-14 18:41:01 +01:00
parent 016503a85f
commit d7eab570bd
No known key found for this signature in database
GPG key ID: 491C8F0B8ACDEB01
13 changed files with 113 additions and 146 deletions

View file

@ -0,0 +1,39 @@
--- a/net/minecraft/world/item/component/Consumable.java
+++ b/net/minecraft/world/item/component/Consumable.java
@@ -84,13 +_,35 @@
stack.getAllOfType(ConsumableListener.class).forEach(consumableListener -> consumableListener.onConsume(level, entity, stack, this));
if (!level.isClientSide) {
- this.onConsumeEffects.forEach(consumeEffect -> consumeEffect.apply(level, stack, entity));
+ // CraftBukkit start
+ org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause;
+ if (stack.is(net.minecraft.world.item.Items.MILK_BUCKET)) {
+ cause = org.bukkit.event.entity.EntityPotionEffectEvent.Cause.MILK;
+ } else if (stack.is(net.minecraft.world.item.Items.POTION)) {
+ cause = org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_DRINK;
+ } else {
+ cause = org.bukkit.event.entity.EntityPotionEffectEvent.Cause.FOOD;
+ }
+
+ this.onConsumeEffects.forEach(consumeEffect -> consumeEffect.apply(level, stack, entity, cause));
+ // CraftBukkit end
}
entity.gameEvent(this.animation == ItemUseAnimation.DRINK ? GameEvent.DRINK : GameEvent.EAT);
stack.consume(1, entity);
return stack;
}
+
+ // CraftBukkit start
+ public void cancelUsingItem(ServerPlayer player, ItemStack stack) {
+ final java.util.List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> packets = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(); // Paper - properly resend entities - collect packets for bundle
+ stack.getAllOfType(ConsumableListener.class).forEach(listener -> {
+ listener.cancelUsingItem(player, stack, packets); // Paper - properly resend entities - collect packets for bundle
+ });
+ player.server.getPlayerList().sendActiveEffects(player, packets::add); // Paper - properly resend entities - collect packets for bundle
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundBundlePacket(packets));
+ }
+ // CraftBukkit end
public boolean canConsume(LivingEntity entity, ItemStack stack) {
FoodProperties foodProperties = stack.get(DataComponents.FOOD);

View file

@ -0,0 +1,9 @@
--- a/net/minecraft/world/item/component/ConsumableListener.java
+++ b/net/minecraft/world/item/component/ConsumableListener.java
@@ -6,4 +_,6 @@
public interface ConsumableListener {
void onConsume(Level level, LivingEntity entity, ItemStack stack, Consumable consumable);
+
+ default void cancelUsingItem(net.minecraft.server.level.ServerPlayer player, ItemStack stack, java.util.List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> collectedPackets) {} // CraftBukkit // Paper - properly resend entities - collect packets for bundle
}

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/world/item/component/CustomData.java
+++ b/net/minecraft/world/item/component/CustomData.java
@@ -34,7 +34,17 @@
@@ -34,7 +_,17 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final CustomData EMPTY = new CustomData(new CompoundTag());
private static final String TYPE_TAG = "id";
@ -16,6 +16,6 @@
+ }
+ })
+ // Paper end - Item serialization as json
.xmap(CustomData::new, component -> component.tag);
.xmap(CustomData::new, customData -> customData.tag);
public static final Codec<CustomData> CODEC_WITH_ID = CODEC.validate(
component -> component.getUnsafe().contains("id", 8) ? DataResult.success(component) : DataResult.error(() -> "Missing id for entity in: " + component)
data -> data.getUnsafe().contains("id", 8) ? DataResult.success(data) : DataResult.error(() -> "Missing id for entity in: " + data)

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/component/DeathProtection.java
+++ b/net/minecraft/world/item/component/DeathProtection.java
@@ -37,7 +_,7 @@
public void applyEffects(ItemStack stack, LivingEntity entity) {
for (ConsumeEffect consumeEffect : this.deathEffects) {
- consumeEffect.apply(entity.level(), stack, entity);
+ consumeEffect.apply(entity.level(), stack, entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM); // CraftBukkit
}
}
}

View file

@ -1,11 +1,11 @@
--- a/net/minecraft/world/item/component/LodestoneTracker.java
+++ b/net/minecraft/world/item/component/LodestoneTracker.java
@@ -29,7 +29,7 @@
@@ -29,7 +_,7 @@
return this;
} else {
BlockPos blockPos = this.target.get().pos();
- return world.isInWorldBounds(blockPos) && world.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)
+ return world.isInWorldBounds(blockPos) && (!world.hasChunkAt(blockPos) || world.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)) // Paper - Prevent compass from loading chunks
- return level.isInWorldBounds(blockPos) && level.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)
+ return level.isInWorldBounds(blockPos) && (!level.hasChunkAt(blockPos) || level.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)) // Paper - Prevent compass from loading chunks
? this
: new LodestoneTracker(Optional.empty(), true);
}

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/item/component/OminousBottleAmplifier.java
+++ b/net/minecraft/world/item/component/OminousBottleAmplifier.java
@@ -28,8 +_,15 @@
@Override
public void onConsume(Level level, LivingEntity entity, ItemStack stack, Consumable consumable) {
- entity.addEffect(new MobEffectInstance(MobEffects.BAD_OMEN, 120000, this.value, false, false, true));
- }
+ entity.addEffect(new MobEffectInstance(MobEffects.BAD_OMEN, 120000, this.value, false, false, true)); // Paper - properly resend entities - diff on change for below
+ }
+
+ // Paper start - properly resend entities - collect packets for bundle
+ @Override
+ public void cancelUsingItem(net.minecraft.server.level.ServerPlayer player, ItemStack stack, List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> collectedPackets) {
+ collectedPackets.add(new net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket(player.getId(), MobEffects.BAD_OMEN));
+ }
+ // Paper end - properly resend entities - collect packets for bundle
@Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> tooltipAdder, TooltipFlag tooltipFlag) {

View file

@ -1,18 +1,18 @@
--- a/net/minecraft/world/item/component/ResolvableProfile.java
+++ b/net/minecraft/world/item/component/ResolvableProfile.java
@@ -20,9 +20,10 @@
@@ -20,9 +_,10 @@
instance -> instance.group(
ExtraCodecs.PLAYER_NAME.optionalFieldOf("name").forGetter(ResolvableProfile::name),
UUIDUtil.CODEC.optionalFieldOf("id").forGetter(ResolvableProfile::id),
+ UUIDUtil.STRING_CODEC.lenientOptionalFieldOf("Id").forGetter($ -> Optional.empty()), // Paper
ExtraCodecs.PROPERTY_MAP.optionalFieldOf("properties", new PropertyMap()).forGetter(ResolvableProfile::properties)
)
- .apply(instance, ResolvableProfile::new)
+ .apply(instance, (s, uuid, uuid2, propertyMap) -> new ResolvableProfile(s, uuid2.or(() -> uuid), propertyMap)) // Paper
ExtraCodecs.PLAYER_NAME.optionalFieldOf("name").forGetter(ResolvableProfile::name),
UUIDUtil.CODEC.optionalFieldOf("id").forGetter(ResolvableProfile::id),
+ UUIDUtil.STRING_CODEC.lenientOptionalFieldOf("Id").forGetter($ -> Optional.empty()), // Paper
ExtraCodecs.PROPERTY_MAP.optionalFieldOf("properties", new PropertyMap()).forGetter(ResolvableProfile::properties)
)
- .apply(instance, ResolvableProfile::new)
+ .apply(instance, (name, uuid, uuid2, propertyMap) -> new ResolvableProfile(name, uuid2.or(() -> uuid), propertyMap)) // Paper
);
public static final Codec<ResolvableProfile> CODEC = Codec.withAlternative(
FULL_CODEC, ExtraCodecs.PLAYER_NAME, name -> new ResolvableProfile(Optional.of(name), Optional.empty(), new PropertyMap())
@@ -49,7 +50,7 @@
@@ -49,7 +_,7 @@
if (this.isResolved()) {
return CompletableFuture.completedFuture(this);
} else {
@ -20,4 +20,4 @@
+ return this.id.isPresent() ? SkullBlockEntity.fetchGameProfile(this.id.get(), this.name.orElse(null)).thenApply(optional -> { // Paper - player profile events
GameProfile gameProfile = optional.orElseGet(() -> new GameProfile(this.id.get(), this.name.orElse("")));
return new ResolvableProfile(gameProfile);
}) : SkullBlockEntity.fetchGameProfile(this.name.orElseThrow()).thenApply(profile -> {
}) : SkullBlockEntity.fetchGameProfile(this.name.orElseThrow()).thenApply(optional -> {

View file

@ -0,0 +1,18 @@
--- a/net/minecraft/world/item/component/SuspiciousStewEffects.java
+++ b/net/minecraft/world/item/component/SuspiciousStewEffects.java
@@ -41,6 +_,15 @@
}
}
+ // CraftBukkit start
+ @Override
+ public void cancelUsingItem(net.minecraft.server.level.ServerPlayer player, ItemStack stack, List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> collectedPackets) { // Paper - properly resend entities - collect packets for bundle
+ for (SuspiciousStewEffects.Entry entry : this.effects) {
+ collectedPackets.add(new net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket(player.getId(), entry.effect())); // Paper - bundlize packets
+ }
+ }
+ // CraftBukkit end
+
@Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> tooltipAdder, TooltipFlag tooltipFlag) {
if (tooltipFlag.isCreative()) {

View file

@ -1,53 +0,0 @@
--- a/net/minecraft/world/item/component/Consumable.java
+++ b/net/minecraft/world/item/component/Consumable.java
@@ -29,6 +29,11 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
+// CraftBukkit start
+import net.minecraft.world.item.Items;
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+// CraftBukkit end
+
public record Consumable(float consumeSeconds, ItemUseAnimation animation, Holder<SoundEvent> sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects) {
public static final float DEFAULT_CONSUME_SECONDS = 1.6F;
@@ -69,8 +74,19 @@
consumablelistener.onConsume(world, user, stack, this);
});
if (!world.isClientSide) {
+ // CraftBukkit start
+ EntityPotionEffectEvent.Cause cause;
+ if (stack.is(Items.MILK_BUCKET)) {
+ cause = EntityPotionEffectEvent.Cause.MILK;
+ } else if (stack.is(Items.POTION)) {
+ cause = EntityPotionEffectEvent.Cause.POTION_DRINK;
+ } else {
+ cause = EntityPotionEffectEvent.Cause.FOOD;
+ }
+
this.onConsumeEffects.forEach((consumeeffect) -> {
- consumeeffect.apply(world, stack, user);
+ consumeeffect.apply(world, stack, user, cause);
+ // CraftBukkit end
});
}
@@ -79,6 +95,17 @@
return stack;
}
+ // CraftBukkit start
+ public void cancelUsingItem(net.minecraft.server.level.ServerPlayer entityplayer, ItemStack itemstack) {
+ final java.util.List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> packets = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(); // Paper - properly resend entities - collect packets for bundle
+ itemstack.getAllOfType(ConsumableListener.class).forEach((consumablelistener) -> {
+ consumablelistener.cancelUsingItem(entityplayer, itemstack, packets); // Paper - properly resend entities - collect packets for bundle
+ });
+ entityplayer.server.getPlayerList().sendActiveEffects(entityplayer, packets::add); // Paper - properly resend entities - collect packets for bundle
+ entityplayer.connection.send(new net.minecraft.network.protocol.game.ClientboundBundlePacket(packets));
+ }
+ // CraftBukkit end
+
public boolean canConsume(LivingEntity user, ItemStack stack) {
FoodProperties foodinfo = (FoodProperties) stack.get(DataComponents.FOOD);

View file

@ -1,9 +0,0 @@
--- a/net/minecraft/world/item/component/ConsumableListener.java
+++ b/net/minecraft/world/item/component/ConsumableListener.java
@@ -7,4 +7,6 @@
public interface ConsumableListener {
void onConsume(Level world, LivingEntity user, ItemStack stack, Consumable consumable);
+
+ default void cancelUsingItem(net.minecraft.server.level.ServerPlayer entityplayer, ItemStack itemstack, java.util.List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> collectedPackets) {} // CraftBukkit // Paper - properly resend entities - collect packets for bundle
}

View file

@ -1,22 +0,0 @@
--- a/net/minecraft/world/item/component/DeathProtection.java
+++ b/net/minecraft/world/item/component/DeathProtection.java
@@ -15,6 +15,10 @@
import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect;
import net.minecraft.world.item.consume_effects.ConsumeEffect;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+// CraftBukkit end
+
public record DeathProtection(List<ConsumeEffect> deathEffects) {
public static final Codec<DeathProtection> CODEC = RecordCodecBuilder.create((instance) -> {
@@ -29,7 +33,7 @@
while (iterator.hasNext()) {
ConsumeEffect consumeeffect = (ConsumeEffect) iterator.next();
- consumeeffect.apply(entity.level(), stack, entity);
+ consumeeffect.apply(entity.level(), stack, entity, EntityPotionEffectEvent.Cause.TOTEM); // CraftBukkit
}
}

View file

@ -1,18 +0,0 @@
--- a/net/minecraft/world/item/component/OminousBottleAmplifier.java
+++ b/net/minecraft/world/item/component/OminousBottleAmplifier.java
@@ -28,8 +28,14 @@
@Override
public void onConsume(Level world, LivingEntity user, ItemStack stack, Consumable consumable) {
- user.addEffect(new MobEffectInstance(MobEffects.BAD_OMEN, 120000, this.value, false, false, true));
+ user.addEffect(new MobEffectInstance(MobEffects.BAD_OMEN, 120000, this.value, false, false, true)); // Paper - properly resend entities - diff on change for below
}
+ // Paper start - properly resend entities - collect packets for bundle
+ @Override
+ public void cancelUsingItem(net.minecraft.server.level.ServerPlayer entityplayer, ItemStack itemstack, java.util.List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> collectedPackets) {
+ collectedPackets.add(new net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket(entityplayer.getId(), MobEffects.BAD_OMEN));
+ }
+ // Paper end - properly resend entities - collect packets for bundle
@Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> tooltip, TooltipFlag type) {

View file

@ -1,28 +0,0 @@
--- a/net/minecraft/world/item/component/SuspiciousStewEffects.java
+++ b/net/minecraft/world/item/component/SuspiciousStewEffects.java
@@ -29,7 +29,7 @@
public static final StreamCodec<RegistryFriendlyByteBuf, SuspiciousStewEffects> STREAM_CODEC = SuspiciousStewEffects.Entry.STREAM_CODEC.apply(ByteBufCodecs.list()).map(SuspiciousStewEffects::new, SuspiciousStewEffects::effects);
public SuspiciousStewEffects withEffectAdded(SuspiciousStewEffects.Entry stewEffect) {
- return new SuspiciousStewEffects(Util.copyAndAdd(this.effects, (Object) stewEffect));
+ return new SuspiciousStewEffects(Util.copyAndAdd(this.effects, stewEffect)); // CraftBukkit - decompile error
}
@Override
@@ -44,7 +44,16 @@
}
+ // CraftBukkit start
@Override
+ public void cancelUsingItem(net.minecraft.server.level.ServerPlayer entityplayer, ItemStack itemstack, java.util.List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> collectedPackets) { // Paper - properly resend entities - collect packets for bundle
+ for (SuspiciousStewEffects.Entry suspicioussteweffects_a : this.effects) {
+ collectedPackets.add(new net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket(entityplayer.getId(), suspicioussteweffects_a.effect())); // Paper - bundlize packets
+ }
+ }
+ // CraftBukkit end
+
+ @Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> tooltip, TooltipFlag type) {
if (type.isCreative()) {
List<MobEffectInstance> list = new ArrayList();