Jump to content

Fractangle

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Fractangle

  1. Thanks! I had originally been off-put by the Javadoc on FMLLoadCompleteEvent due to it saying "Mods should not in general override or otherwise attempt to implement this event." Correct me if I'm wrong, but looking at the Javadoc for TagsUpdatedEvent, it appears that it could fire multiple times during the server's lifecycle? (e.g. after doing a /ct reload in a pack that includes CraftTweaker)
  2. I want to parse certain items out of a list of all registered items, so I need it to only run after all items have been registered. What event ought I subscribe to?
  3. Sixth time's the charm? šŸ¤£ public static final String FIREWORK_ITEM_SRG = "field_184566_a"; public static final Field FIREWORK_ITEM_FIELD = ObfuscationReflectionHelper.findField(FireworkRocketEntity.class, FIREWORK_ITEM_SRG); // [stuff] DataParameter<ItemStack> FIREWORK_ITEM; FIREWORK_ITEM_FIELD.setAccessible(true); try { FIREWORK_ITEM = (DataParameter<ItemStack>) FIREWORK_ITEM_FIELD.get(rocket); } catch(IllegalAccessException e) { throw new WTFException("I literally just called setAccessible(true)"); }
  4. Like this? public static final String FIREWORK_ITEM_SRG = "field_184566_a"; // [a bunch of unrelated stuff in the class] DataParameter<ItemStack> FIREWORK_ITEM = ObfuscationReflectionHelper.getPrivateValue(FireworkRocketEntity.class, null, FIREWORK_ITEM_SRG); CompoundNBT fireworkData = rocketDataManager.get(FIREWORK_ITEM).getTag();
  5. Whew, thanks for that one! I've got it using the SRG name now, and looking the field up only once. public static final DataParameter<ItemStack> FIREWORK_ITEM = ObfuscationReflectionHelper.getPrivateValue(FireworkRocketEntity.class, null, "field_184566_a");
  6. Good point! (I've never done that before, hence why I overlooked it. Back in a bit with cleaner code once I've done some Learningā„¢!) Edit: As promised, the working reflection-based code: double ax, ay, az, bx, by, bz; double range = 32; ax = player.getPosX() - range; ay = player.getPosY() - range; az = player.getPosZ() - range; bx = player.getPosX() + range; by = player.getPosY() + range; bz = player.getPosZ() + range; AxisAlignedBB boundingBox = new AxisAlignedBB(ax, ay, az, bx, by, bz); List<FireworkRocketEntity> rocketsLotsOfRockets = world.getEntitiesWithinAABB(FireworkRocketEntity.class, boundingBox, null); for(FireworkRocketEntity rocket : rocketsLotsOfRockets) { EntityDataManager rocketDataManager = rocket.getDataManager(); Field fireworkItemField; try { fireworkItemField = FireworkRocketEntity.class.getDeclaredField("FIREWORK_ITEM"); fireworkItemField.setAccessible(true); DataParameter<ItemStack> FIREWORK_ITEM = (DataParameter<ItemStack>)fireworkItemField.get(null); ItemStack stack = rocketDataManager.get(FIREWORK_ITEM); SSoMM.PAUL_BUNYAN.log(Level.DEBUG, stack.getTag()); } catch(NoSuchFieldException e) { throw new WTFException("FireworkRocketEntity class was missing the FIREWORK_ITEM field...?!"); } catch(IllegalAccessException e) { throw new WTFException("I literally just called setAccessible(true)"); } }
  7. Ah okay, that makes sense! Thank you! I've got something that works, but it's a little gross (due to FireworkRocketEntity.FIREWORK_ITEM being private): double ax, ay, az, bx, by, bz; double range = 32; ax = player.getPosX() - range; ay = player.getPosY() - range; az = player.getPosZ() - range; bx = player.getPosX() + range; by = player.getPosY() + range; bz = player.getPosZ() + range; AxisAlignedBB boundingBox = new AxisAlignedBB(ax, ay, az, bx, by, bz); List<FireworkRocketEntity> rocketsLotsOfRockets = world.getEntitiesWithinAABB(FireworkRocketEntity.class, boundingBox, null); for(FireworkRocketEntity rocket : rocketsLotsOfRockets) { List<EntityDataManager.DataEntry<?>> allRocketData = rocket.getDataManager().getAll(); if(allRocketData == null) { SSoMM.PAUL_BUNYAN.log(Level.DEBUG, "Rocket data had no data"); return false; } for(EntityDataManager.DataEntry<?> datum : allRocketData) { Object value = datum.getValue(); if(value instanceof ItemStack) { ItemStack stack = (ItemStack) value; CompoundNBT tag = stack.getTag(); SSoMM.PAUL_BUNYAN.log(Level.DEBUG, tag); } } } Might be a bit niche, but I figured I'd throw it out there in case anybody else can use it.
  8. I'm not sure I understand what you mean by "replicate it" on the server side. For context, I only care about the firework data on the server side - my use case is for the presence of a correctly-colored-patterned-etc firework to trigger the spawning of a mob, hence why I ruled out sending a custom packet from client to server. (Don't want a client spoofing the firework presence!)
  9. I'm trying to determine if there's a firework with particular colors/effects/shapes near a player. This is what I have so far: double ax, ay, az, bx, by, bz; double range = 32; ax = player.getPosX() - range; ay = player.getPosY() - range; az = player.getPosZ() - range; bx = player.getPosX() + range; by = player.getPosY() + range; bz = player.getPosZ() + range; AxisAlignedBB boundingBox = new AxisAlignedBB(ax, ay, az, bx, by, bz); List<FireworkRocketEntity> rocketsLotsOfRockets = world.getEntitiesWithinAABB(FireworkRocketEntity.class, boundingBox, null); for(FireworkRocketEntity rocket : rocketsLotsOfRockets) { Set<String> tags = rocket.getTags(); if(player.isSneaking()) { SSoMM.PAUL_BUNYAN.log(Level.DEBUG, "Rocket data: " + tags.size() + " tags"); for(String tag : tags) { SSoMM.PAUL_BUNYAN.log(Level.DEBUG, "\t" + tag); } } } But looking at the logs, all I get is (a spam of) "Rocket data: 0 tags". This is because rocket.getTags() is returning an (empty) array of Tag-system tags, not NBT tags, right? How do I get the NBT data containing the colors and effects and so forth?
  10. So I'm new to modding, and I've spent the last few hours trying to get a basic client-side-only GUI to open when an item is right-clicked. Right when the GUI was supposed to open, Minecraft crashed, complaining of a toothache or a NullPointerException or something. Googling around eventually led me to realize that I hadn't registered my GUI handler, so I created an init() method in CommonProxy, and added the GUI handler registration. Still crashes with a server-side NPE. I google more, do some searches specifically on this forum, and meticulously check every line of code to see why the server is upset. Not a clue. At this point, I'm at the end of my rope, so I register here and prepare to post in Modder Support. But just in case, I do another forum search, and find a couple threads I'd not seen previously. Sadly, they didn't contain the magic I needed to fix my code. As I'm getting ready to write my post, it hits me. I forgot to call CommonProxy's init() method in the actual mod init. Here's a screenshot of my GUI right now: Figured you lovely folks could get a laugh out of my pain!
×
×
  • Create New...

Important Information

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