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;
}
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();
}
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;
}
Aggregations