Skip to content

Commit 087fe6a

Browse files
committed
chore(git): merge upstream changes
2 parents 4c7bd6d + f16da75 commit 087fe6a

26 files changed

Lines changed: 745 additions & 49 deletions

File tree

generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ public static List<Generator> itemRegistries(final Context context) {
111111
$ -> true,
112112
RegistryScope.SERVER
113113
),
114+
new RegistryEntriesGenerator<>(
115+
"data.type",
116+
"ItemActionTypes",
117+
"ITEM_ACTION_TYPE",
118+
context.relativeClass("data.type", "ItemActionType"),
119+
Registries.CONSUME_EFFECT_TYPE
120+
),
114121
new EnumEntriesValidator<>(
115122
"entity.display",
116123
"ItemDisplayTypes",

src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
package org.spongepowered.common.data.provider.item.stack;
2626

2727
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
28-
import net.minecraft.core.Holder;
29-
import net.minecraft.core.HolderSet;
3028
import net.minecraft.core.component.DataComponentPatch;
3129
import net.minecraft.core.component.DataComponents;
3230
import net.minecraft.network.chat.Component;
3331
import net.minecraft.resources.ResourceLocation;
32+
import net.minecraft.sounds.SoundEvents;
3433
import net.minecraft.tags.DamageTypeTags;
3534
import net.minecraft.util.StringUtil;
3635
import net.minecraft.util.Unit;
@@ -43,21 +42,18 @@
4342
import net.minecraft.world.item.component.Consumable;
4443
import net.minecraft.world.item.component.CustomModelData;
4544
import net.minecraft.world.item.component.DamageResistant;
45+
import net.minecraft.world.item.component.DeathProtection;
4646
import net.minecraft.world.item.component.ItemContainerContents;
4747
import net.minecraft.world.item.component.ItemLore;
4848
import net.minecraft.world.item.component.UseCooldown;
4949
import net.minecraft.world.item.component.UseRemainder;
50-
import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect;
51-
import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect;
5250
import net.minecraft.world.item.consume_effects.ConsumeEffect;
53-
import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect;
54-
import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect;
55-
import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect;
5651
import org.checkerframework.checker.nullness.qual.Nullable;
5752
import org.spongepowered.api.Platform;
5853
import org.spongepowered.api.ResourceKey;
5954
import org.spongepowered.api.data.DataTransactionResult;
6055
import org.spongepowered.api.data.Keys;
56+
import org.spongepowered.api.data.type.ItemAction;
6157
import org.spongepowered.api.data.value.Value;
6258
import org.spongepowered.api.item.ItemRarity;
6359
import org.spongepowered.api.item.ItemType;
@@ -77,7 +73,7 @@
7773
public final class ItemStackData {
7874

7975
public static final FoodProperties DEFAULT_FOOD_PROPERTIES = new FoodProperties(0, 0, false);
80-
public static final Consumable DEFAULT_CONSUMABLE_PROPERTIES = new Consumable(1.6F, ItemUseAnimation.EAT, null, true, List.of());
76+
public static final Consumable DEFAULT_CONSUMABLE_PROPERTIES = new Consumable(1.6F, ItemUseAnimation.EAT, SoundEvents.GENERIC_EAT, true, List.of());
8177

8278
private ItemStackData() {
8379
}
@@ -99,14 +95,6 @@ public static void register(final DataProviderRegistrator registrator) {
9995
// TODO DataComponents.RECIPES - for Items.KNOWLEDGE_BOOK
10096
// TODO DataComponents.OMINOUS_BOTTLE_AMPLIFIER 1.21
10197

102-
// TODO rework applicable potion effects to consume effects
103-
final var applicablePotionEffects = Keys.APPLICABLE_POTION_EFFECTS;
104-
ConsumeEffect newPotionEffects = new ApplyStatusEffectsConsumeEffect(List.of());
105-
ConsumeEffect teleportRand = new TeleportRandomlyConsumeEffect(5);
106-
ConsumeEffect removeStatusEffects = new RemoveStatusEffectsConsumeEffect(HolderSet.empty());
107-
ConsumeEffect clearStatusEffects = new ClearAllStatusEffectsConsumeEffect();
108-
ConsumeEffect playSoundEffect = new PlaySoundConsumeEffect(Holder.direct(null));
109-
11098
registrator
11199
.asMutable(ItemStack.class)
112100
.create(Keys.BURN_TIME)
@@ -251,6 +239,20 @@ public static void register(final DataProviderRegistrator registrator) {
251239
})
252240
.set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES,
253241
c -> new Consumable(v.ticks() / 20f, c.animation(), c.sound(), c.hasConsumeParticles(), c.onConsumeEffects())))
242+
.create(Keys.CONSUME_ACTIONS)
243+
.get(h -> {
244+
final var consumable = h.get(DataComponents.CONSUMABLE);
245+
return consumable == null ? null : (List<ItemAction>) (Object) consumable.onConsumeEffects();
246+
})
247+
.set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES,
248+
c -> new Consumable(c.consumeSeconds(), c.animation(), c.sound(), c.hasConsumeParticles(), (List<ConsumeEffect>) (Object) v)))
249+
.create(Keys.DEATH_PROTECTION_ACTIONS)
250+
.get(h -> {
251+
final var deathProtection = h.get(DataComponents.DEATH_PROTECTION);
252+
return deathProtection == null ? null : (List<ItemAction>) (Object) deathProtection.deathEffects();
253+
})
254+
.set((h, v) -> h.set(DataComponents.DEATH_PROTECTION, new DeathProtection((List<ConsumeEffect>) (Object) v)))
255+
.delete(h -> h.remove(DataComponents.DEATH_PROTECTION))
254256
.create(Keys.FOOD_CONVERTS_TO)
255257
.get(h -> {
256258
final var remainder = h.get(DataComponents.USE_REMAINDER);
@@ -364,6 +366,10 @@ public static void register(final DataProviderRegistrator registrator) {
364366
return builder.build();
365367
})
366368
.deleteAndGet(ItemStackData::deleteAndTransactUseCooldown)
369+
.create(Keys.TOOLTIP_STYLE)
370+
.get(h -> (ResourceKey) (Object) h.get(DataComponents.TOOLTIP_STYLE))
371+
.set((h, v) -> h.set(DataComponents.TOOLTIP_STYLE, (ResourceLocation) (Object) v))
372+
.delete(h -> h.remove(DataComponents.TOOLTIP_STYLE))
367373
;
368374
}
369375
// @formatter:on

src/main/java/org/spongepowered/common/effect/SpongeForwardingViewer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import net.minecraft.network.protocol.game.ClientGamePacketListener;
3333
import org.spongepowered.api.effect.ForwardingViewer;
3434
import org.spongepowered.api.effect.sound.music.MusicDisc;
35+
import org.spongepowered.api.item.inventory.ItemStackLike;
3536
import org.spongepowered.common.bridge.effect.ViewerBridge;
3637

3738
public interface SpongeForwardingViewer extends SpongeViewer, ForwardingViewer, ViewerBridge {
@@ -50,6 +51,11 @@ public interface SpongeForwardingViewer extends SpongeViewer, ForwardingViewer,
5051

5152
// Viewer
5253

54+
@Override
55+
default void playTotemOfUndyingEffect(final ItemStackLike stack) {
56+
this.audiences().forEach(viewer -> viewer.playTotemOfUndyingEffect(stack));
57+
}
58+
5359
@Override
5460
default void playMusicDisc(final int x, final int y, final int z, final MusicDisc musicDisc) {
5561
this.audiences().forEach(viewer -> viewer.playMusicDisc(x, y, z, musicDisc));

src/main/java/org/spongepowered/common/effect/util/ViewerPacketUtil.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131
import net.minecraft.core.BlockPos;
3232
import net.minecraft.core.Holder;
3333
import net.minecraft.core.RegistryAccess;
34+
import net.minecraft.core.component.DataComponents;
3435
import net.minecraft.core.registries.Registries;
3536
import net.minecraft.network.protocol.Packet;
3637
import net.minecraft.network.protocol.game.ClientGamePacketListener;
3738
import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
3839
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
3940
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
4041
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
42+
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
4143
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
4244
import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket;
45+
import net.minecraft.network.protocol.game.ClientboundSetPlayerInventoryPacket;
4346
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
4447
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
4548
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
@@ -50,7 +53,10 @@
5053
import net.minecraft.sounds.SoundEvent;
5154
import net.minecraft.sounds.SoundSource;
5255
import net.minecraft.util.RandomSource;
56+
import net.minecraft.world.entity.player.Inventory;
57+
import net.minecraft.world.item.ItemStack;
5358
import net.minecraft.world.item.JukeboxSong;
59+
import net.minecraft.world.item.component.DeathProtection;
5460
import net.minecraft.world.level.BlockGetter;
5561
import net.minecraft.world.level.dimension.DimensionType;
5662
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -60,12 +66,15 @@
6066
import org.spongepowered.api.effect.particle.ParticleEffect;
6167
import org.spongepowered.api.effect.sound.music.MusicDisc;
6268
import org.spongepowered.api.entity.Entity;
69+
import org.spongepowered.api.entity.living.player.Player;
70+
import org.spongepowered.api.item.inventory.ItemStackLike;
6371
import org.spongepowered.api.world.World;
6472
import org.spongepowered.api.world.WorldType;
6573
import org.spongepowered.common.SpongeCommon;
6674
import org.spongepowered.common.SpongeEngine;
6775
import org.spongepowered.common.adventure.SpongeAdventure;
6876
import org.spongepowered.common.effect.particle.SpongeParticleHelper;
77+
import org.spongepowered.common.item.util.ItemStackUtil;
6978
import org.spongepowered.common.network.packet.ChangeViewerEnvironmentPacket;
7079

7180
import java.time.Duration;
@@ -80,6 +89,38 @@ public static ChangeViewerEnvironmentPacket changeEnvironment(final WorldType wo
8089
return new ChangeViewerEnvironmentPacket((DimensionType) (Object) Objects.requireNonNull(worldType, "worldType"));
8190
}
8291

92+
public static Packet<ClientGamePacketListener> totemOfUndying(final Player player, final ItemStackLike stack) {
93+
final ItemStack item = ItemStackUtil.fromLikeToNativeCopy(stack);
94+
// Client will play item animation only if it has DEATH_PROTECTION component,
95+
// otherwise it will use totem of undying
96+
if (!item.has(DataComponents.DEATH_PROTECTION)) {
97+
item.set(DataComponents.DEATH_PROTECTION, new DeathProtection(List.of()));
98+
}
99+
100+
final net.minecraft.world.entity.player.Player mcPlayer = (net.minecraft.world.entity.player.Player) player;
101+
final Inventory inventory = mcPlayer.getInventory();
102+
final int totemSlot = inventory.getSelectedSlot();
103+
final net.minecraft.world.item.ItemStack oldItem = inventory.getSelectedItem();
104+
105+
final ClientboundEntityEventPacket effectPacket = new ClientboundEntityEventPacket(mcPlayer, (byte) 35);
106+
if (ItemStack.matches(oldItem, item)) {
107+
return effectPacket;
108+
}
109+
110+
final List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
111+
112+
// First we need to send a fake totem ItemStack to the player's hand
113+
packets.add(new ClientboundSetPlayerInventoryPacket(totemSlot, item));
114+
115+
// Next we tell the client to play the totem of undying effect
116+
packets.add(effectPacket);
117+
118+
// Now we can remove the fake totem
119+
packets.add(new ClientboundSetPlayerInventoryPacket(totemSlot, oldItem));
120+
121+
return new ClientboundBundlePacket(packets);
122+
}
123+
83124
public static ClientboundBundlePacket spawnParticles(final ParticleEffect particleEffect, final double x, final double y, final double z) {
84125
return SpongeParticleHelper.createPacket(particleEffect, x, y, z);
85126
}

src/main/java/org/spongepowered/common/event/tracking/context/transaction/effect/OldBlockOnReplaceEffect.java

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.spongepowered.common.event.tracking.context.transaction.effect;
2626

27+
import net.minecraft.world.level.block.BaseRailBlock;
2728
import net.minecraft.world.level.block.state.BlockState;
2829
import org.checkerframework.checker.nullness.qual.Nullable;
2930
import org.spongepowered.common.event.tracking.context.transaction.pipeline.BlockPipeline;
@@ -47,28 +48,22 @@ public static OldBlockOnReplaceEffect getInstance() {
4748
) {
4849
// This replaces LevelChunk#setBlockState block:
4950
/*
50-
51-
if ($$14) {
52-
if (this.level instanceof ServerLevel $$17) {
53-
// -- this block is this side effect
54-
if (hasBlockEntity && $$16) {
55-
BlockEntity $$18 = this.level.getBlockEntity($$0);
56-
if ($$18 != null) {
57-
$$18.preRemoveSideEffects($$0, $$9, $$15);
58-
}
51+
boolean $$13 = !$$9.is($$10);
52+
boolean $$14 = ($$2 & 64) != 0;
53+
boolean $$15 = ($$2 & 256) == 0;
54+
if ($$13 && $$9.hasBlockEntity()) {
55+
if (!this.level.isClientSide && $$15) {
56+
BlockEntity $$16 = this.level.getBlockEntity($$0);
57+
if ($$16 != null) {
58+
$$16.preRemoveSideEffects($$0, $$9);
5959
}
60+
}
6061
61-
if (hasBlockEntity) {
62-
this.removeBlockEntity($$0);
63-
}
62+
this.removeBlockEntity($$0);
63+
}
6464
65-
if (($$2 & 1) != 0) {
66-
$$9.affectNeighborsAfterRemoval($$17, $$0, $$15);
67-
}
68-
// -- end of side effect
69-
} else if (hasBlockEntity) {
70-
this.removeBlockEntity($$0);
71-
}
65+
if (($$13 || $$10 instanceof BaseRailBlock) && this.level instanceof ServerLevel $$17 && (($$2 & 1) != 0 || $$14)) {
66+
$$9.affectNeighborsAfterRemoval($$17, $$0, $$14);
7267
}
7368
Notes:
7469
Since we know we're on the server context, we eliminate
@@ -81,22 +76,19 @@ public static OldBlockOnReplaceEffect getInstance() {
8176
final var flag = args.flag();
8277
final var pos = oldState.pos();
8378

84-
if (!oldState.state().is(newState.getBlock())) {
85-
return EffectResult.nullPass();
86-
}
87-
// Spogne adds the block physics flag
88-
if (hasBlockEntity && !flag.performBlockDestruction() && flag.performBlockPhysics()) {
89-
final var blockEntity = oldState.tileEntity();
90-
if (blockEntity != null) {
91-
blockEntity.preRemoveSideEffects(pos, newState);
79+
final boolean replaced = !oldState.state().is(newState.getBlock());
80+
if (replaced && hasBlockEntity) {
81+
if (flag.performBlockDestruction()) {
82+
final var blockEntity = oldState.tileEntity();
83+
if (blockEntity != null) {
84+
blockEntity.preRemoveSideEffects(pos, oldState.state());
85+
}
9286
}
93-
}
9487

95-
if (hasBlockEntity) {
9688
pipeline.getAffectedChunk().removeBlockEntity(pos);
9789
}
9890

99-
if (flag.updateNeighbors()) {
91+
if ((replaced || newState.getBlock() instanceof BaseRailBlock) && (flag.updateNeighbors() || flag.movingBlocks())) {
10092
oldState.state().affectNeighborsAfterRemoval(pipeline.getServerWorld(), pos, flag.movingBlocks());
10193
}
10294

src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/ClickMenuTransaction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
package org.spongepowered.common.event.tracking.context.transaction.inventory;
2626

2727
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
28+
import net.minecraft.network.protocol.game.ServerboundPickItemFromBlockPacket;
29+
import net.minecraft.network.protocol.game.ServerboundPickItemFromEntityPacket;
2830
import net.minecraft.server.level.ServerPlayer;
2931
import net.minecraft.world.entity.player.Player;
3032
import net.minecraft.world.inventory.AbstractContainerMenu;
@@ -109,6 +111,10 @@ boolean isContainerEventAllowed(
109111
if (!(context instanceof InventoryPacketContext ipc)) {
110112
return false;
111113
}
114+
if(ipc.getPacket() instanceof ServerboundPickItemFromBlockPacket ||
115+
ipc.getPacket() instanceof ServerboundPickItemFromEntityPacket) {
116+
return true; //The item is always put in the player container menu
117+
}
112118
final int containerId = ipc.<ServerboundContainerClickPacket>getPacket().containerId();
113119
return containerId != this.player.containerMenu.containerId;
114120
}

src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
4040
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
4141
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
42+
import net.minecraft.network.protocol.game.ServerboundPickItemFromBlockPacket;
43+
import net.minecraft.network.protocol.game.ServerboundPickItemFromEntityPacket;
4244
import net.minecraft.network.protocol.game.ServerboundPlaceRecipePacket;
4345
import net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket;
4446
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
@@ -314,6 +316,8 @@ private void setupPacketToStateMapping() {
314316
this.packetTranslationMap.put(ServerboundPlayerInputPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
315317
this.packetTranslationMap.put(ServerboundContainerClosePacket.class, packet -> PacketPhase.General.CLOSE_WINDOW);
316318
this.packetTranslationMap.put(ServerboundContainerClickPacket.class, packet -> PacketPhase.fromWindowPacket((ServerboundContainerClickPacket) packet));
319+
this.packetTranslationMap.put(ServerboundPickItemFromBlockPacket.class, packet -> Inventory.MIDDLE_INVENTORY_CLICK);
320+
this.packetTranslationMap.put(ServerboundPickItemFromEntityPacket.class, packet -> Inventory.MIDDLE_INVENTORY_CLICK);
317321
this.packetTranslationMap.put(ServerboundSetCreativeModeSlotPacket.class, packet -> PacketPhase.General.CREATIVE_INVENTORY);
318322
this.packetTranslationMap.put(ServerboundContainerButtonClickPacket.class, packet -> PacketPhase.Inventory.ENCHANT_ITEM);
319323
this.packetTranslationMap.put(ServerboundSignUpdatePacket.class, packet -> PacketPhase.General.UPDATE_SIGN);

0 commit comments

Comments
 (0)