Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Printing the in_open_water parameter to Debug (F3) screen
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Frozen Storm

Printing the in_open_water parameter to Debug (F3) screen

By Frozen Storm, January 24 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Frozen Storm    0

Frozen Storm

Frozen Storm    0

  • Tree Puncher
  • Frozen Storm
  • Members
  • 0
  • 4 posts
Posted January 24 (edited)

According to the patch notes one of the recent updates added the in_open_water parameter. Is there a way to print the value of this parameter to the debug screen (F3) either for the currently targeted block or for the bobber when fishing?

 

I've managed to make a mod that adds something to the debug screen when the player is fishing:

@Mod("extended_debug")
public class ExtendedDebug
{
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    private static final Minecraft mc = Minecraft.getInstance();

    public ExtendedDebug() {
        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void onRenderOverlay(RenderGameOverlayEvent.Text event) {
        if (mc.gameSettings.showDebugInfo) {
    	    ArrayList<String> leftText = event.getLeft();
    	    ArrayList<String> rightText = event.getRight();
    	    if (mc.player.fishingBobber != null) {
    		    rightText.add("");
    		    rightText.add("HELLO WORLD!");
    	    }
        }
    }
}

 

This properly adds HELLO WORLD to the debug screen when the player is fishing, but I can't find anything in FishingBobberEntity to get information about whether the player is fishing in open water.

Edited January 25 by Frozen Storm
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56375 posts
Posted January 24

Look at FishingPredicate.

  • Quote

Share this post


Link to post
Share on other sites

Frozen Storm    0

Frozen Storm

Frozen Storm    0

  • Tree Puncher
  • Frozen Storm
  • Members
  • 0
  • 4 posts
Posted January 25 (edited)

I've looked at FishingPredicate, but both the documentation and the class definition I found with ctrl+click in Eclipse have some very confusing field and function names, so I'm having a little trouble with how I'm supposed to use it.

 

I've found a (somewhat old) post that explains briefly how Predicates work in general (although looking at the docs of other predicates, it seems the apply method has been renamed to test - or maybe this is specific to Forge API predicates?), but I'm not sure how I'm supposed to initialise FishingPredicate (or otherwise obtain it from the player/water block/fishing rod/...).

Edited January 25 by Frozen Storm
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56375 posts
Posted January 25

This is not ForgeAPI. This is decompiled Mojang code, as such documentation will be lackluster.

You need to look at the source code, in particular func_234638_a_.

  • Quote

Share this post


Link to post
Share on other sites

Frozen Storm    0

Frozen Storm

Frozen Storm    0

  • Tree Puncher
  • Frozen Storm
  • Members
  • 0
  • 4 posts
Posted January 25

So I've dived a bit more into the source code.

 

First off, there seem to be 3 ways to obtain an instance of FishingPredicate:

  1. A private constructor and a public static factory method (func_234640_a_) that seems to just invoke this constructor (whatever the reason for this particular design pattern might be).
  2. A serialization (func_234637_a_) and deserialization (func_234639_a_) method that handle JSONification of the object.
  3. An instance field (field_234635_a_) which seems to just be a fallback placeholder (similar to ANY in many other Predicates).

Of these three only the 1st one (func_234640_a_) seems relevant to me, since I don't know where I'd get the required JSON for 2, and 3 just simply always returns true in the test method, which probably isn't what I want. The 1st one is also used in FishingLootTables, namely with the argument true.

 

Additionally the class contains the boolean field_234636_b_, which seems to determine what value of in_open_water the predicate is looking for. Given the call in FishingLootTables I mentioned above, this would make sense, since treasure loot should only be added if in_open_water is true.

 

Last, the class contains the test method (func_234638_a_), which for a FishingBobberEntity argument (such as mc.player.fishingBobber in my code) returns whether the above field_234636_b_ is equal to the result of a call to the argument's func_234605_g_(). This method simply returns the value of a private boolean field (FishingBobberEntity#field_234595_aq_), which in turn gets set in FishingBobberEntity#tick with a check that seems like it could be for open water. Unfortunately I can't access the function FishingBobberEntity#func_234603_b_ (which is part of this check) in my code, as it's private, but I believe that performs the open water check for a specific block. The most sensible explanation for me would therefore be that FishingBobberEntity#func_234605_g_ returns whether the player is currently fishing.

 

However, I decided to display the results of the test method in-game, and it didn't work as expected. Namely, my mod now contains the following code:

@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent.Text event) {
	if (mc.gameSettings.showDebugInfo) {
		ArrayList<String> leftText = event.getLeft();
		ArrayList<String> rightText = event.getRight();
		if (mc.player.fishingBobber != null) {  // if player is currently fishing
			FishingPredicate alwaysTrue = FishingPredicate.field_234635_a_;  // this will just always return true
			FishingPredicate notIOW = FishingPredicate.func_234640_a_(false);  // this checks if in_open_water is false
			FishingPredicate isIOW = FishingPredicate.func_234640_a_(true);  // this checks if in_open_water is true
			rightText.add(Boolean.toString(mc.player.fishingBobber.func_234605_g_()));  // is bobber currently in open water?
			rightText.add(Boolean.toString(alwaysTrue.func_234638_a_(mc.player.fishingBobber)));
			rightText.add(Boolean.toString(notIOW.func_234640_a_(false).func_234638_a_(mc.player.fishingBobber)));
			rightText.add(Boolean.toString(isIOW.func_234640_a_(true).func_234638_a_(mc.player.fishingBobber)));
		}
	}
}

which checks the values of the methods I described. Unfortunately, func_234605_g_ just always returns true in-game, regardless of whether I'm fishing out in deep open water, or in a 2x2x1 pool I dug, or even on land. The predicates return values that fit this (so always returning true, false, true in the above code).

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56375 posts
Posted January 25
  • field_234635_a_ seems to be "default", it is returned if nothing is found in the JSON.
  • field_234636_b_ is "desired state" - the predicate matches if the "in open water" state matches this (i.e. if this is false, then this predicate matches not being in open water).
  • func_234605_g_ should do what you want. Not sure why not.
  • Quote

Share this post


Link to post
Share on other sites

Frozen Storm    0

Frozen Storm

Frozen Storm    0

  • Tree Puncher
  • Frozen Storm
  • Members
  • 0
  • 4 posts
Posted January 25

In order to debug this, I hacked the private FishingBobberEntity#func_234603_b_ to be callable using java reflection, and printed out its value for the block the bobber is in and for the player's targeted block (objectMouseOver). This does actually print out seemingly correct values (it prints out false for blocks near the shore and true for blocks further out).

 

I rechecked the code in FishingBobberEntity#tick and it seems the check only happens when a fish is catchable (ticksCatchable > 0 || ticksCatchableDelay > 0), otherwise it just returns true. I thought this explained the problem, but it's still erroneously printing true near the shore, even when the blobber gets pulled into the water (indicating a fish can be caught).

 

I guess I'll just use the hacky solution for now.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Sad Whale
      Game crashes whenever I try to increase the RAM

      By Sad Whale · Posted just now

      Would you mind explaining where I can find the debug.log
    • diesieben07
      Game crashes whenever I try to increase the RAM

      By diesieben07 · Posted 11 minutes ago

      That's not the debug.log.
    • Sad Whale
      Game crashes whenever I try to increase the RAM

      By Sad Whale · Posted 35 minutes ago

      Hopefully this works, if not let me know. hs_err_pid4708.log
    • diesieben07
      Game crashes whenever I try to increase the RAM

      By diesieben07 · Posted 46 minutes ago

      Post the debug.log.
    • Sad Whale
      Game crashes whenever I try to increase the RAM

      By Sad Whale · Posted 52 minutes ago

      Whenever I try to increase the amount of RAM allocated to Minecraft it crashes with exit code 1. I have the latest Java 64-bit update, I've uninstalled and reinstalled both Minecraft and Java and have tried multiple 1.16.5 Forge versions and none of them will allow me to allocate more than the 2 gigs that it already has allocated.
  • Topics

    • Sad Whale
      4
      Game crashes whenever I try to increase the RAM

      By Sad Whale
      Started 52 minutes ago

    • fluiX
      1
      server wont start

      By fluiX
      Started 1 hour ago

    • Luis_ST
      6
      [1.16.5] Help with custom Event

      By Luis_ST
      Started 5 hours ago

    • hammy3502
      1
      [1.16.4] Fluid Flowing Very Oddly

      By hammy3502
      Started 21 hours ago

    • <Gl33p_0r4nge>
      0
      [1.16.4] Screen Render

      By <Gl33p_0r4nge>
      Started 5 hours ago

  • Who's Online (See full list)

    • Sad Whale
    • diesieben07
    • Loganator711
    • therogueegamer
    • Microcellule
    • lupicus
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Printing the in_open_water parameter to Debug (F3) screen
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community