-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 3af621d)
- Loading branch information
Showing
9 changed files
with
376 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package mcp.mobius.waila.api; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.HitResult; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* Used to redirect the targeted objet to other object. | ||
* | ||
* @see IBlockComponentProvider#redirect(ITargetRedirector, IBlockAccessor, IPluginConfig) | ||
* @see IEntityComponentProvider#redirect(ITargetRedirector, IEntityAccessor, IPluginConfig) | ||
*/ | ||
@ApiStatus.Experimental | ||
@ApiStatus.NonExtendable | ||
public interface ITargetRedirector { | ||
|
||
/** | ||
* Redirect the current object to itself. | ||
* <p> | ||
* This also restrict lower priority provider from redirecting the object, | ||
* return {@code null} instead if the caller doesn't redirect. | ||
*/ | ||
Result toSelf(); | ||
|
||
/** | ||
* Redirect to nowhere, disabling the tooltip to be displayed. | ||
*/ | ||
Result toNowhere(); | ||
|
||
/** | ||
* Redirect to whatever object behind this object, essentially making this object appear invisible. | ||
*/ | ||
Result toBehind(); | ||
|
||
/** | ||
* Redirect to specific object at the hit result's position. | ||
* <p> | ||
* <b>Note:</b> {@link BlockHitResult#withPosition(BlockPos)} will have the original | ||
* {@linkplain HitResult#getLocation() hit location} (not to be confused with | ||
* {@linkplain BlockHitResult#getBlockPos() block position}), you need to take | ||
* account if the redirect target is not from something you own (e.g. redirecting | ||
* to other mod's block). | ||
*/ | ||
Result to(HitResult hitResult); | ||
|
||
/** | ||
* Redirection result, only here to make sure it's not called multiple times. | ||
*/ | ||
@ApiStatus.NonExtendable | ||
interface Result { | ||
|
||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/mcp/mobius/waila/gui/hud/TargetRedirector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package mcp.mobius.waila.gui.hud; | ||
|
||
import mcp.mobius.waila.api.ITargetRedirector; | ||
import net.minecraft.world.phys.HitResult; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class TargetRedirector implements ITargetRedirector { | ||
|
||
private static final TargetRedirector INSTANCE = new TargetRedirector(); | ||
private static final Result RESULT = new Result(); | ||
|
||
public boolean self, nowhere, behind; | ||
public @Nullable HitResult to; | ||
|
||
public static TargetRedirector get() { | ||
INSTANCE.self = false; | ||
INSTANCE.nowhere = false; | ||
INSTANCE.behind = false; | ||
INSTANCE.to = null; | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public Result toSelf() { | ||
self = true; | ||
return RESULT; | ||
} | ||
|
||
@Override | ||
public Result toNowhere() { | ||
nowhere = true; | ||
return RESULT; | ||
} | ||
|
||
@Override | ||
public Result toBehind() { | ||
behind = true; | ||
return RESULT; | ||
} | ||
|
||
@Override | ||
public Result to(HitResult hitResult) { | ||
to = hitResult; | ||
return RESULT; | ||
} | ||
|
||
public static class Result implements ITargetRedirector.Result { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.