Skip to content

Commit 5515ac3

Browse files
committed
Merge remote-tracking branch 'origin/api-10' into api-11
2 parents eeb2542 + b8f03ef commit 5515ac3

4 files changed

Lines changed: 73 additions & 2 deletions

File tree

src/main/java/org/spongepowered/common/inventory/custom/SpongeInventoryMenu.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ public boolean onClick(
232232
if (slot.isPresent()) {
233233
switch (clickTypeIn) {
234234
case SWAP:
235-
if (dragType >= 0 && dragType < 9) {
236-
final Optional<org.spongepowered.api.item.inventory.Slot> slot2 = container.slot(dragType);
235+
if (dragType >= 0 && dragType < 9 || dragType == 40) {
236+
final Optional<org.spongepowered.api.item.inventory.Slot> slot2 =
237+
((org.spongepowered.api.entity.living.player.Player) player).inventory().slot(dragType);
237238
if (slot2.isPresent() && this.keySwapHandler != null) {
238239
return this.keySwapHandler.handle(cause, container, slot.get(), slotId, ClickTypes.KEY_SWAP.get(), slot2.get());
239240
}

src/mixins/java/org/spongepowered/common/mixin/core/world/entity/LivingEntityMixin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
107107
@Shadow protected boolean dead;
108108
@Shadow protected int deathScore;
109109
@Shadow protected ItemStack useItem;
110+
@Shadow @Nullable private DamageSource lastDamageSource;
111+
@Shadow private long lastDamageStamp;
110112

111113
@Shadow public abstract AttributeInstance shadow$getAttribute(Attribute attribute);
112114
@Shadow public abstract void shadow$setHealth(float health);
@@ -726,4 +728,12 @@ protected void actuallyHurt(final DamageSource damageSource, final float damage)
726728
((Living) this).setRotation(event.toRotation());
727729
}
728730

731+
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/damagesource/CombatTracker;recheckStatus()V", shift = At.Shift.AFTER))
732+
private void impl$clearLastDamageSource(final CallbackInfo ci) {
733+
//Fix for MC-270896 - Players leak the last entity they took damage from
734+
if (this.lastDamageSource != null && this.shadow$level().getGameTime() - this.lastDamageStamp > 40L) {
735+
this.lastDamageSource = null;
736+
}
737+
}
738+
729739
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.common.mixin.inventory.impl.server.level;
26+
27+
import net.minecraft.core.NonNullList;
28+
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
29+
import net.minecraft.server.level.ServerPlayer;
30+
import net.minecraft.world.inventory.AbstractContainerMenu;
31+
import net.minecraft.world.item.ItemStack;
32+
import org.spongepowered.asm.mixin.Final;
33+
import org.spongepowered.asm.mixin.Mixin;
34+
import org.spongepowered.asm.mixin.Shadow;
35+
import org.spongepowered.asm.mixin.injection.At;
36+
import org.spongepowered.asm.mixin.injection.Inject;
37+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
38+
import org.spongepowered.common.inventory.adapter.impl.slots.SlotAdapter;
39+
import org.spongepowered.common.item.util.ItemStackUtil;
40+
41+
@Mixin(targets = "net/minecraft/server/level/ServerPlayer$1")
42+
public abstract class ServerPlayer_Mixin_Inventory {
43+
44+
// @formatter:off
45+
@Shadow @Final ServerPlayer this$0;
46+
// @formatter:on
47+
48+
@Inject(method = "sendInitialData", at = @At("RETURN"))
49+
private void inventory$sendOffhand(final AbstractContainerMenu containerMenu, final NonNullList<ItemStack> $$1, final ItemStack $$2, final int[] $$3, final CallbackInfo ci) {
50+
if (containerMenu == this.this$0.inventoryMenu) {
51+
return;
52+
}
53+
54+
final org.spongepowered.api.item.inventory.Slot offhand
55+
= ((org.spongepowered.api.entity.living.player.server.ServerPlayer) this.this$0).inventory().offhand();
56+
this.this$0.connection.send(
57+
new ClientboundContainerSetSlotPacket(-2, 0, ((SlotAdapter) offhand).getOrdinal(), ItemStackUtil.toNative(offhand.peek())));
58+
}
59+
}

src/mixins/resources/mixins.sponge.inventory.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"impl.common.entity.player.SpongeUserInventoryMixin_Lens_Bridge",
6464
"impl.common.inventory.custom.CarriedWrapperInventoryMixin_Adapter_Inventory",
6565
"impl.common.inventory.custom.CustomInventoryMixin_Lens_Inventory",
66+
"impl.server.level.ServerPlayer_Mixin_Inventory",
6667
"impl.world.ContainerMixin_Fabric_Inventory",
6768
"impl.world.TraitMixin_TrackedMenuBridge_Inventory",
6869
"impl.world.entity.LivingEntityMixin_EquipmentFabric_Inventory",

0 commit comments

Comments
 (0)