Search in sources :

Example 1 with PlayerInventoryBridge

use of org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_Inventory method impl$getSpongeSlot.

// -- small bridge-like methods
@SuppressWarnings("ConstantConditions")
@Override
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
    final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
    final PlayerInventoryBridge inventory = (PlayerInventoryBridge) ((net.minecraft.server.level.ServerPlayer) (Object) this).inventory;
    final Lens lens = ((InventoryAdapter) inventory).inventoryAdapter$getRootLens();
    final Fabric fabric = ((InventoryAdapter) inventory).inventoryAdapter$getFabric();
    if (lens instanceof PlayerInventoryLens) {
        final SlotLens slotLens = ((PlayerInventoryLens) lens).getEquipmentLens().getSlotLens(equipmentType);
        return slotLens.getAdapter(fabric, (Inventory) inventory);
    }
    throw new IllegalStateException("Unknown Lens for Player Inventory: " + lens.getClass().getName());
}
Also used : PlayerInventoryBridge(org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Fabric(org.spongepowered.common.inventory.fabric.Fabric) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 2 with PlayerInventoryBridge

use of org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge in project SpongeCommon by SpongePowered.

the class ServerScheduler method tick.

@Override
public void tick() {
    super.tick();
    for (final Player player : Sponge.server().onlinePlayers()) {
        try (final EntityTickContext context = TickPhase.Tick.ENTITY.createPhaseContext(PhaseTracker.SERVER).source(player)) {
            context.buildAndSwitch();
            // Detect Changes on PlayerInventories marked as dirty.
            ((PlayerInventoryBridge) ((net.minecraft.world.entity.player.Player) player).inventory).bridge$cleanupDirty();
        }
    }
}
Also used : EntityTickContext(org.spongepowered.common.event.tracking.phase.tick.EntityTickContext) Player(org.spongepowered.api.entity.living.player.Player) PlayerInventoryBridge(org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge)

Aggregations

PlayerInventoryBridge (org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge)2 Player (org.spongepowered.api.entity.living.player.Player)1 EquipmentType (org.spongepowered.api.item.inventory.equipment.EquipmentType)1 EntityTickContext (org.spongepowered.common.event.tracking.phase.tick.EntityTickContext)1 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)1 Fabric (org.spongepowered.common.inventory.fabric.Fabric)1 Lens (org.spongepowered.common.inventory.lens.Lens)1 PlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens)1 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)1