net.minecraft.inventory.Inventory Java Examples

The following examples show how to use net.minecraft.inventory.Inventory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnergyStorageModuleScreenHandler.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public EnergyStorageModuleScreenHandler(int syncId, PlayerEntity playerEntity, EnergyStorageModuleBlockEntity blockEntity) {
    super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.ENERGY_STORAGE_MODULE_HANDLER);
    Inventory inventory = blockEntity.getInventory().asInventory();

    // Battery slots
    this.addSlot(new ChargeSlot(inventory, 0, 18 * 6 - 6, 18 + 6));
    this.addSlot(new ChargeSlot(inventory, 1, 18 * 6 - 6, 18 * 2 + 12));

    // Player inventory slots
    int playerInvYOffset = 84;

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18));
        }
    }

    // Hotbar slots
    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58));
    }
}
 
Example #2
Source File: DrawCommand.java    From fabric-carpet with MIT License 6 votes vote down vote up
private static int setBlock(
        ServerWorld world, BlockPos.Mutable mbpos, int x, int y, int z,
        BlockStateArgument block, Predicate<CachedBlockPosition> replacement,
        List<BlockPos> list
)
{
    mbpos.set(x, y, z);
    int success=0;
    if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true)))
    {
        BlockEntity tileentity = world.getBlockEntity(mbpos);
        if (tileentity instanceof Inventory)
        {
            ((Inventory) tileentity).clear();
        }
        if (block.setBlockState(world, mbpos, 2))
        {
            list.add(mbpos.toImmutable());
            ++success;
        }
    }

    return success;
}
 
Example #3
Source File: MixinBlock.java    From Sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
public <X> Mono<X> sbx$getComponent(WorldReader reader, Position position, BlockState state, Component<X> component, Mono<Direction> side) {
    if (component == Components.INVENTORY_COMPONENT) {
        if (this instanceof InventoryProvider) {
            SidedInventory inventory = ((InventoryProvider) this).getInventory((net.minecraft.block.BlockState) state, (IWorld) reader, (BlockPos) position);
            if (side.isPresent())
                return Mono.of(new SidedRespective(inventory, side.get())).cast();
            return Mono.of(new V2SInventory(inventory)).cast();
        }
        net.minecraft.block.entity.BlockEntity entity = ((BlockView) reader).getBlockEntity((BlockPos) position);
        if (entity instanceof Inventory) {
            if (side.isPresent() && entity instanceof SidedInventory)
                return Mono.of(new SidedRespective((SidedInventory) entity, side.get())).cast();
            return Mono.of(new V2SInventory((Inventory) entity)).cast();
        }
    }
    if (component == Components.FLUID_COMPONENT) {
        if (this instanceof Waterloggable) {
            FluidLoggingContainer container = new FluidLoggingContainer((FluidLoggable) this, reader, position, state, side);
            return Mono.of(container).cast();
        }
    }
    return Mono.empty();
}
 
Example #4
Source File: BasicSolarPanelScreenHandler.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public BasicSolarPanelScreenHandler(int syncId, PlayerEntity playerEntity, BasicSolarPanelBlockEntity blockEntity) {
    super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.BASIC_SOLAR_PANEL_HANDLER);
    Inventory inventory = blockEntity.getInventory().asInventory();
    addProperty(status);

    this.addSlot(new ChargeSlot(inventory, 0, 8, 53));

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
        }
    }

    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 142));
    }
}
 
Example #5
Source File: CoalGeneratorScreenHandler.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public CoalGeneratorScreenHandler(int syncId, PlayerEntity playerEntity, CoalGeneratorBlockEntity generator) {
    super(syncId, playerEntity, generator, GalacticraftScreenHandlerTypes.COAL_GENERATOR_HANDLER);
    Inventory inventory = blockEntity.getInventory().asInventory();
    addProperty(status);
    // Coal Generator fuel slot
    this.addSlot(new ItemSpecificSlot(inventory, 0, 8, 72, fuel));
    this.addSlot(new ChargeSlot(inventory, 1, 8, 8));

    // Player inventory slots
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18));
        }
    }

    // Hotbar slots
    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 152));
    }

}
 
Example #6
Source File: OxygenCollectorScreenHandler.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public OxygenCollectorScreenHandler(int syncId, PlayerEntity playerEntity, OxygenCollectorBlockEntity blockEntity) {
    super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.OXYGEN_COLLECTOR_HANDLER);
    Inventory inventory = blockEntity.getInventory().asInventory();

    addProperty(status);
    addProperty(oxygen);
    addProperty(lastCollectAmount);

    // Charging slot
    this.addSlot(new ChargeSlot(inventory, 0, 20, 70));

    // Player inventory slots
    int playerInvYOffset = 99;

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18));
        }
    }

    // Hotbar slots
    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58));
    }
}
 
Example #7
Source File: ShapedCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
private boolean matchesSmall(Inventory inv, int int_1, int int_2, boolean boolean_1) {
    int invWidth = 3;
    int invHeight = 3;

    for (int int_3 = 0; int_3 < invWidth; ++int_3) {
        for (int int_4 = 0; int_4 < invHeight; ++int_4) {
            int int_5 = int_3 - int_1;
            int int_6 = int_4 - int_2;
            Ingredient ingredient_1 = Ingredient.EMPTY;
            if (int_5 >= 0 && int_6 >= 0 && int_5 < this.width && int_6 < this.height) {
                if (boolean_1) {
                    ingredient_1 = this.ingredients.get(this.width - int_5 - 1 + int_6 * this.width);
                } else {
                    ingredient_1 = this.ingredients.get(int_5 + int_6 * this.width);
                }
            }

            if (!ingredient_1.test(inv.getStack(int_3 + int_4 * invWidth))) {
                return false;
            }
        }
    }

    return true;
}
 
Example #8
Source File: ShapedCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public boolean matches(Inventory inv, World world_1) {
    int invWidth = 3;
    int invHeight = 3;

    for (int x = 0; x <= invWidth - this.width; ++x) {
        for (int y = 0; y <= invHeight - this.height; ++y) {
            if (this.matchesSmall(inv, x, y, true)) {
                return true;
            }

            if (this.matchesSmall(inv, x, y, false)) {
                return true;
            }
        }
    }

    return false;
}
 
Example #9
Source File: WItemSlot.java    From LibGui with MIT License 5 votes vote down vote up
public static WItemSlot outputOf(Inventory inventory, int index) {
	WItemSlot w = new WItemSlot();
	w.inventory = inventory;
	w.startIndex = index;
	w.big = true;
	
	return w;
}
 
Example #10
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Inventory getOutputInventory() {
    Vec3d offsetToInventory = getBlockBelowCartOffset();
    //The visual rotation point of the minecart is roughly 0.5 above its feet (determined visually ingame)
    //Search 0.5 Blocks below the feet for an inventory
    Inventory inv =  HopperBlockEntity.getInventoryAt(this.world, this.getX() + offsetToInventory.x, this.getY() + 0.5 + offsetToInventory.y, this.getZ() + offsetToInventory.z);

    //There is probably a way nicer way to determine the access side of the target inventory
    if(inv instanceof BlockEntity){
        BlockPos pos = ((BlockEntity) inv).getPos();
        if(pos.getY() < MathHelper.floor(this.getY()))
            outputDirection = Direction.DOWN;
        else if(pos.getX() > MathHelper.floor(this.getX()))
            outputDirection = Direction.EAST;
        else if(pos.getX() < MathHelper.floor(this.getX()))
            outputDirection = Direction.WEST;
        else if(pos.getZ() > MathHelper.floor(this.getZ()))
            outputDirection = Direction.SOUTH;
        else if(pos.getZ() < MathHelper.floor(this.getZ()))
            outputDirection = Direction.NORTH;
        else outputDirection = Direction.DOWN;
    }else
        outputDirection = Direction.DOWN;



    return inv;
}
 
Example #11
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean insert(){
    if(!this.isInvEmpty()){
        Inventory inventory_1 = this.getOutputInventory();
        if (inventory_1 == null) {
            return false;
        } else {
            Direction direction_1 = getLastOutputDirection().getOpposite();
            if (this.isInventoryFull(inventory_1, direction_1)) {
                return false;
            } else {
                for(int int_1 = 0; int_1 < this.getInvSize(); ++int_1) {
                    if (!this.getInvStack(int_1).isEmpty()) {
                        ItemStack itemStack_1 = this.getInvStack(int_1).copy();
                        ItemStack itemStack_2 = transfer(this, inventory_1, this.takeInvStack(int_1, 1), direction_1);
                        if (itemStack_2.isEmpty()) {
                            inventory_1.markDirty();
                            return true;
                        }

                        this.setInvStack(int_1, itemStack_1);
                    }
                }

                return false;
            }
        }
    }
    return false;
}
 
Example #12
Source File: ServerPlayNetworkHandlerMixin.java    From the-hallow with MIT License 5 votes vote down vote up
private boolean isPlayerWearingCostume(PlayerEntity player) {
	for (int i = 0; i < 4; i++) {
		if (HallowedTags.Items.COSTUMES.contains(player.inventory.armor.get(i).getItem()))
			return true;
	}
	Inventory inv = TrinketsApi.getTrinketsInventory(player);
	for (int i = 0; i < inv.getInvSize(); i++) {
		if (HallowedTags.Items.COSTUMES.contains(inv.getInvStack(i).getItem())) return true;
	}
	return false;
}
 
Example #13
Source File: SyncedGuiDescription.java    From LibGui with MIT License 5 votes vote down vote up
public SyncedGuiDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, Inventory blockInventory, PropertyDelegate propertyDelegate) {
	super(type, syncId);
	this.blockInventory = blockInventory;
	this.playerInventory = playerInventory;
	this.world = playerInventory.player.world;
	this.propertyDelegate = propertyDelegate;
	if (propertyDelegate!=null && propertyDelegate.size()>0) this.addProperties(propertyDelegate);
}
 
Example #14
Source File: WItemSlot.java    From LibGui with MIT License 5 votes vote down vote up
public WItemSlot(Inventory inventory, int startIndex, int slotsWide, int slotsHigh, boolean big) {
	this.inventory = inventory;
	this.startIndex = startIndex;
	this.slotsWide = slotsWide;
	this.slotsHigh = slotsHigh;
	this.big = big;
	//this.ltr = ltr;
}
 
Example #15
Source File: WItemSlot.java    From LibGui with MIT License 5 votes vote down vote up
public static WItemSlot of(Inventory inventory, int index) {
	WItemSlot w = new WItemSlot();
	w.inventory = inventory;
	w.startIndex = index;
	
	return w;
}
 
Example #16
Source File: WItemSlot.java    From LibGui with MIT License 5 votes vote down vote up
public static WItemSlot of(Inventory inventory, int startIndex, int slotsWide, int slotsHigh) {
	WItemSlot w = new WItemSlot();
	w.inventory = inventory;
	w.startIndex = startIndex;
	w.slotsWide = slotsWide;
	w.slotsHigh = slotsHigh;
	
	return w;
}
 
Example #17
Source File: CircuitFabricatorScreenHandler.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public CircuitFabricatorScreenHandler(int syncId, PlayerEntity playerEntity, CircuitFabricatorBlockEntity blockEntity) {
    super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.CIRCUIT_FABRICATOR_HANDLER);
    addProperty(progress);
    addProperty(status);
    Inventory inventory = blockEntity.getInventory().asInventory();
    // Energy slot
    this.addSlot(new ChargeSlot(inventory, 0, 8, 79));
    this.addSlot(new ItemSpecificSlot(inventory, 1, 8, 15, Items.DIAMOND));
    this.addSlot(new ItemSpecificSlot(inventory, 2, 8 + (18 * 3), 79, GalacticraftItems.RAW_SILICON));
    this.addSlot(new ItemSpecificSlot(inventory, 3, 8 + (18 * 3), 79 - 18, GalacticraftItems.RAW_SILICON));
    this.addSlot(new ItemSpecificSlot(inventory, 4, 8 + (18 * 6), 79 - 18, Items.REDSTONE));
    this.addSlot(new ItemSpecificSlot(inventory, 5, 8 + (18 * 7), 15, materials));
    this.addSlot(new FurnaceOutputSlot(playerEntity, inventory, 6, 8 + (18 * 8), 79));


    // Player inventory slots
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 110 + i * 18));
        }
    }

    // Hotbar slots
    for (int i = 0; i < 9; ++i) {
        this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 168));
    }

}
 
Example #18
Source File: WItemSlot.java    From LibGui with MIT License 5 votes vote down vote up
/**
 * Creates a 9x3 slot widget from the "main" part of a player inventory.
 *
 * @param inventory the player inventory
 * @return the created slot widget
 * @see WPlayerInvPanel
 */
public static WItemSlot ofPlayerStorage(Inventory inventory) {
	WItemSlot w = new WItemSlot();
	w.inventory = inventory;
	w.startIndex = 9;
	w.slotsWide = 9;
	w.slotsHigh = 3;
	//w.ltr = false;
	
	return w;
}
 
Example #19
Source File: CompressorBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private ItemStack getResultFromRecipeStack(Inventory inv) {
    // Once this method has been called, we have verified that either a shapeless or shaped recipe is present with isValidRecipe. Ignore the warning on getShapedRecipe(inv).get().

    Optional<ShapelessCompressingRecipe> shapelessRecipe = getShapelessRecipe(inv);
    if (shapelessRecipe.isPresent()) {
        return shapelessRecipe.get().craft(inv);
    }
    return getShapedRecipe(inv).orElseThrow(() -> new IllegalStateException("Neither a shapeless recipe or shaped recipe was present when getResultFromRecipeStack was called. This should never happen, as isValidRecipe should have been called first. That would have prevented this.")).craft(inv);
}
 
Example #20
Source File: ShapelessCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public boolean matches(Inventory inv, World world_1) {
    RecipeFinder recipeFinder_1 = new RecipeFinder();
    int int_1 = 0;

    for (int int_2 = 0; int_2 < inv.size(); ++int_2) {
        ItemStack itemStack_1 = inv.getStack(int_2);
        if (!itemStack_1.isEmpty()) {
            ++int_1;
            recipeFinder_1.addItem(itemStack_1);
        }
    }

    return int_1 == this.input.size() && recipeFinder_1.findRecipe(this, null);
}
 
Example #21
Source File: CmdPeek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	ItemStack item = mc.player.inventory.getCurrentItem();
	
	if (!(item.getItem() instanceof BlockItem)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	if (!(((BlockItem) item.getItem()).getBlock() instanceof ContainerBlock)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	NonNullList<ItemStack> items = NonNullList.withSize(27, new ItemStack(Items.AIR));
	CompoundNBT nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundNBT itemnbt = nbt.getCompound("BlockEntityTag");
		if (itemnbt.contains("Items")) ItemStackHelper.loadAllItems(itemnbt, items);
	}
	
	Inventory inv = new Inventory(items.toArray(new ItemStack[27]));
	
	BleachQueue.queue.add(() -> {
		mc.displayGuiScreen(new ShulkerBoxScreen(
				new ShulkerBoxContainer(420, mc.player.inventory, inv),
				mc.player.inventory,
				item.getDisplayName()));
	});
}
 
Example #22
Source File: NBTSerializableValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static int validateSlot(int slot, Inventory inv)
{
    int invSize = inv.getInvSize();
    if (slot < 0)
        slot = invSize + slot;
    if (slot < 0 || slot >= invSize)
        return inv.getInvSize(); // outside of inventory
    return slot;
}
 
Example #23
Source File: NBTSerializableValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
InventoryLocator(Object owner, BlockPos pos, Inventory i, int o, boolean isEnder)
{
    this.owner = owner;
    position = pos;
    inventory = i;
    offset = o;
    this.isEnder = isEnder;
}
 
Example #24
Source File: ElectricCompressorBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public ItemStack getResultFromRecipeStack(Inventory inv) {
    // Once this method has been called, we have verified that either a shapeless or shaped recipe is present with isValidRecipe. Ignore the warning on getShapedRecipe(inv).get().

    Optional<ShapelessCompressingRecipe> shapelessRecipe = getShapelessRecipe(inv);
    if (shapelessRecipe.isPresent()) {
        return shapelessRecipe.get().craft(inv);
    }
    return getShapedRecipe(inv).orElseThrow(() -> new IllegalStateException("Neither a shapeless recipe or shaped recipe was present when getResultFromRecipeStack was called. This should never happen, as isValidRecipe should have been called first. That would have prevented this.")).craft(inv);
}
 
Example #25
Source File: VoidContainer.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onContentChanged(Inventory inventory_1) { }
 
Example #26
Source File: ElectricCompressorBlockEntity.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private Optional<ShapelessCompressingRecipe> getShapelessRecipe(Inventory input) {
    return this.world.getRecipeManager().getFirstMatch(GalacticraftRecipes.SHAPELESS_COMPRESSING_TYPE, input, this.world);
}
 
Example #27
Source File: ValidatedSlot.java    From LibGui with MIT License 4 votes vote down vote up
public ValidatedSlot(Inventory inventory, int index, int x, int y) {
	super(inventory, index, x, y);
	if (inventory==null) throw new IllegalArgumentException("Can't make an itemslot from a null inventory!");
	this.slotNumber = index;
}
 
Example #28
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static IntStream getAvailableSlots(Inventory inventory_1, Direction direction_1) {
    return inventory_1 instanceof SidedInventory ? IntStream.of(((SidedInventory)inventory_1).getInvAvailableSlots(direction_1)) : IntStream.range(0, inventory_1.getInvSize());
}
 
Example #29
Source File: NBTSerializableValue.java    From fabric-carpet with MIT License 4 votes vote down vote up
InventoryLocator(Object owner, BlockPos pos, Inventory i, int o)
{
    this(owner, pos, i, o, false);
}
 
Example #30
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isInventoryFull(Inventory inventory_1, Direction direction_1) {
    return getAvailableSlots(inventory_1, direction_1).allMatch((int_1) -> {
        ItemStack itemStack_1 = inventory_1.getInvStack(int_1);
        return itemStack_1.getCount() >= itemStack_1.getMaxCount();
    });
}