Jump to content

TheXFactor117

Forge Modder
  • Posts

    82
  • Joined

  • Last visited

Everything posted by TheXFactor117

  1. I know, I realized that now, not sure why it didn't occur to me. I don't have access to my code now but I was getting an IllegalStateException which said I was recursively loading in my loot table which didn't make a whole lot of sense. I was casting the loot table to my new LootTable class inside LootTableLoadEvent so maybe that was an issue or it was an issue with the class itself. Either way way I'll post code later if needed. My LootTableClass is basically a copy of the old one plus the new LootContext class and I'm sure that's where my issue is. I just haven't had time to look into it yet.
  2. Actually, I don't understand how this could even work. There's still not away to the get a player or chest from the inventory unless I'm missing something.
  3. Ok, I think that'll work. Theoretically, I could pass an instance of the player through the LootContext which would set it as the Killer Player, correct? I was starting to think I'd need to do some ASM to get it to work.
  4. Long story short, I've been using the PlayerTickEvent to set certain items up with specific NBT data - works fine, but I don't necessarily want to loop through a player's inventory every tick for everyone on a given server. My idea of a solution was to use LootTables to spawn in said items with the given NBT data applied to it whenever they drop from a monster or are spawned in a chest. The problem is in order to setup this information, I need to get the chunk coordinates for where that item was dropped/looted from a chest (reason for this is chunks will be assigned a value, and I need to retrieve this value and set this value to the specific item drops and such). To get these coordinates I'd either need the player or chest TE position. The issue is partially solved when the item is dropped from a monster since I would have access to the monster killed or the player who killed it via LootContext - however, this doesn't help me with loot generated in chests. My question is, does anything store the chest that was opened/the player who opened anywhere where I could access it easily, ideally from a custom LootFunction (or LootCondition because I think that could work too)? I read somewhere that this information is stored, but I'm not sure if that's entirely true and don't know where it would even be located.
  5. Ok, I think my theory is holding up. I removed the call setRandomAttributes and setAttributeModifiers and the output is only called once. I must be trying to process to much information for a single tick to handle it all. I guess I'll have to either set the information not inside of a TickEvent or try and optimize how I'm setting the information.
  6. @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { if (event.phase == Phase.START) { if (!event.player.getEntityWorld().isRemote) { if (event.player.inventory.getCurrentItem().getItem() instanceof ItemSword && !NBTHelper.loadStackNBT(event.player.inventory.getCurrentItem()).hasKey("Level")) { ItemGenerator.createWeapon(event.player.inventory.getCurrentItem(), event.player); } } } } and the createWeapon method... public static void createWeapon(ItemStack stack, EntityPlayer player) { NBTTagCompound nbt = NBTHelper.loadStackNBT(stack); IPlayerInformation playerInfo = player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null); if (playerInfo != null) { if (Rarity.getRarity(nbt) == Rarity.DEFAULT) { Rarity.setRarity(nbt, Rarity.getRandomRarity(nbt, player.getEntityWorld().rand)); // sets a random rarity MineHackSlash.LOGGER.info("Rarity: " + Rarity.getRarity(nbt)); nbt.setInteger("HideFlags", 6); // hides Attribute Modifier and Unbreakable tags nbt.setInteger("Level", 1); // set level to current player level setRandomAttributes(stack, nbt, Rarity.getRarity(nbt), player); setAttributeModifiers(nbt, stack, player); stack.setStackDisplayName(Rarity.getRarity(nbt).getColor() + stack.getDisplayName()); NBTHelper.saveStackNBT(stack, nbt); } } } My output gets run twice on the server thread. I'm checking for Phase.Start and making sure we're on the server side. However, if I call createWeapon from anything other than PlayerTickEvent, that outputs only one time. Edit: maybe the code I'm trying to run within a tick is taking too long to process? Because if you output world time the time is increasing so it's two separate ticks. It's almost like the event calls my method and calls it again before it can set anything. The Rarity is always set to the first call but later on the method setRandomAttributes uses the rarity to determine how many attributes to apply - this number always uses the second rarity created instead of the first. I'm just confused as to what is happening.
  7. I'll do the above, though I've been having issues with my PlayerTickEvent being run twice on the server thread during Phase.START and it's kinda screwing the generation process up.
  8. Ah I see now - there is a downside to just using the TooltipEvent assuming the player doesn't actually look at the weapon... There honestly just needs to be an event for when an item is added into a player inventory. Make my life a hell of a lot easier. Though would looping through the current item on PlayerTick cause any noticeable effects? I'm assuming the entire inventory would cause issues potentially or is the scale of that just not even noticeable nowadays with the computers we have?
  9. Yes I know, but that would be slightly annoying from a player's point of view. They get an item but it has the default stuff until they put it in their currently equipped item slot.
  10. Well PlayerTickEvent + specific slots might not work the best, it would require the player to put the item in the right slot before it was setup. Maybe the best option would be to set everything client side through ItemTooltipEvent and just send a packet to the server and set the values that way?
  11. Ok - I'll look into implementing it anyways. Though a quick question regarding setting the values: what's the best way to set these values up? I don't want to use the PlayerTickEvent because I don't feel comfortable iterating through every player's inventory every tick to update information. ItemCraftedEvent doesn't really work (though I might not even need to set stuff up by crafting), I think there's an OpenContainer event which would handle things spawned in chests, maybe there are other events that would do this in a better way?
  12. Thanks, that's what I was thinking. So I'll still need events to set everything up...which makes me wonder whether or not it is actually worth converting everything to a capability.
  13. That makes sense. But am I understand the part about adding data and attaching capabilities?
  14. I don't understand how you can use ItemCraftedEvent to add NBT based on this. Whenever I try the NBT is never saved/added correctly. I was hoping capabilities would be able to solve this but it doesn't look like. Just so I'm understanding things right, you can't add capability data when you attach the capability?
  15. Yes, but what about for vanilla items? I don't have access to those methods. I'm trying to add information to my own weapons + vanilla's weapons (and other mods weapons should everything be compatible). The problem is I don't know where I would setup all this information - I read something where you couldn't add information to the capability in the AttachCapabilityEvent. If that is the case, where would I do it for vanilla items? Events don't seem to be the place because half of them don't work as intended (e.g. you can't use ItemCraftedEvent to update NBT because that's not what it's designed for).
  16. Yes I am using the ItemStack sensitive, so I think that solves that issue. I need the player for some of the information I'm setting. For example, the player has a level and whenever the player creates/gets a new weapon, that weapon should have the same level as the player. I know I need to use AttachCapabilityEvent to register the capability, but could I use that to setup the data for the item?
  17. I'm trying to add some extra data to items and I have been using NBT data for that in the past, though I was wondering if I should be using capabilities now since I'm using 1.12. However, I have a few questions about it. The capability stores all of the information within itself, and not on the itemstack's NBT, right? If that's the case, that would seem to mess up how I'm overwriting the ItemStack's Attributes. Right now, I am creating an AttributeModifier's NBT taglist which when I apply it to a weapon for instance, it uses my AttributeModifiers instead of the vanilla default one. Though if I'm storing this tag inside the capability, the ItemStack won't know it's there (if I'm thinking correctly). Other than that, it seems like I can store the other information fairly easily. The other question though is actually adding this information to the capability. I can't add the information within the AttachCapabilityEvent because one of what I've read up on, and two because I need an EntityPlayer to be passed in somehow. That leaves me to use events again and I've already had several issues with those which is why I'm looking into setting this stuff up in a capability. In the end, if anyone could provide some more information on how the item capability works and if it will even be a solution to my problem. Thanks!
  18. Yeah I've already thought about migrating. But ItemCraftedEvent doesn't work properly - adding NBT to the stack doesn't work for whatever reason. I need to look into capabilities for items - I've used them for player and entities before. I might make another topic about that because I have some more questions about that but I want to look more in-depth at it first. As far as this issue goes, I have no idea why it's getting called twice - ItemCraftedEvent calls it once and PlayerTickEvent calls it twice.
  19. I'm using PlayerTick because that's the only event where I can setup the NBT for the item for crafting, drops, chest loot, you name it, unless there is a better way to do that. 1) But no, there is only one sword. It wouldn't matter because the NBT value is unique to each stack. 2) Nope, the event is the only place this is called.
  20. Ok, that helps somewhat - I might've made a logical error somewhere then. public static void createWeapon(ItemStack stack, EntityPlayer player) { NBTTagCompound nbt = NBTHelper.loadStackNBT(stack); IPlayerInformation playerInfo = player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null); if (playerInfo != null) { if (Rarity.getRarity(nbt) == Rarity.DEFAULT) { nbt.setInteger("HideFlags", 6); // hides Attribute Modifier and Unbreakable tags Rarity.setRarity(nbt, Rarity.getRandomRarity(nbt, player.getEntityWorld().rand)); // sets a random rarity nbt.setInteger("Level", 1); // set level to current player level setRandomAttributes(stack, nbt, Rarity.getRarity(nbt), player); setAttributeModifiers(nbt, stack, player); stack.setStackDisplayName(Rarity.getRarity(nbt).getColor() + stack.getDisplayName()); NBTHelper.saveStackNBT(stack, nbt); } } } This is the method that gets fired from the PlayerTickEvent. If I output the world time in this block, it gets run twice (and increments too). Shouldn't it only run once though? Edit: I have very similar code also running on 1.11.2 that only gets run once in this period of time, which is why I'm confused.
  21. Yes and yes - I linked a gist up top. Let me know if that doesn't work.
  22. Yes I know - I'm checking for the START phase. Still runs twice.
  23. I'm subscribing to the PlayerTickEvent in order to setup some NBT on items as they enter an inventory. However, the code used to create the NBT is being run twice on the Server Thread. You can look at my event here as well as the class I used to generate the NBT. I feel like I'm missing something obvious but I have code very similar to this which works perfectly fine and is only called once per tick in 1.11.2. For whatever reason the method in the second gist gets called twice. Another thing that is weird is when looking at the output, the item is always assigned the rarity from the first call but there's another variable which just stores a number which is always assigned to the second call. I'm just not sure what's happening, so any help is appreciated.
  24. I would update and use Structure Blocks. It's as simple as loading and spawning the NBT file in two lines of code. Though if you need it for 1.9.4, then you might be out of luck with it.
×
×
  • Create New...

Important Information

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