JayZX535 Posted May 15, 2020 Posted May 15, 2020 Hey all, I have a set of items that can be dyed dynamically (think leather armor, but simpler-- just the main 16 colors). This works by assigning an NBT tag to the dyed ItemStack, which the game then checks for when applying tints to the layer. This function itself works fine, however I've run into a bit of a block when trying to add additional functionality. Put simply, this item can be crafted with another item to make a 'combined' item. I'd like to make it possible to un-craft that combination, returning the item crafted with it in the output slot, and leaving the base item in the crafting grid (i.e. buckets after crafting cake). There are multiple items that can be crafted with the base item, which are also saved in the stack NBT data, so I'd like to keep those secondary items as the output, since that seems like it should be easier to determine which item to output that way. However, as I understand it, if I just use the default .containerItem() to return the base item, it will create a new stack of that item, thus wiping the NBT (and any color data that might have been stored in it). Is there a good way I could ensure that the color NBT data is copied over to the base item, so that it doesn't revert to its un-dyed version upon crafting? Thanks, and have a great day. Quote
poopoodice Posted May 15, 2020 Posted May 15, 2020 I've never interact with container item before but I think you should be able to get the nbt tag from the old stack and attach it to the new stack? Quote
JayZX535 Posted May 15, 2020 Author Posted May 15, 2020 7 minutes ago, poopoodice said: I've never interact with container item before but I think you should be able to get the nbt tag from the old stack and attach it to the new stack? That was my first thought but the method that does it, getRemainingItems(C inv) comes from the IRecipe interface and is a default, so I can't just override and insert my own code. Which is a shame because the method itself would be easy enough to alter. Quote
poopoodice Posted May 15, 2020 Posted May 15, 2020 I remember in vanilla minecraft you can combine two damaged items, which are saved by nbt as well, but I don't know how they work and where they are being done. Quote
JayZX535 Posted May 15, 2020 Author Posted May 15, 2020 Just now, poopoodice said: I remember in vanilla minecraft you can combine two damaged items, which are saved by nbt as well, but I don't know how they work and where they are being done. Oh yeah, I know how to edit the NBT data for the result item, which goes into the output slot. I just don't know how to edit the NBT data for an item that gets left behind in the crafting grid, like buckets from the cake recipe, or (in 1.15) empty bottles after crafting a honey block. Quote
poopoodice Posted May 15, 2020 Posted May 15, 2020 Just now, JayZX535 said: Oh yeah, I know how to edit the NBT data for the result item, which goes into the output slot. I just don't know how to edit the NBT data for an item that gets left behind in the crafting grid, like buckets from the cake recipe, or (in 1.15) empty bottles after crafting a honey block. Ah, by that can't you not just use something like @Override public ItemStack getContainerItem(ItemStack itemStack) { ItemStack result = new ItemStack(something); result.setTag(itemStack.getTag()); return result; } ? Quote
JayZX535 Posted May 15, 2020 Author Posted May 15, 2020 5 minutes ago, poopoodice said: Ah, by that can't you not just use something like @Override public ItemStack getContainerItem(ItemStack itemStack) { ItemStack result = new ItemStack(something); result.setTag(itemStack.getTag()); return result; } ? Unfortunately no. I tried adding a custom extension to properties in my Item class, but the problem is, the method is this: public Item.Properties containerItem(Item containerItemIn) { this.containerItem = containerItemIn; return this; } Which takes an Item and not an ItemStack. Good thought though... Quote
JayZX535 Posted May 15, 2020 Author Posted May 15, 2020 8 hours ago, diesieben07 said: You are looking at the wrong method. You need to override the method in your item class. Which one? Because the only one I see in the item class is this: @Nullable @Deprecated // Use ItemStack sensitive version. public final Item getContainerItem() { return this.containerItem; } I don't even see where the "ItemStack sensitive version" is. A lot of the times those notes have an actual link, but I'm not finding anything with ctrl + f either. Just this and the one I referenced earlier in properties (which is how this.containerItem is set in this method). Quote
JayZX535 Posted May 15, 2020 Author Posted May 15, 2020 Just now, diesieben07 said: Why on earth would you use Ctrl-F to find a method? Use your IDE's "find symbol" function (ctrl-alt-shift-n in IntelliJ). Or, even easier: Just tell your IDE to override a method. In both IDE's I've used (eclipse and IntelliJ) you can just start typing a method name in a class body and it will suggest overriding it. Because nothing else I tried was working. I figured I might as well see if that would, and it didn't. The override method isn't working for me. It didn't auto-suggest anything, and when I tried manually typing in what I thought it probably would be, the only thing it did was give me an incorrect return type and suggest I change it to the Item one. I've literally never seen it suggest a method like that either, so I don't know if something is off by default or what. Does anyone know what the method that deprecation note referred to even is? Because I sure as heck don't see it. Quote
Draco18s Posted May 15, 2020 Posted May 15, 2020 11 minutes ago, JayZX535 said: I figured I might as well see if that would, and it didn't. You didn't bother checking the class's parents and interfaces, though. 12 minutes ago, JayZX535 said: Does anyone know what the method that deprecation note referred to even is? Because I sure as heck don't see it. Check the class's interfaces. I'm sure one of them will have it. Quote 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.
JayZX535 Posted May 15, 2020 Author Posted May 15, 2020 31 minutes ago, Draco18s said: You didn't bother checking the class's parents and interfaces, though. Check the class's interfaces. I'm sure one of them will have it. Aha! It's in IForgeItem-- apparently I'd missed that one. Overrode the method to make it check for the color variable before returning the stack and it works like a charm. Thanks everyone, for helping me figure this one out. Quote
Recommended Posts
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.