Jump to content

[SOLVED] [1.12.2] Custom player container cannot be cast to ContainerPlayer


Recommended Posts

Posted (edited)

I have a custom player container that has a full 3x3 crafting grid, and I'm updating to 1.12.2. It worked great before, but now it seems that changes introduced with the recipe book are causing me trouble. Specifically, when pressing E to open the player inventory, I get a crash:

 

com.daeruin.primalcraft.inventory.PrimalContainerPlayer cannot be cast to net.minecraft.inventory.ContainerPlayer

    at net.minecraft.client.gui.inventory.GuiInventory.initGui(GuiInventory.java:72) ~[GuiInventory.class:?]

 

The line in question is a new bit of code for the recipe book GUI that includes a cast to ContainerPlayer. This doesn't work for me since I'm replacing the container player with my custom one. I have tried/considered a few things.

 

  1. I tried just overriding the initGui method and casting to my custom player container instead, but there is a call to super.initGUI(). Since I'm extending GuiInventory it ends up processing the super's hard-coded cast to ContainerPlayer anyway. I think I need the call to super, because it goes way up the chain of inheritance to do lots of stuff like displaying potion effects and setting the location of the GUI. Unless maybe I need to duplicate all that stuff in my override instead?
  2. I tried making my PrimalContainerPlayer extend ContainerPlayer instead of Container. Unfortunately ContainerPlayer's constructor doesn't work for me since that's where all the inventory slots are created. I need different slots.
  3. I considered making my GUI extend InventoryEffectRenderer instead of GuiInventory, but that would require me to copy a ton of vanilla code. That seems like bad style since vanilla code could get change with an update, and my copied code wouldn't automatically reflect the changes. Is that the best choice here, or is there another solution?

 

My player inventory GUI class:

 

  Reveal hidden contents

 

My container class:

 

  Reveal hidden contents

 

Edited by Daeruin
Formatting
Posted
  On 2/11/2018 at 6:38 PM, Daeruin said:

extends Container

Expand  

Cough

extends PlayerContainer

Cough

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You still need to extend it and deal with it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 2/11/2018 at 6:58 PM, Draco18s said:

You still need to extend it and deal with it.

Expand  

 

Well, that was easier than I thought it would be. You made me awfully grumpy at first, but after taking your word for it and thinking about it for a while, I realized that after calling the super's constructor, I could just clear all the old inventory slots using List::clear and start over, so all my old code still works fine.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Create New...

Important Information

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