Jump to content

Zemelua

Members
  • Posts

    190
  • Joined

  • Last visited

Everything posted by Zemelua

  1. I have created a Container with a FluidTank Slot. In order to draw this on the Screen, I need to get the texture of the Fluid and draw it transparently in the case of water. 1. How do I get the texture of a fluid? 2. How can I draw transparent (and animate) water?
  2. I think the problem is here(https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/capability/storage/FluidTankHandlerStorage.java). The instance argument passed by IStorage#writeNBT is incorrect. When is this method called? Where do the passed arguments come from? I'm sorry to repeat, but please help me someone.
  3. I did some research, but the data is still not saved ... The data of ItemStackHandler seems to be saved properly. When is IStorage#writeNBT called and where does the instance passed to the instance get from? The instance may not have been passed in properly and may not be able to save the data.
  4. Here is my code. FluidTankHandler#fill fills the holding FluidTank in order, but that doesn't seem to work. The behavior I want to implement is that when the first FluidTank is full, the second FluidTank will be filled. However, now it is put in every Fluid Tank one by one, and after that, the water does not increase no matter how many times it is repeated. Does anyone know what's going on? FluidTankHandler class: https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/fluid/FluidTankHandler.java Mod fluid capability: https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/capability/UMUCapabilities.java BackpackItem class (Testing FluidTankHandler behavior in onItemUse method: https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/item/BackpackItem.java
  5. I've fixed the code so that item operations can now be done normally. However, the backpack inventory operations that you were equipped with when you opened the inventory are saved, but the inventory operations for the backpack that you replaced in that inventory after opening the inventory are not saved. I was wondering if the inventory I changed later wouldn't be saved because the inventory I saved when I opened the container was saved somewhere else, but I couldn't find a match by tracing the code in the IDE. did. Does anyone know why the modified inventory isn't saved? Container class: Slot class:
  6. There are the following container slots, and items can be displayed in the slots by changing the backpack. However, if you try to move an item in the backpack slot, you will not be able to pick it up, and if you move it from the inventory to the backpack slot, the item will disappear. I looked through the code and couldn't figure out the cause of this bug. How can I get it to work properly? Container class: Slot class:
  7. Help me. I've been trying it for about two days, but I don't know. Currently the code is below. If you open the inventory with the backpack equipped and close it after operating the backpack slot, it will be saved correctly. However, if you open it with it equipped, remove the backpack, re-equip it, close the slot after operating it, the operation is not saved. Here's what I want to implement: What should I do to do that? Where should I fix it and which method should I use? I need help. 1. The backpack slot is active when the player is equipped with a backpack. 2. The same applies when the player equips / removes the backpack in the inventory screen. At that time, the slot (the item operation performed in the backpack inventory) is saved correctly. 3. With the above, it is possible to put on and take off multiple backpack items (that is, each has a different inventory) in the inventory. AbstractUMUPlayerContainer addsslot()s vanilla player inventory slots. public class BelongingsUMUPlayerContainer extends AbstractUMUPlayerContainer { private static final UMUEquipmentSlotType[] VALID_EQUIPMENT_SLOTS = new UMUEquipmentSlotType[]{ UMUEquipmentSlotType.HEAD, UMUEquipmentSlotType.CHEST, UMUEquipmentSlotType.LEGS, UMUEquipmentSlotType.FEET }; private static final UMUEquipmentSlotType[] VALID_RING_SLOTS = new UMUEquipmentSlotType[]{ UMUEquipmentSlotType.MAINRING1, UMUEquipmentSlotType.MAINRING2, UMUEquipmentSlotType.OFFRING1, UMUEquipmentSlotType.OFFRING2 }; private static final UMUEquipmentSlotType[] VALID_MISCELLANEOUS_SLOTS = new UMUEquipmentSlotType[]{ UMUEquipmentSlotType.ENCYCLOPEDIA, UMUEquipmentSlotType.MAP }; public BelongingsUMUPlayerContainer(int id, PlayerInventory playerInventory, PacketBuffer extraData) { this(UMUContainers.BELONGING_INVENTORY.get(), id, playerInventory, playerInventory.player); } public BelongingsUMUPlayerContainer(ContainerType<?> type, int id, PlayerInventory playerInventory, PlayerEntity player) { super(type, id, playerInventory, player); // index : 36 - 39 for (int i = 0; i < 4; i++) { this.addSlot(new EquipmentSlot(playerInventory, 39 - i, 186, 18 + i * 18, VALID_EQUIPMENT_SLOTS[i])); } this.addSlot(new OffhandSlot(playerInventory, 40, 255, 72)); this.addSlot(new EquipmentSlot(playerInventory, 41, 293, 27, UMUEquipmentSlotType.NECKLACE)); // index : 42 - 45 for (int iU = 0; iU < 2; iU++) { for (int iV = 0; iV < 2; iV++) { this.addSlot(new EquipmentSlot(playerInventory, 42 + iU * 2 + iV, 282 + iU * 18 + 4, 48 + iV * 18, VALID_RING_SLOTS[iU * 2 + iV])); } } for (int i = 0; i < 2; i++) { this.addSlot(new EquipmentSlot(playerInventory, 46 + i, 330, 72 + i * 18, VALID_MISCELLANEOUS_SLOTS[i])); } // for (int iV = 0; iV < 4; iV++) { // for (int iU = 0; iU < 9; iU++) { // //this.addSlot(new BackpackSlot(new ItemStackHandler(36), iU + iV * 9, 8 + iU * 18, 18 + iV * 18, Minecraft.getInstance().player, iV + 1)); // } // } this.initBackpackSlots(); } private void initBackpackSlots() { for (int iV = 0; iV < 4; iV++) { for (int iU = 0; iU < 9; iU++) { IItemHandler itemHandler = new ItemStackHandler(36); if (UMUEntityUtil.hasBackpack(this.player)) { itemHandler = this.player.getItemStackFromSlot(EquipmentSlotType.CHEST) .getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(new ItemStackHandler(36)); } this.addSlot(new BSlot(itemHandler, iU + iV * 9, 8 + iU * 18, 18 + iV * 18, this.player, iV + 1)); } } } @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) { if (slotId == 38) { //this.inventorySlots.subList(48, 83).forEach(s -> ((BackpackSlot) s).onEquipOrRemoveBackpack()); player.openContainer = new BelongingsUMUPlayerContainer(this.windowId, player.inventory, null); } return super.slotClick(slotId, dragType, clickTypeIn, player); } public class BSlot extends SlotItemHandler { private final PlayerEntity player; private final int size; public BSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition, PlayerEntity player, int size) { super(itemHandler, index, xPosition, yPosition); this.player = player; this.size = size; } @Override public boolean isEnabled() { if (UMUEntityUtil.hasBackpack(player)) { return UMUEntityUtil.getBackpackSize(Minecraft.getInstance().player) >= size; } return false; } } }
  8. When I checked it now, there was no problem in the first one. If you equip the backpack later, it seems that slots will be added. However, if you remove the equipment from it again, the slot will remain active.
  9. It goes back to the first problem. I'm checking if I have a backpack in isEnabled but it's not working. Slots remain enabled / disabled with or without a backpack with the inventory open.
  10. As far as I can see, there is no method called clicked in the Slot class. Do you mean slotClick ()? What do the arguments and return values of this method mean? Also, how to close and reopen the container?
  11. Sorry. My English was bad. How do I detect changes in the container and reopen it?
  12. Thank you. What is the best way to detect container changes, close the current container and reopen it?
  13. understood. So what is Slot # isEnabled? What is the difference between returning false with isEnabled with a slot added and not adding it in the first place?
  14. I'm having two issues with the code below. 1. If I open an inventory without a backpack and equip it with a backpack in that inventory, no backpack slots will be added. 2. If I open an inventory with a backpack equipped and remove the backpack in that inventory, the backpack slot remains active. What are the causes of these problems? Please help someone. Backpack container: Although omitted, there is also a player inventory slot similar to a regular inventory container public class BackpackPlayerContainer Container { private boolean addedBackpackSlot; public BackpackPlayerContainer(int id, PlayerInventory playerInventory, PacketBuffer extraData) { this(UMUContainers.BELONGING_INVENTORY.get(), id, playerInventory, playerInventory.player); } public BackpackPlayerContainer(ContainerType<?> type, int id, PlayerInventory playerInventory, PlayerEntity player) { super(type, id); this.addedBackpackSlot = false; if (EntityUtil.hasBackpack(player)) { for (int iV = 0; iV < 4; iV++) { for (int iU = 0; iU < 9; iU++) { this.addSlot(new BackpackSlot(player.getItemStackFromSlot(EquipmentSlotType.CHEST).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(new ItemStackHandler(36)), iU + iV * 9, 8 + iU * 18, 18 + iV * 18, player, iV + 1)); } } this.addedBackpackSlot = true; } } @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) { if (!addedBackpackSlot && EntityUtil.hasBackpack(player)) { for (int iV = 0; iV < 4; iV++) { for (int iU = 0; iU < 9; iU++) { this.addSlot(new BackpackSlot(null, iU + (iV + 1) * 9, 8 + iU * 18, 18 + iV * 18, player, iV + 1)); } } addedBackpackSlot = true; } return super.slotClick(slotId, dragType, clickTypeIn, player); } } public class BackpackSlot extends SlotItemHandler { private final PlayerEntity player; private final int size; public BackpackSlot(IItemHandler inventoryIn, int index, int xPosition, int yPosition, PlayerEntity player, int size) { super(inventoryIn, index, xPosition, yPosition); this.player = player; this.size = size; } @Override public boolean isEnabled() { return EntityUtil.getBackpackSize(player) >= size; } } public class EntityUtil { public static boolean hasBackpack(LivingEntity entity) { if (entity.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ModItems.BACKPACK.get()) { return true; } return false; } public static int getBackpackSize(LivingEntity entity) { return 3; } }
  15. Change the question. I want to open the corresponding screen by pressing the tab of a certain Screen class Nonaka. In summary, 1. Is it possible to implement another container screen as a child element of one screen class? (The child screen is drawn like a normal screen and responds to mouse clicks) 2. Is it possible to switch the child container screen with the parent screen open?
  16. I'm currently replacing PlayerContainer with a custom inventory screen. I was able to open a custom inventory instead of the vanilla screen. Now, I want to switch between multiple screens / containers, like the tabs on the left side of the vanilla recipe book. The method I'm thinking about right now is 1. In the ModInventoryScreen class, keep the list of InventoryTabToggleWidget and the current tab. 2.InventoryTabToogleWidget has a corresponding category and screen class. 3. Open the screen of the tab selected from mouseClicked (). I'm thinking of a method like the one above, but I can't think of a way to switch containers at that time. Is my screen switching method appropriate? And how do you switch containers at the same time?
  17. Oh, I just used RepairContainer for testing, so it won't be closed in my own container. Thank you, then this problem has been resolved.
  18. Very helpful. I think I was able to send the packet, but when I press the E key this time, the GUI is displayed for a moment and it closes without permission. What is the cause? Network Handler: Message: Register message: @SubscribeEvent public void onOpenGui(GuiOpenEvent event) { World world = Minecraft.getInstance().world; if (Minecraft.getInstance().world == null) return; PlayerEntity player = Minecraft.getInstance().player; if (player == null) return; ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST); if (!(chest.getItem() instanceof BackpackItem)) return; if (!(event.getGui() instanceof InventoryScreen)) return; event.setGui(new AnvilScreen(ContainerType.ANVIL.create(0, player.inventory), player.inventory, new StringTextComponent("text"))); UMUNetwork.sendToServer(new BackpackOpenMessage()); }
  19. Thank you. I haven't touched on packets very much, so is there a good tutorial (or sample code) for it? What should I send as a packet? @SubscribeEvent public void onOpenGui(GuiOpenEvent event) { World world = Minecraft.getInstance().world; if (Minecraft.getInstance().world == null) return; PlayerEntity player = Minecraft.getInstance().player; if (player == null) return; ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST); if (!(chest.getItem() instanceof BackpackItem)) return; if (!(event.getGui() instanceof InventoryScreen)) return; if (world.isRemote()) { event.setGui(new AnvilScreen(ContainerType.ANVIL.create(0, player.inventory), player.inventory, new StringTextComponent("text"))); // send a packet to server? } else { NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider((id, playerInventory, unused) -> { return new RepairContainer(id, playerInventory, IWorldPosCallable.of(world, player.getPosition())); }, new StringTextComponent("test"))); } }
  20. Thanks, GuiOpenEvent#setGui was able to open another screen. However, since the container is probably still PlayerContainer on that screen, moving ItemStack etc. will be different from AnvilScreen. How can I change the container? (Because it's a test, don't worry about the clutter of the code right now) @SubscribeEvent public void onOpenGui(GuiOpenEvent event) { if (Minecraft.getInstance().world == null) return; if (!Minecraft.getInstance().world.isRemote) return; PlayerEntity player = Minecraft.getInstance().player; if (player == null || !(event.getGui() instanceof InventoryScreen)) return; ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST); if (!(chest.getItem() instanceof BackpackItem)) return; event.setGui(new AnvilScreen(ContainerType.ANVIL.create(0, player.inventory), player.inventory, new StringTextComponent("test"))); }
  21. I organized it a little. I found in GuiOpenEvent#getGui that I need to check that it is an InventoryScreen and cancel it. However, there are some questions here. 1: Is it correct to recognize that the server player PlayerContainer and the client player are opening the InventoryScreen when the player opens the inventory with the E key? 2: At 1, Is the InventoryScreen returned by GuiOpenEvent#getGui? 3: How can I open another screen after canceling with event.setCanceled(true)? event.setGui(new CustomScreen(...))? 4. Is the method of processing the client side (screen) with GuiOpenEvent correct in 1-3? Also, how can I perform server side (container) processing?
  22. I'm currently working on a backpack item. I can equip it to my chest and when the equipped player opens the inventory I want to open a custom inventory instead, but that doesn't work. What should I do? public class BackpackItem extends DyeableArmorItem implements INamedContainerProvider { public BackpackItem(IArmorMaterial material, EquipmentSlotType slot, Properties properties) { super(material, slot, properties); } @Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { return new BackpackInventory(); } @Nullable @Override public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) { return new BackpackContainer(p_createMenu_1_, p_createMenu_2_.player); } @Override public ITextComponent getDisplayName() { return null; } public void onOpenGui(GuiOpenEvent event) { PlayerEntity player = Minecraft.getInstance().player; if (player == null || event.getGui().getClass() != InventoryScreen.class) return; ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST); if (!(chest.getItem() instanceof BackpackItem)) return; NetworkHooks.openGui((ServerPlayerEntity) player, this); }
  23. // Test @Override public ActionResultType onItemUse(ItemUseContext context) { IItemHandler inventory = context.getItem().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(new ItemStackHandler(27)); if (!context.getWorld().isRemote()) { // add 3 diamonds to inventory slot 0, how? int test = // get inventory slot 0 itemstack context.getPlayer().sendMessage(new StringTextComponent(String.valueOf(test)), null); } return super.onItemUse(context); } Thank you very much. It seems that I was able to implement capability, but I don't know how to manipulate the value (contents of the inventory) ......
  24. Perhaps it's a question many people have asked, but how do I do to implement capability? I now want my item to have a simple 27-slot inventory. 1. What else do I need to add a slot to the item stack through capability, besides a simple class of slot data (ItemStackHandler? In this case?), Item # initCapabilities? 1. When and for what is the method called Item # initCapabilities called? What should I return? 2. What is CapabilityItemHander.ITEM_HANDLER_CAPABILITY? 3. What does @CapabilityInject (IItemHandler) mean?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.