Posted April 3, 20214 yr Basically, I have some UI with area where player can place and move items as it want. This area has no grid and slots at all. I even can say, that these objects inside that area not exactly items, they just have item icons. However I had to write container to be able to display player inventory on my screen. Now I want to be able to take and add items to mouse slot on my own whenever I want, but PlayerInventory seems to have only getter getItemStack. Below you can see my hacky implementation, where I'm emulating clicks on some transition slot. It, actually, doesn't work completely. Despite the fact that I'm cleaning my transition slot, sometimes I still have some "trash" inside it. Taking items to mouse doesn't work too, sometimes. Does containers have server-side logic? It all just looks like I'm working with invalid remote data private final Inventory transitionInventory = new Inventory(1); private final Slot transitionSlot = new Slot(transitionInventory, 0, -10000, -10000); public void putItemFromScreen(ResearchTableScreen screen, int mouseX, int mouseY) { screen.mouseClicked(screen.getGuiLeft() + transitionSlot.xPos, screen.getGuiTop() + transitionSlot.yPos, 1); screen.mouseReleased(screen.getGuiLeft() + transitionSlot.xPos, screen.getGuiTop() + transitionSlot.yPos, 1); if (!transitionSlot.getStack().isEmpty()) { ResearchTableEntity.ItemState itemState = new ResearchTableEntity.ItemState(); itemState.item = transitionSlot.getStack().copy(); itemState.pos = screen.getTableRect().getLocalPointLocation(mouseX, mouseY); itemState.pos.x = Utils.clamp(itemState.pos.x, 8, screen.getTableRect().width - 8); itemState.pos.y = Utils.clamp(itemState.pos.y, 8, screen.getTableRect().height - 8); researchTableEntity.putItemState(itemState); transitionInventory.clear(); } } public void putItemToScreen(ResearchTableScreen screen, ResearchTableEntity.ItemState itemState) { PlayerInventory playerInventory = Minecraft.getInstance().player.inventory; if (itemState != null && playerInventory.getItemStack().isEmpty()) { transitionSlot.putStack(itemState.item); screen.mouseClicked(screen.getGuiLeft() + transitionSlot.xPos, screen.getGuiTop() + transitionSlot.yPos, 1); screen.mouseReleased(screen.getGuiLeft() + transitionSlot.xPos, screen.getGuiTop() + transitionSlot.yPos, 1); researchTableEntity.removeItemState(itemState); transitionInventory.clear(); } } Edited April 3, 20214 yr by Soft-fur dragon closed
April 3, 20214 yr Author Don't know why, but I did not noticed setItemStack function... However, it still doesn't work and my question about network is still relevant P.S. This is my new code. It being called from UI public void putItemFromScreen(ResearchTableScreen screen, int mouseX, int mouseY) { PlayerInventory playerInventory = Minecraft.getInstance().player.inventory; if (!playerInventory.getItemStack().isEmpty()) { ResearchTableEntity.ItemState itemState = new ResearchTableEntity.ItemState(); itemState.item = playerInventory.getItemStack().copy(); itemState.item.setCount(1); playerInventory.getItemStack().shrink(1); itemState.pos = screen.getTableRect().getLocalPointLocation(mouseX, mouseY); itemState.pos.x = Utils.clamp(itemState.pos.x, 8, screen.getTableRect().width - 8); itemState.pos.y = Utils.clamp(itemState.pos.y, 8, screen.getTableRect().height - 8); researchTableEntity.putItemState(itemState); } } public void putItemToScreen(ResearchTableScreen screen, ResearchTableEntity.ItemState itemState) { PlayerInventory playerInventory = Minecraft.getInstance().player.inventory; if (itemState != null && (playerInventory.getItemStack().isEmpty() || playerInventory.getItemStack().isItemEqual(itemState.item))) { if (playerInventory.getItemStack().isEmpty()) { playerInventory.setItemStack(itemState.item.copy()); playerInventory.getItemStack().setCount(1); } else { playerInventory.getItemStack().grow(1); } researchTableEntity.removeItemState(itemState); } }
April 3, 20214 yr Author Yes. Player inventory have network part. I have to send messages to server and perform all mouse item modifications there. P.S. no need to perform them on both client and server, server would be enough
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.