Jump to content

Printing the in_open_water parameter to Debug (F3) screen


Frozen Storm

Recommended Posts

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 by Frozen Storm
Link to comment
Share on other sites

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 by Frozen Storm
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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



×
×
  • Create New...

Important Information

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