Search in sources :

Example 6 with Container

use of net.minecraft.world.Container in project SpongeCommon by SpongePowered.

the class BaseContainerBlockEntityMixin_API method toContainer.

// @formatter:off
@Override
public DataContainer toContainer() {
    final DataContainer container = super.toContainer();
    if (this.lockKey != null) {
        container.set(Constants.TileEntity.LOCK_CODE, ((LockCodeAccessor) this.lockKey).accessor$key());
    }
    final List<DataView> items = Lists.newArrayList();
    for (int i = 0; i < ((Container) this).getContainerSize(); i++) {
        final ItemStack stack = ((Container) this).getItem(i);
        if (!stack.isEmpty()) {
            // todo make a helper object for this
            final DataContainer stackView = DataContainer.createNew().set(Queries.CONTENT_VERSION, 1).set(Constants.TileEntity.SLOT, i).set(Constants.TileEntity.SLOT_ITEM, ((org.spongepowered.api.item.inventory.ItemStack) (Object) stack).toContainer());
            items.add(stackView);
        }
    }
    if (this.name != null) {
        container.set(Constants.TileEntity.LOCKABLE_CONTAINER_CUSTOM_NAME, this.name);
    }
    container.set(Constants.TileEntity.ITEM_CONTENTS, items);
    return container;
}
Also used : DataView(org.spongepowered.api.data.persistence.DataView) DataContainer(org.spongepowered.api.data.persistence.DataContainer) DataContainer(org.spongepowered.api.data.persistence.DataContainer) Container(net.minecraft.world.Container) ItemStack(net.minecraft.world.item.ItemStack)

Example 7 with Container

use of net.minecraft.world.Container in project SpongeCommon by SpongePowered.

the class DropperBlockMixin_Inventory method afterDispense.

@Surrogate
private void afterDispense(final ServerLevel worldIn, final BlockPos pos, final CallbackInfo callbackInfo, final BlockSourceImpl proxyblocksource, final DispenserBlockEntity dispensertileentity, final int i, final ItemStack itemstack, final ItemStack itemstack1) {
    // after setItem
    dispensertileentity.setItem(i, itemstack1);
    if (ShouldFire.TRANSFER_INVENTORY_EVENT_POST) {
        // Transfer worked if remainder is one less than the original stack
        if (itemstack1.getCount() == itemstack.getCount() - 1) {
            final TrackedInventoryBridge capture = InventoryUtil.forCapture(dispensertileentity);
            final Inventory sourceInv = ((Inventory) dispensertileentity);
            SlotTransaction sourceSlotTransaction = InventoryEventFactory.captureTransaction(capture, sourceInv, i, itemstack);
            final Direction enumfacing = worldIn.getBlockState(pos).getValue(DispenserBlock.FACING);
            final BlockPos blockpos = pos.relative(enumfacing);
            final Container iinventory = HopperBlockEntity.getContainerAt(worldIn, blockpos.getX(), blockpos.getY(), blockpos.getZ());
            InventoryEventFactory.callTransferPost(capture, sourceInv, ((Inventory) iinventory), itemstack, sourceSlotTransaction);
        }
    }
    // dont call setInventorySlotContents twice
    callbackInfo.cancel();
}
Also used : Container(net.minecraft.world.Container) TrackedInventoryBridge(org.spongepowered.common.bridge.world.inventory.container.TrackedInventoryBridge) BlockPos(net.minecraft.core.BlockPos) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Direction(net.minecraft.core.Direction) Inventory(org.spongepowered.api.item.inventory.Inventory) Surrogate(org.spongepowered.asm.mixin.injection.Surrogate)

Example 8 with Container

use of net.minecraft.world.Container in project SpongeCommon by SpongePowered.

the class ContainerMixin_Inventory_API method viewed.

@Override
public List<Inventory> viewed() {
    List<Inventory> list = new ArrayList<>();
    for (Container inv : ((ContainerBridge) this).bridge$getInventories().keySet()) {
        Inventory inventory = InventoryUtil.toInventory(inv, null);
        list.add(inventory);
    }
    return list;
}
Also used : Container(net.minecraft.world.Container) ArrayList(java.util.ArrayList) Inventory(org.spongepowered.api.item.inventory.Inventory) DefaultImplementedAdapterInventory(org.spongepowered.common.inventory.adapter.impl.DefaultImplementedAdapterInventory)

Aggregations

Container (net.minecraft.world.Container)8 ItemStack (net.minecraft.world.item.ItemStack)5 Ingredient (net.minecraft.world.item.crafting.Ingredient)3 ArrayList (java.util.ArrayList)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 JsonElement (com.google.gson.JsonElement)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 Supplier (java.util.function.Supplier)1 Component (net.kyori.adventure.text.Component)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 MenuProvider (net.minecraft.world.MenuProvider)1 SimpleMenuProvider (net.minecraft.world.SimpleMenuProvider)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 AbstractHorse (net.minecraft.world.entity.animal.horse.AbstractHorse)1