Fix anvil rename warnings
This commit is contained in:
1 parent
5e56133f34
commit
8e2567bd0d
3 files changed
+70
No files matched your search
+7
@@ -78,6 +78,7 @@ import org.spongepowered.common.event.tracking.context.transaction.inventory.Con
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.CraftingPreviewTransaction;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.CraftingTransaction;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.DropFromPlayerInventoryTransaction;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.ExplicitInventoryOmittedTransaction;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.OpenMenuTransaction;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.PlaceRecipeTransaction;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.inventory.PlayerInventoryTransaction;
|
||||
@@ -406,4 +407,10 @@ interface TransactionSink {
|
||||
final CraftingTransaction transaction = new CraftingTransaction(player, craftedStack, craftInv, lastRecipe);
|
||||
this.logTransaction(transaction);
|
||||
}
|
||||
|
||||
default EffectTransactor logIgnoredInventory(AbstractContainerMenu containerMenu) {
|
||||
final ExplicitInventoryOmittedTransaction transaction = new ExplicitInventoryOmittedTransaction(containerMenu);
|
||||
this.logTransaction(transaction);
|
||||
return this.pushEffect(new ResultingTransactionBySideEffect(InventoryEffect.getInstance()));
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.common.event.tracking.context.transaction.inventory;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.item.inventory.container.ClickContainerEvent;
|
||||
import org.spongepowered.common.event.tracking.PhaseContext;
|
||||
import org.spongepowered.common.event.tracking.context.transaction.GameTransaction;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ExplicitInventoryOmittedTransaction extends ContainerBasedTransaction {
|
||||
public ExplicitInventoryOmittedTransaction(
|
||||
final AbstractContainerMenu menu
|
||||
) {
|
||||
super(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClickContainerEvent> generateEvent(
|
||||
final PhaseContext<@NonNull ?> context, @Nullable final GameTransaction<@NonNull ?> parent,
|
||||
final ImmutableList<GameTransaction<ClickContainerEvent>> gameTransactions, final Cause currentCause
|
||||
) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
+11
@@ -38,6 +38,7 @@ import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.inventory.MerchantMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -152,6 +153,16 @@ public class ServerGamePacketListenerImplMixin_Inventory {
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "handleRenameItem(Lnet/minecraft/network/protocol/game/ServerboundRenameItemPacket;)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AnvilMenu;setItemName(Ljava/lang/String;)V"))
|
||||
private void impl$onHandleRenameItem(final AnvilMenu menu, final String name) {
|
||||
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
|
||||
final TransactionalCaptureSupplier transactor = context.getTransactor();
|
||||
try (EffectTransactor ignored = transactor.logIgnoredInventory(this.player.containerMenu)) {
|
||||
menu.setItemName(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleSelectTrade", at = @At("RETURN"))
|
||||
private void impl$onHandleSelectTrade(final ServerboundSelectTradePacket param0, final CallbackInfo ci) {
|
||||
if (this.player.containerMenu instanceof MerchantMenu) {
|
||||
|
||||
Reference in new issue
Block a user