use of org.spongepowered.common.accessor.world.inventory.AbstractContainerMenuAccessor in project SpongeCommon by SpongePowered.
the class SpongeInventoryMenu method setCurrentInventory.
@Override
public void setCurrentInventory(ViewableInventory inventory) {
if (inventory.getClass().equals(this.inventory.getClass()) && inventory instanceof ViewableCustomInventory && inventory.capacity() == this.inventory.capacity()) {
this.inventory = inventory;
for (Map.Entry<Container, ServerPlayer> entry : this.tracked.entrySet()) {
final net.minecraft.world.inventory.AbstractContainerMenu container = (net.minecraft.world.inventory.AbstractContainerMenu) entry.getKey();
final ServerPlayer player = entry.getValue();
// create a new container for the viewable inventory
final net.minecraft.world.inventory.AbstractContainerMenu newContainer = ((ViewableCustomInventory) inventory).createMenu(-1, ((Player) player).inventory, (Player) player);
for (int i = 0; i < inventory.capacity(); i++) {
// And put its slots into the old container
final Slot slot = newContainer.slots.get(i);
container.slots.set(i, slot);
// Update Container items
((AbstractContainerMenuAccessor) container).accessor$lastSlots().set(i, slot.getItem());
}
// send update to Client
for (ContainerListener listener : ((AbstractContainerMenuAccessor) container).accessor$containerListeners()) {
listener.refreshContainer(container, ((AbstractContainerMenuAccessor) container).accessor$lastSlots());
}
}
} else {
// Get all distinct players and reopen inventory for them
this.inventory = inventory;
this.reopen();
}
}
Aggregations