net.minecraft.entity.player.PlayerInventory Java Examples

The following examples show how to use net.minecraft.entity.player.PlayerInventory. 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: DryingRackContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void bindPlayerInventory(PlayerInventory playerInventory, int yOffset)
{
    for (int y = 0; y < 3; y++)
    {
        for (int x = 0; x < 9; x++)
        {
            addSlot(new Slot(playerInventory,
                    x + y * 9 + 9,
                    8 + x * 18, yOffset + y * 18));
        }
    }

    for (int x = 0; x < 9; x++)
    {
        addSlot(new Slot(playerInventory, x, 8 + x * 18, yOffset+ 58));
    }
}
 
Example #2
Source File: SawmillContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public SawmillContainer(int windowId, PlayerInventory playerInventory, IItemHandlerModifiable inventory, IIntArray dryTimes)
{
    super(TYPE, windowId);

    fields = dryTimes;

    wrappedInventory = new ChoppingContext(inventory, null, 0, 0, RANDOM);
    world = playerInventory.player.world;

    addSlot(new SlotItemHandler(inventory, 0, 56, 17));
    addSlot(new SawmillFuelSlot(inventory, 1, 56, 53));
    addSlot(new SawmillOutputSlot(inventory, 2, 116, 35));

    bindPlayerInventory(playerInventory);

    trackIntArray(fields);
}
 
Example #3
Source File: AutoFishHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private void updateBestRod()
{
	PlayerInventory inventory = MC.player.inventory;
	int selectedSlot = inventory.selectedSlot;
	ItemStack selectedStack = inventory.getStack(selectedSlot);
	
	// start with selected rod
	bestRodValue = getRodValue(selectedStack);
	bestRodSlot = bestRodValue > -1 ? selectedSlot : -1;
	
	// search inventory for better rod
	for(int slot = 0; slot < 36; slot++)
	{
		ItemStack stack = inventory.getStack(slot);
		int rodValue = getRodValue(stack);
		
		if(rodValue > bestRodValue)
		{
			bestRodValue = rodValue;
			bestRodSlot = slot;
		}
	}
}
 
Example #4
Source File: AutoToolHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private int getFallbackSlot()
{
	PlayerInventory inventory = MC.player.inventory;
	
	for(int slot = 0; slot < 9; slot++)
	{
		if(slot == inventory.selectedSlot)
			continue;
		
		ItemStack stack = inventory.getStack(slot);
		
		if(!isDamageable(stack))
			return slot;
	}
	
	return -1;
}
 
Example #5
Source File: AutoToolHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private void selectFallbackSlot()
{
	int fallbackSlot = getFallbackSlot();
	PlayerInventory inventory = MC.player.inventory;
	
	if(fallbackSlot == -1)
	{
		if(inventory.selectedSlot == 8)
			inventory.selectedSlot = 0;
		else
			inventory.selectedSlot++;
		
		return;
	}
	
	inventory.selectedSlot = fallbackSlot;
}
 
Example #6
Source File: TestDescription.java    From LibGui with MIT License 6 votes vote down vote up
public TestDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) {
	super(type, syncId, playerInventory, getBlockInventory(context), null);
	
	WGridPanel root = (WGridPanel)this.getRootPanel();
	
	root.add(WItemSlot.of(blockInventory, 0, 4, 1), 0, 1);

	root.add(new WButton(new LiteralText("Button A")), 0, 3, 4, 1);
	root.add(new WButton(new LiteralText("Button B")), 5, 3, 4, 1);
	root.add(new WButton(new LiteralText("Button C")), 0, 5, 4, 1);
	root.add(new WButton(new LiteralText("Button D")), 5, 5, 4, 1);
	root.add(new WTextField(new LiteralText("Type something...")), 0, 7, 5, 1);

	root.add(createPlayerInventoryPanel(), 0, 9);
	System.out.println(root.toString());

	this.getRootPanel().validate(this);
}
 
Example #7
Source File: MachineHandledScreen.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public MachineHandledScreen(C screenHandler, PlayerInventory playerInventory, World world, BlockPos pos, Text textComponent) {
    super(screenHandler, playerInventory, textComponent);
    assert isAllowed();
    this.pos = pos;
    this.world = world;

    if (this.handler.blockEntity != null) {
        ConfigurableElectricMachineBlockEntity entity = this.handler.blockEntity;

        ConfigurableElectricMachineBlockEntity.SecurityInfo security = entity.getSecurity();
        if (!security.hasOwner()) {
            security.setOwner(this.playerInventory.player);
            security.setPublicity(ConfigurableElectricMachineBlockEntity.SecurityInfo.Publicity.PRIVATE);
            sendSecurityUpdate(entity);
        } else if (security.getOwner().equals(playerInventory.player.getUuid())
                && !security.getUsername().equals(playerInventory.player.getEntityName())) {
            security.setUsername(playerInventory.player.getEntityName());
            sendSecurityUpdate(entity);
        }

        for (BlockFace face : BlockFace.values()) {
            sideOptions.put(face, ((ConfigurableElectricMachineBlock) world.getBlockState(pos).getBlock()).getOption(world.getBlockState(pos), face));
        }
    }
}
 
Example #8
Source File: SyncedGuiDescription.java    From LibGui with MIT License 5 votes vote down vote up
public SyncedGuiDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory) {
	super(type, syncId);
	this.blockInventory = null;
	this.playerInventory = playerInventory;
	this.world = playerInventory.player.world;
	this.propertyDelegate = null;//new ArrayPropertyDelegate(1);
}
 
Example #9
Source File: AutoToolHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private int getBestSlot(BlockPos pos, boolean useSwords, boolean repairMode)
{
	ClientPlayerEntity player = MC.player;
	PlayerInventory inventory = player.inventory;
	ItemStack heldItem = MC.player.getMainHandStack();
	
	BlockState state = BlockUtils.getState(pos);
	float bestSpeed = getMiningSpeed(heldItem, state);
	int bestSlot = -1;
	
	for(int slot = 0; slot < 9; slot++)
	{
		if(slot == inventory.selectedSlot)
			continue;
		
		ItemStack stack = inventory.getStack(slot);
		
		float speed = getMiningSpeed(stack, state);
		if(speed <= bestSpeed)
			continue;
		
		if(!useSwords && stack.getItem() instanceof SwordItem)
			continue;
		
		if(repairMode && isTooDamaged(stack))
			continue;
		
		bestSpeed = speed;
		bestSlot = slot;
	}
	
	return bestSlot;
}
 
Example #10
Source File: AutoFishHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void selectBestRod()
{
	PlayerInventory inventory = MC.player.inventory;
	
	if(bestRodSlot < 9)
	{
		inventory.selectedSlot = bestRodSlot;
		return;
	}
	
	int firstEmptySlot = inventory.getEmptySlot();
	
	if(firstEmptySlot != -1)
	{
		if(firstEmptySlot >= 9)
			IMC.getInteractionManager()
				.windowClick_QUICK_MOVE(36 + inventory.selectedSlot);
		
		IMC.getInteractionManager().windowClick_QUICK_MOVE(bestRodSlot);
		
	}else
	{
		IMC.getInteractionManager().windowClick_PICKUP(bestRodSlot);
		IMC.getInteractionManager()
			.windowClick_PICKUP(36 + inventory.selectedSlot);
		
		scheduledWindowClick = -bestRodSlot;
	}
}
 
Example #11
Source File: AutoTotemHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	IClientPlayerInteractionManager im = IMC.getInteractionManager();
	PlayerInventory inventory = MC.player.inventory;
	
	if(nextTickSlot != -1)
	{
		im.windowClick_PICKUP(nextTickSlot);
		nextTickSlot = -1;
	}
	
	ItemStack offhandStack = inventory.getStack(40);
	if(offhandStack.getItem() == Items.TOTEM_OF_UNDYING)
		return;
	
	if(MC.currentScreen instanceof HandledScreen
		&& !(MC.currentScreen instanceof AbstractInventoryScreen))
		return;
	
	for(int slot = 0; slot <= 36; slot++)
	{
		if(inventory.getStack(slot).getItem() != Items.TOTEM_OF_UNDYING)
			continue;
		
		int newTotemSlot = slot < 9 ? slot + 36 : slot;
		boolean offhandEmpty = offhandStack.isEmpty();
		
		im.windowClick_PICKUP(newTotemSlot);
		im.windowClick_PICKUP(45);
		
		if(!offhandEmpty)
			nextTickSlot = newTotemSlot;
		
		break;
	}
}
 
Example #12
Source File: AutoSwitchHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	PlayerInventory inventory = MC.player.inventory;
	
	if(inventory.selectedSlot == 8)
		inventory.selectedSlot = 0;
	else
		inventory.selectedSlot++;
}
 
Example #13
Source File: RecipeBook_1_12.java    From multiconnect with MIT License 5 votes vote down vote up
private int getOccupiedSlotWithRoomForStack(PlayerInventory playerInv, ItemStack stack) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_11_2) {
        if (canStackAddMore(playerInv.getStack(playerInv.selectedSlot), stack)) {
            return playerInv.selectedSlot;
        }
        for (int j = 0; j < playerInv.main.size(); j++) {
            if (canStackAddMore(playerInv.main.get(j), stack)) {
                return j;
            }
        }
        return -1;
    } else {
        return playerInv.getOccupiedSlotWithRoomForStack(stack);
    }
}
 
Example #14
Source File: LibGuiTest.java    From LibGui with MIT License 5 votes vote down vote up
@Override
public void onInitialize() {
	Registry.register(Registry.ITEM, new Identifier(MODID, "client_gui"), new GuiItem());
	
	GUI_BLOCK = new GuiBlock();
	Registry.register(Registry.BLOCK, new Identifier(MODID, "gui"), GUI_BLOCK);
	GUI_BLOCK_ITEM = new BlockItem(GUI_BLOCK, new Item.Settings().group(ItemGroup.MISC));
	Registry.register(Registry.ITEM, new Identifier(MODID, "gui"), GUI_BLOCK_ITEM);
	GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
	Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE);
	
	GUI_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "gui"), (int syncId, PlayerInventory inventory) -> {
		return new TestDescription(GUI_SCREEN_HANDLER_TYPE, syncId, inventory, ScreenHandlerContext.EMPTY);
	});

	Optional<ModContainer> containerOpt = FabricLoader.getInstance().getModContainer("jankson");
	if (containerOpt.isPresent()) {
		ModContainer jankson = containerOpt.get();
		System.out.println("Jankson root path: "+jankson.getRootPath());
		try {
			Files.list(jankson.getRootPath()).forEach((path)->{
				path.getFileSystem().getFileStores().forEach((store)->{
					System.out.println("        Filestore: "+store.name());
				});
				System.out.println("    "+path.toAbsolutePath());
			});
		} catch (IOException e) {
			e.printStackTrace();
		}
		Path modJson = jankson.getPath("/fabric.mod.json");
		System.out.println("Jankson fabric.mod.json path: "+modJson);
		System.out.println(Files.exists(modJson) ? "Exists" : "Does Not Exist");
	} else {
		System.out.println("Container isn't present!");
	}
}
 
Example #15
Source File: WPlayerInvPanel.java    From LibGui with MIT License 5 votes vote down vote up
/**
 * Constructs a player inventory panel.
 *
 * @param playerInventory the player inventory
 * @param label           the label widget, can be null
 * @since 2.0.0
 */
public WPlayerInvPanel(PlayerInventory playerInventory, @Nullable WWidget label) {
	int y = 0;

	this.label = label;
	if (label != null) {
		this.add(label, 0, 0, label.getWidth(), label.getHeight());
		y += label.getHeight();
	}

	inv = WItemSlot.ofPlayerStorage(playerInventory);
	hotbar = WItemSlot.of(playerInventory, 0, 9, 1);
	this.add(inv, 0, y);
	this.add(hotbar, 0, y + 58);
}
 
Example #16
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 #17
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 5 votes vote down vote up
private void dropItemFromSlot(int slot, boolean dropAll)
{
    PlayerInventory inv = player.inventory;
    if (!inv.getInvStack(slot).isEmpty())
        player.dropItem(inv.takeInvStack(slot,
                dropAll ? inv.getInvStack(slot).getCount() : 1
        ), false, true); // scatter, keep owner
}
 
Example #18
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 5 votes vote down vote up
public void drop(int selectedSlot, boolean dropAll)
{
    PlayerInventory inv = player.inventory;
    if (selectedSlot == -2) // all
    {
        for (int i = inv.getInvSize(); i >= 0; i--)
            dropItemFromSlot(i, dropAll);
    }
    else // one slot
    {
        if (selectedSlot == -1)
            selectedSlot = inv.selectedSlot;
        dropItemFromSlot(selectedSlot, dropAll);
    }
}
 
Example #19
Source File: ModificationTableContainer.java    From MiningGadgets with MIT License 5 votes vote down vote up
public ModificationTableContainer(int windowId, PlayerInventory playerInventory, PacketBuffer extraData) {
    super(ModContainers.MODIFICATIONTABLE_CONTAINER.get(), windowId);

    this.tileEntity = Minecraft.getInstance().world.getTileEntity(extraData.readBlockPos());
    this.playerInventory = new InvWrapper(playerInventory);

    setupContainerSlots();
    layoutPlayerInventorySlots(8, 84);
}
 
Example #20
Source File: ModificationTableContainer.java    From MiningGadgets with MIT License 5 votes vote down vote up
public ModificationTableContainer(int windowId, World world, BlockPos pos, PlayerInventory playerInventory) {
    super(ModContainers.MODIFICATIONTABLE_CONTAINER.get(), windowId);
    this.tileEntity = world.getTileEntity(pos);
    this.playerInventory = new InvWrapper(playerInventory);

    setupContainerSlots();
    layoutPlayerInventorySlots(10, 70);
}
 
Example #21
Source File: GuiEnderItemStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
public GuiEnderItemStorage(ContainerEnderItemStorage container, PlayerInventory playerInv, ITextComponent title) {
    super(container, playerInv, title);
    passEvents = false;

    if (container.chestInv.getSize() == 2) {
        ySize = 222;
    }
}
 
Example #22
Source File: ContainerEnderItemStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
public ContainerEnderItemStorage(int windowId, PlayerInventory playerInv, EnderItemStorage chestInv) {
    super(ModContent.containerItemStorage, windowId);
    this.chestInv = chestInv;
    chestInv.openInventory();

    switch (chestInv.getSize()) {
        case 0:
            for (int row = 0; row < 3; ++row) {
                for (int col = 0; col < 3; ++col) {
                    addSlot(new Slot(chestInv, col + row * 3, 62 + col * 18, 17 + row * 18));
                }
            }
            addPlayerSlots(playerInv, 84);
            break;
        case 1:
            for (int row = 0; row < 3; ++row) {
                for (int col = 0; col < 9; ++col) {
                    addSlot(new Slot(chestInv, col + row * 9, 8 + col * 18, 18 + row * 18));
                }
            }
            addPlayerSlots(playerInv, 85);
            break;
        case 2:
            for (int row = 0; row < 6; ++row) {
                for (int col = 0; col < 9; ++col) {
                    addSlot(new Slot(chestInv, col + row * 9, 8 + col * 18, 18 + row * 18));
                }
            }
            addPlayerSlots(playerInv, 140);
            break;
    }

}
 
Example #23
Source File: ContainerExtended.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void bindPlayerInventory(PlayerInventory inventoryPlayer, int x, int y) {
    for (int row = 0; row < 3; row++) {
        for (int col = 0; col < 9; col++) {
            addSlot(new Slot(inventoryPlayer, col + row * 9 + 9, x + col * 18, y + row * 18));
        }
    }
    for (int slot = 0; slot < 9; slot++) {
        addSlot(new Slot(inventoryPlayer, slot, x + slot * 18, y + 58));
    }
}
 
Example #24
Source File: ICCLContainerType.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public T create(int windowId, PlayerInventory inventory, MCDataInput packet) {
    if (factory instanceof ICCLContainerFactory) {
        return ((ICCLContainerFactory<T>) factory).create(windowId, inventory, packet);
    }
    return null;
}
 
Example #25
Source File: SawmillContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void bindPlayerInventory(PlayerInventory playerInventory)
{
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 9; ++j)
        {
            this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
        }
    }

    for (int k = 0; k < 9; ++k)
    {
        this.addSlot(new Slot(playerInventory, k, 8 + k * 18, 142));
    }
}
 
Example #26
Source File: DryingRackContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DryingRackContainer(int windowId, PlayerInventory playerInventory, IItemHandler inventory, IIntArray dryTimes)
{
    super(TYPE, windowId);

    dryTimeRemainingArray = dryTimes;

    addSlot(new SlotItemHandler(inventory, 0, 26, 34));
    addSlot(new SlotItemHandler(inventory, 1, 62, 34));
    addSlot(new SlotItemHandler(inventory, 2, 98, 34));
    addSlot(new SlotItemHandler(inventory, 3, 134, 34));

    bindPlayerInventory(playerInventory, 84);

    this.trackIntArray(dryTimeRemainingArray);
}
 
Example #27
Source File: ContainerExtended.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void bindPlayerInventory(PlayerInventory inventoryPlayer) {
    bindPlayerInventory(inventoryPlayer, 8, 84);
}
 
Example #28
Source File: SawmillTileEntity.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
@Override
public Container createMenu(int windowId, PlayerInventory playerInventory, PlayerEntity player)
{
    return new SawmillContainer(windowId, this, playerInventory);
}
 
Example #29
Source File: ElectricCompressorScreen.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public ElectricCompressorScreen(ElectricCompressorScreenHandler handler, PlayerInventory inv, Text title) {
    super(handler, inv, inv.player.world, handler.blockEntity.getPos(), title);
    this.backgroundHeight = 199;
}
 
Example #30
Source File: ICCLContainerFactory.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
default T create(int windowId, PlayerInventory inventory) {
    return create(windowId, inventory, null);
}