use of net.minecraft.world.inventory.InventoryMenu in project SpongeCommon by SpongePowered.
the class TransactionSink method logSlotTransaction.
/**
* Called with a created {@link SlotTransaction} that's been created and
* possibly already recorded by {@link TrackedContainerBridge#bridge$detectAndSendChanges(boolean)}
* performing transaction handling and submitting to be recorded through
* here. The caveat with this system is that since it's reliant on having
* the transactions created as a side effect of {@link AbstractContainerMenu#broadcastChanges()},
* it's possible that certain transactions are "too late" or remain uncaptured
* until the next tick.
*
* @param phaseContext The context
* @param newTransaction The slot transaction in relation to the menu
* @param abstractContainerMenu The container menu
*/
/*
Non-Javadoc: Known areas where we are keeping transactions recorded:
- commands - during CommandPhaseContext see below
- place/use ServerPlayerGameModeMixin_Tracker#useItemOn
- Dispenser equip PlayerEntityMixin_Inventory#setItemSlot
- eating etc. LivingEntityMixin_Inventory#completeUsingItem
- throw/use ServerGamePacketListenerImplMixin_Inventory#impl$onHandleUseItem
- breaking blocks ServerPlayerGameModeMixin_Tracker#impl$onMineBlock
- exp pickup with mending PlayerEntityMixin_Inventory#inventory$onTouch
- attack PlayerMixin#attack
- armor/shield damage LivingEntityMixin#bridge$damageEntity
- elytra damage LivingEntityMixin#inventory$onElytraUse
- consume arrow (BowItem#releaseUsing - shrink on stack) LivingEntityMixin#impl$onStopPlayerUsing
- villager trade select ServerGamePacketListenerImplMixin_Inventory#impl$onHandleSelectTrade
- close inventory adding back to inventory ServerPlayerEntityMixin_Inventory#impl$onCloseContainer
- use on entity - ServerGamePacketListenerImplMixin_Inventory#impl$onInteractAt/impl$onInteractOn
*/
default void logSlotTransaction(final PhaseContext<@NonNull ?> phaseContext, final SlotTransaction newTransaction, final AbstractContainerMenu abstractContainerMenu) {
// Inventory change during command
if (abstractContainerMenu instanceof InventoryMenu) {
if (phaseContext instanceof CommandPhaseContext) {
this.logPlayerInventoryChange(((InventoryMenuAccessor) abstractContainerMenu).accessor$owner(), PlayerInventoryTransaction.EventCreator.STANDARD);
}
if (phaseContext instanceof UnwindingPhaseContext) {
return;
}
if (phaseContext instanceof EntityTickContext) {
// TODO remove warning when we got all cases covered
SpongeCommon.logger().warn("Ignoring slot transaction on InventoryMenu during {}. {}\nNo Event will be fired for this", phaseContext.getClass().getSimpleName(), newTransaction);
return;
}
}
final ContainerSlotTransaction transaction = new ContainerSlotTransaction(abstractContainerMenu, newTransaction);
this.logTransaction(transaction);
}
use of net.minecraft.world.inventory.InventoryMenu in project SpongeCommon by SpongePowered.
the class CloseMenuTransaction method reopen.
private void reopen(final ServerPlayer player, final AbstractContainerMenu container) {
if (container.getSlot(0) == null) {
return;
}
if (!(container instanceof InventoryMenu)) {
// Inventory closed by client, reopen window and send container
player.containerMenu = container;
final Slot slot = container.getSlot(0);
final net.minecraft.world.Container slotInventory = slot.container;
final net.minecraft.network.chat.@Nullable Component title;
// TODO get name from last open
if (slotInventory instanceof MenuProvider) {
title = ((MenuProvider) slotInventory).getDisplayName();
} else {
// expected fallback for unknown types
title = null;
}
slotInventory.startOpen(player);
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), title));
// resync data to client
player.refreshContainer(container);
} else {
// TODO: Maybe print a warning or throw an exception here?
// The player gui cannot be opened from the
// server so allowing this event to be cancellable when the
// GUI has been closed already would result
// in opening the wrong GUI window.
}
}
use of net.minecraft.world.inventory.InventoryMenu in project SpongeCommon by SpongePowered.
the class RecipeManagerMixin_API method findMatchingRecipe.
@Override
@SuppressWarnings("unchecked")
public Optional<Recipe> findMatchingRecipe(final Inventory inventory, final ServerWorld world) {
Preconditions.checkNotNull(inventory);
Preconditions.checkNotNull(world);
if (inventory instanceof AbstractFurnaceBlockEntity) {
final net.minecraft.world.item.crafting.RecipeType<? extends AbstractCookingRecipe> type = ((AbstractFurnaceBlockEntityAccessor) inventory).accessor$recipeType();
return this.<Container, AbstractCookingRecipe>shadow$getRecipeFor((net.minecraft.world.item.crafting.RecipeType<AbstractCookingRecipe>) type, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof CampfireBlockEntity) {
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof CraftingMenu) {
final CraftingContainer craftingInventory = ((CraftingMenuAccessor) inventory).accessor$craftSlots();
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof InventoryMenu) {
final CraftingContainer craftingInventory = ((InventoryMenuAccessor) inventory).accessor$craftSlots();
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof StonecutterMenu) {
final Container stonecutterInventory = ((StonecutterMenu) inventory).container;
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.STONECUTTING, stonecutterInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
return Optional.empty();
}
Aggregations