Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Luis_ST

Members
  • Joined

  • Last visited

Everything posted by Luis_ST

  1. I looked in ItemStackHandler and found out that I have to create a constructor for my ItemStackHandler that sets the size of the inventory. I then created this: public class ModItemStackHandler extends ItemStackHandler implements IModItemHandler { public ModItemStackHandler(int size) { stacks = NonNullList.withSize(size, ItemStack.EMPTY); } } Now I can put items in this lot, but they are removed from the slot after a short time
  2. I'm trying to understand your code and why it doesn't work
  3. but why? vanilla not overwirte the equals methode I think there is still a better way. check whether the item is an instance of AxeItem / PickaxeItem / ShovelItem then your vanillaToolTier sets to: ItemInstance#getTier#getHarvestLevel so like this: you then have to set the ToolType Item item = player.getHeldItemMainhand().getItem(); int vanillaToolTier = 0; if (item instanceof PickaxeItem) { vanillaToolTier = ((PickaxeItem) item).getTier().getHarvestLevel(); } else if (item instanceof AxeItem) { vanillaToolTier = ((AxeItem) item).getTier().getHarvestLevel(); } else if (item instanceof ShovelItem) { vanillaToolTier = ((ShovelItem) item).getTier().getHarvestLevel(); }
  4. https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk
  5. no no no. the equals method comes from the java object class and minecrft item class does not overwrite this method so again don't use: item.getItem().equals(Items.WOODEN_PICKAXE) || item.getItem().equals(Items.GOLDEN_PICKAXE) use instead: item.getItem() == Items.WOODEN_PICKAXE || item.getItem() == Items.GOLDEN_PICKAXE
  6. do not use: item.getItem().equals(Items.WOODEN_PICKAXE) || item.getItem().equals(Items.GOLDEN_PICKAXE) use instead: item.getItem() == Items.WOODEN_PICKAXE Edit: that should fix your problem
  7. okay i now have slots in the container they are not in the correct position yet but that should be a matter of setting unfortunately it still doesn't do perfect: the enderchest inventory works but in my inventory only the first slot works, the others are displayed but I can't put any items in the slots
  8. okay if I want to add slots there (those of the container) I need an IItemHandlerModifiable. Can I save the IItemHandlerModifiable from the server constructor in a field and then use it in the client constructor?
  9. what do you want to do exactly?
  10. yes as far as I know there is no type that is unused
  11. you need to update your version to a newer one and we will help you (1.15 - 1.16)
  12. if you want to create a chest / barrel that the item drops when it is destroyed you don't need a capability. if you want to create a block like the enderchest that has its own inventory for each player, you need a capability
  13. do you mean this: dependencies { minecraft 'net.minecraftforge:forge:1.16.5-36.0.1' } if not i use the normal mdk from forge (1.16.5): https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.16.5.html
  14. do you mean how you use the event? then use this: @SubscribeEvent public static void HarvestCheck(PlayerEvent.HarvestCheck event) { } @SubscribeEvent public static void BreakSpeed(PlayerEvent.BreakSpeed event) { }
  15. ah you use an api. (I probably overlooked it) then it could be that there is no other method and this is the only way to get the player position but i'm not sure because i have never worked with an api before
  16. first use RenderGameOverlayEvent Pre or Post Second, the RenderGameOverlayEvent contains an ElementType enum which contains the various vanilla overlay elements. Check whether the ElementType is what you need (example: you want to change something on the Hunger overlay then check whether the ElementType == FOOD). This is because you are rendering on all ElementType, that is, when minecraft renders your bar over all ElementType that are under the current layer use something like this to check if the current ElementType is correct: // example if (event.getType() != ElementType.VIGNETTE) { return; }
  17. you can use that it returns a double: PlayerEntity playerEntity = Minecraft.getInstance().player; playerEntity.getPosX(); playerEntity.getPosY(); playerEntity.getPosZ();
  18. you can use events to modify blocks and tools - PlayerEvent#HarvestCheck -> harvestLevel - PlayerEvent#BreakSpeed -> breakSpeed - LivingDamageEvent -> damage of tools - LivingEntityUseItemEvent -> durablity read the description of the events for more information about the function of the events and what they do what kind of values do you mean exactly can you give an example of that what you want to change?
  19. if I understand it correctly, the method only looks if the inventory doesn't have too many inventory slots. if there is too much, it will issue an error now i got another error the container is opened but has no slots: [20:15:14] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?] {} at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?] {} at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) ~[?:?] {} at java.util.Objects.checkIndex(Objects.java:359) ~[?:?] {} at java.util.ArrayList.get(ArrayList.java:427) ~[?:?] {} at net.minecraft.inventory.container.Container.getSlot(Container.java:165) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.inventory.container.Container.setAll(Container.java:486) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.client.network.play.ClientPlayNetHandler.handleWindowItems(ClientPlayNetHandler.java:1224) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.network.play.server.SWindowItemsPacket.processPacket(SWindowItemsPacket.java:61) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.network.play.server.SWindowItemsPacket.processPacket(SWindowItemsPacket.java:13) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:973) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {} at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[?:?] {} at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {} at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?] {} at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {} at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {} at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {} at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
  20. in my container at: assertInventorySize((IInventory) itemHandlerModifiable, 6 * 9); public ModEnderChestContainer(int id, PlayerInventory playerInventoryIn, IItemHandlerModifiable itemHandlerModifiable) { // TODO: fix super(ModContainerType.ENDER_CHEST.get(), id); assertInventorySize((IInventory) itemHandlerModifiable, 6 * 9); int i = (6 - 4) * 18; for (int j = 0; j < 6; ++j) { for (int k = 0; k < 9; ++k) { this.addSlot(new SlotItemHandler(itemHandlerModifiable, k + j * 9, 8 + k * 18, 18 + j * 18)); } } for (int l = 0; l < 3; ++l) { for (int j1 = 0; j1 < 9; ++j1) { this.addSlot(new Slot(playerInventoryIn, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i)); } } for (int i1 = 0; i1 < 9; ++i1) { this.addSlot(new Slot(playerInventoryIn, i1, 8 + i1 * 18, 161 + i)); } }
  21. my ide says that I need an IInventory and not an IItemHandlerModifiable
  22. I get an error again (cannot be cast) now my question do i need this method in my container: assertInventorySize((IInventory) itemHandlerModifiable, 6 * 9); because I cannot cast IItemHandlerModifiable to an IInventory when i need them what do i have to use there instead
  23. if i understand the forge doc correctly i have to run the constructor in my capability class but in which FML setup do i have to do this (FMLCommonSetupEvent) I took a little too literally
  24. https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk/tree/main/forge-1.16.5-36.0.1-mdk
  25. I'm not sure, but I think the LazyOptional isn't initialized because i tried this: when i search for the message ("this is a test message to find you on the console") on the console i can't find it CapabilityProvider: private ModItemStackHandler inventory = new ModItemStackHandler(); private PlayerEntity player; private LazyOptional<CombinedInvWrapper> optional = LazyOptional.of(() -> { // i think this is not called Cave.LOGGER.debug("this is a test message to find you on the console"); // not on the console EnderChestInventory enderChestInventory = player.getInventoryEnderChest(); Cave.LOGGER.debug("enderChestInventory: " + enderChestInventory != null); // not on the console InvWrapper invWrapper = new InvWrapper(enderChestInventory); Cave.LOGGER.debug("invWrapper: " + invWrapper != null); // not on the console CombinedInvWrapper combinedInvWrapper = new CombinedInvWrapper(invWrapper, inventory); Cave.LOGGER.debug("inventory: " + inventory != null); Cave.LOGGER.debug("combinedInvWrapper: " + combinedInvWrapper != null); // not on the console return combinedInvWrapper; }); public Provider(PlayerEntity playerIn) { this.player = playerIn; } @Override @SuppressWarnings({ "unchecked" }) public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { Cave.LOGGER.debug("getCapability: cap == CAPABILITY: " + (cap == CAPABILITY)); // on the console: return true Cave.LOGGER.debug("getCapability: cap != null: " + cap != null); // on the console: return true Cave.LOGGER.debug("optional: " + optional.isPresent()); // on the console: return true return cap == CAPABILITY && cap != null ? (LazyOptional<T>) optional : LazyOptional.empty(); } and the event: if (player instanceof ServerPlayerEntity) { event.setCanceled(true); ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player; IItemHandlerModifiable itemHandlerModifiable = serverPlayer.getCapability(ModCapability.CAPABILITY, null).orElseThrow( () -> new NullPointerException("The mod Capability<IModItemHandler> is null")); Cave.LOGGER.debug("getCapability isPresent: " + serverPlayer.getCapability(ModCapability.CAPABILITY, null).isPresent()); // on the console: return false if (itemHandlerModifiable != null) { NetworkHooks.openGui(serverPlayer, new SimpleNamedContainerProvider((id, inventory, playerIn) -> { return new ModEnderChestContainer(id, inventory, itemHandlerModifiable); }, CONTAINER_NAME), pos); } } if someone still has an idea what i can do to find the problem i am open to suggestions

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.