Jump to content

1.5 GUI and Item information


Vogner

Recommended Posts

Basically, I'm working toward a weapon that levels, complete with a perks screen like a single talent tree from WoW, and I want to open its GUI with the inventory button.

 

I've been trying to trigger a GUI with a keybinding rather than right clicking an item or block, and I've hit a bit of a wall. I've got the code working to the extent that when I hit the inventory button, code triggers. But I don't have a world or player reference, although I guess I could grab the FMLClientHandler references. Anyway, there's too much to consider beyond that, I'm not sure where to go from here. Is there an obvious solution I'm unaware of?

 

Question 2: This idea will obviously require a bunch of NBT stuff. I'm probably just going to extrapolate from the code in ItemFireworks/FireworksCharge, which already keeps track of a bunch of NBT flags, which is perfect for a perks system . Since there are no dedicated methods for adding miscellaneous tags, I'll probably lump it in with one of the other methods that take a ItemStack object as a parameter. Is there an easier solution than this, or something I've missed?

 

Thanks in advance.

Link to comment
Share on other sites

The keybinding is quite easy. After you have the GUI working (test it via the onBlockActivated() method) you literally just use the FMLClientHandler.getClient().openGui(new GuiToOpen); (its something like that) and it opens the GUI*.

 

* I have yet to figure out how to CLOSE the GUI using the bound button :/

 

I know that I saw a tutorial on the minecraft forums that was to do with item stack nbt tag compounds... I cannot find it at the time being though.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Okay so I've got the item writing and reading values from NBT, but naturally I've hit a few more walls:

 

The NBTTagCompound is always null, despite the fact that the item is both damageable and not stackable, so I have to manually give it an NBTTagCompound object with ItemStack.setNBTTagCompound (or whatever it's called precisely)

 

Perhaps related to the aforementioned is the fact that there are only one set of values for all items, so they all share and affect the same sets of values. Basically, they're all using the same NBT object and I'm not sure  how to stop this from happening. Any ideas, guys?

 

Third, my GUI now works. I decided to give it its own dedicated key, instead of using the inventory button, because there just isn't enough screen space for both GUIs. However, the GUI's background image is tiling. Any thoughts on that one?

Link to comment
Share on other sites

Okay so I've got the item writing and reading values from NBT, but naturally I've hit a few more walls:

 

The NBTTagCompound is always null, despite the fact that the item is both damageable and not stackable, so I have to manually give it an NBTTagCompound object with ItemStack.setNBTTagCompound (or whatever it's called precisely)

 

Perhaps related to the aforementioned is the fact that there are only one set of values for all items, so they all share and affect the same sets of values. Basically, they're all using the same NBT object and I'm not sure  how to stop this from happening. Any ideas, guys?

 

Third, my GUI now works. I decided to give it its own dedicated key, instead of using the inventory button, because there just isn't enough screen space for both GUIs. However, the GUI's background image is tiling. Any thoughts on that one?

 

1. It's null if it has no enchantment or already defined data.

2. Do you create an entirely new instance of the NBTTagCompound for each item? Seems like not, because of the behavior.

3. Can we see a screenshot? or at least a bit more explanation, what do you mean by tiling, how exactly?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Okay so I've got the item writing and reading values from NBT, but naturally I've hit a few more walls:

 

The NBTTagCompound is always null, despite the fact that the item is both damageable and not stackable, so I have to manually give it an NBTTagCompound object with ItemStack.setNBTTagCompound (or whatever it's called precisely)

 

Perhaps related to the aforementioned is the fact that there are only one set of values for all items, so they all share and affect the same sets of values. Basically, they're all using the same NBT object and I'm not sure  how to stop this from happening. Any ideas, guys?

 

Third, my GUI now works. I decided to give it its own dedicated key, instead of using the inventory button, because there just isn't enough screen space for both GUIs. However, the GUI's background image is tiling. Any thoughts on that one?

 

1. It's null if it has no enchantment or already defined data.

2. Do you create an entirely new instance of the NBTTagCompound for each item? Seems like not, because of the behavior.

3. Can we see a screenshot? or at least a bit more explanation, what do you mean by tiling, how exactly?

 

Unfortunately, I don't have internet on the computer with my project on it. But this is an example of a tiled image:

 

width=102 height=102https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSiPtcQZ10wUrygGkoBp4T1Gk9defn9K9EXI5ASHv6B_fKJ2m1fRA[/img]

 

The grass, sand and water images are laid next to each other, over and over again. This is happening to my GUI for some reason, although it is being displayed at the correct scale, so you can only see the tiling on the edges of the screen. Imagine the inventory gui, and then another next to it, and another beneath it, etc. This is only happening to the background layer. I'm using the exact same DrawBackgroundLayer code as every other GUI, with my own image substituted in.

 

Also, I solved the NBT problem. I resorted to event handlers yet again. <3 event handlers. While I didn't know that the NBTTagCompound will likely be null if the item isn't enchanted, the problem wasn't the NBT thing at all. I neglected that items are static, and I had the xp integer saving, initializing and incrementing in the item's class, and so they were all reading the same value. I moved the entire exp system to an EntityAttack event, effectively solving the problem. So voila, I now have a mod with weapons that tier without having to craft each tier separately, as well as one that encourages hunting over constructing mob farms. Also, I made spiders tameable and mountable. That's unrelated, but it rocks.

Link to comment
Share on other sites

I see, do you properly set the xSize and ySize variables in your gui? They must match the size of the drawn background or you'll see this "tiling"if the variables are set too small.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I see, do you properly set the xSize and ySize variables in your gui? They must match the size of the drawn background or you'll see this "tiling"if the variables are set too small.

 

Well there's no gap or overlap between the tiles, so I'm not sure that's the issue. I'll keep comparing my code to vanilla code and see if I snafu'd something somewhere.

 

In terms of progress, however, I've arrived at the point that when opened, a cleanly formatted GUI is displayed that lists every relevant piece of equipment in the player's inventory (including equipped items) as a button. Basically, you'll click on the gear you want to enhance, go to a second, item-specific GUI and expend some experience to purchase abilities or perks that you've unlocked. It should be really fun when I'm done.

 

That issue aside, I haven't been able to trigger any of this with a keybinding, because there's no way that I know of to get a player reference that isn't null, and therefor I can't access its inventory, either... Quite a few mods have done it, though, so there's got to be a way.

Link to comment
Share on other sites

That issue aside, I haven't been able to trigger any of this with a keybinding, because there's no way that I know of to get a player reference that isn't null, and therefor I can't access its inventory, either... Quite a few mods have done it, though, so there's got to be a way.

 

That is not really that hard. All you need to do is make a new EntityPlayer variable like so:

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

 

That will give you an instance of the player. BUT!!!! This is the CLIENT SIDE player, so if you are wanting stuff done server side, you will have a slight issue. Though I am sure that you could then create a packet that sends the required information to the server and casts the EntityPlayer (player) variable to a EntityPlayerMP (that being done in the packet).

 

I just released, GUI's are ONLY client side, so you will be fine with that reference I made. Also you WILL need a packet handler and such when working with GUI's, you have to pass information done and such to the server. But I am sure you would already know this.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

I actually tried something like that using the FMLClientHandler.getClient().getPlayer() (or whatever its called), and the resultant player reference was null. My sanity checks were even client side/server side sensitive. I haven't yet tried that specific line of code, though - I'll try it and report back when I can.

 

Since yesterday I've moved from buttons listing all level-able gear as text to custom buttons displaying the item's Icon, including any animation. I've also managed some GUIInventory-style tooltips that describe which specific item you're about to affect. There are still plenty of visual bugs, but I'm very happy with it, since it's my first.

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
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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