Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.18.2] Error when attaching capabilities


Squander
 Share

Recommended Posts

Posted (edited)
1 hour ago, Luis_ST said:

I'm not sure what's the problem everything works how i think it should.

When I turn on the menu, the items that I have in the hotbar appear in 9 slots form my capability, and I want more space

Edited by Squander
Link to comment
Share on other sites

Posted (edited)

This is not a backpack, I open it with an event (only for the test) in the ClickBlock class

3 minutes ago, Luis_ST said:

Is the code in your Git repo up to date?
How did you open the Backpack?
Did you tried a new World?

 

Edited by Squander
Link to comment
Share on other sites

1 hour ago, Squander said:

and I want more space

I'll guess you mean the size of the ExtraStorageInventory, in your case the size is set in AttachCapabilities where you create ExtraStorageInventory,
and in ClickBlock where you send the size to the client. If you change these values and handle the new Slot size in your ExtraStorageMenu you can expands the ExtraStorage.

Note if you change the value you need to create a new World.

1 hour ago, Squander said:

When I turn on the menu, the items that I have in the hotbar appear in 9 slots form my capability

Finally i found your issue, as D7 already told you can not use ITEM_HANDLER_CAPABILITY but this include IItemHandler.
Due you use IItemHandler for your Capability it always return the already attached IItemHandler (the player inventory).
The steps to solve this problem are easy:

  1. Create a new interface which extends IItemHandler
  2. Implement this interface in your ExtraStorageInventory
  3. Use this interface for your Capability and the LazyOptional
Link to comment
Share on other sites

17 minutes ago, Luis_ST said:

I'll guess you mean the size of the ExtraStorageInventory, in your case the size is set in AttachCapabilities where you create ExtraStorageInventory,
and in ClickBlock where you send the size to the client. If you change these values and handle the new Slot size in your ExtraStorageMenu you can expands the ExtraStorage.

Note if you change the value you need to create a new World.

Finally i found your issue, as D7 already told you can not use ITEM_HANDLER_CAPABILITY but this include IItemHandler.
Due you use IItemHandler for your Capability it always return the already attached IItemHandler (the player inventory).
The steps to solve this problem are easy:

  1. Create a new interface which extends IItemHandler
  2. Implement this interface in your ExtraStorageInventory
  3. Use this interface for your Capability and the LazyOptional

Does my IItemHandler extension interface need to be registered with RegisterCapabilityEvent?

Link to comment
Share on other sites

2 hours ago, Luis_ST said:
  • Create a new interface which extends IItemHandler
  • Implement this interface in your ExtraStorageInventory
  • Use this interface for your Capability and the LazyOptional

Prefer composition over inheritance.

Make a class that has an IItemHandler field and use it as your capability instead of extending IitemHandler.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Prefer composition over inheritance.

Make a class that has an IItemHandler field and use it as your capability instead of extending IitemHandler.

Should I assign a new instance to the IItemHandler field

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • @Mod.EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) public class ClientEvents { @SubscribeEvent public static void camera(ViewportEvent.ComputeCameraAngles event) { event.setRoll(180f); } }  
    • @SubscribeEvent public static void onRenderTick(TickEvent.RenderTickEvent event) { Player player = Minecraft.getInstance().player; if (player != null) { Vec2 rotation = new Vec2(player.getXRot(), player.getYRot()); Vec2 addition = Vec2Rot(new Vec3(0, 0, 0.01)); player.setXRot(rotation.x + addition.x); player.setYRot(rotation.y + addition.y); } } So i was thinking that minecraft camera rotation is kinda boring so i try to make it rotate on z-axis (like how it did when the player get damage), i soonly writing codes to test it and the x, y works fine but when i try to set the z rotation, there is no setZRot method. I went to find class like Renderers, Camera, etc in the sources but still can't find how to do it. Does anyone know how to do it, or is this not possible?
    • Hello, I have a block entity that is using entity.teleportTo(x, y, z); to teleport an entity(Armor Stand in this case) into a chunk that's being kept loaded with ForgeChunkManager.forceChunk(level.getServer().getLevel(Level.OVERWORLD), StargateJourney.MODID, getBlockPos(), level.getChunk(getBlockPos()).getPos().x, level.getChunk(getBlockPos()).getPos().z, true, true); It works well, however, when I teleport the player alongside the entity, the entity doesn't load. It's still there, because if the player leaves to unload the chunk and then returns, the entity appears where it should. I've tried fixing it by not forceloading the chunk and the entity loads without problems, but I actually need to have the chunk loaded, because I have a block entity in said chunk, that is ticking(essentially, it's the second end of a teleporter mechanism). Is there a workaround to load the entity manually or even better, have it never unload in the first place?
    • Apologies, but as this is written with MCreator, we do not support it on this forum. Please ask their support forums for help.
    • Google the IDE and look up the features necessary to do so. There is plenty of text and videos about how to use it. Everything is written by volunteers and they have to be maintained by volunteers. Additionally, when it comes to the official docs or the community wiki, there are only so many people who have time and are willing to do that. It requires a lot of research to be able to write something competent without providing copy-paste elements. So, unless you're willing to hire people to do so, contribute to the people who keep Forge going, or write some yourself, expect that there probably won't be any documentation for anything besides from simple elements.
×
×
  • Create New...

Important Information

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