diff --git a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java index ea615c6a6..7fe4a920e 100644 --- a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java +++ b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -71,6 +71,8 @@ import net.minecraft.util.Hand; import net.minecraft.util.MovementInput; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.TextFormatting; @@ -149,6 +151,14 @@ public class ForgeHooksClient public static boolean onDrawBlockHighlight(WorldRenderer context, ActiveRenderInfo info, RayTraceResult target, int subID, float partialTicks) { + switch (target.getType()) { + case BLOCK: + if (!(target instanceof BlockRayTraceResult)) return false; + return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent.HighlightBlock(context, info, target, subID, partialTicks)); + case ENTITY: + if (!(target instanceof EntityRayTraceResult)) return false; + return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent.HighlightEntity(context, info, target, subID, partialTicks)); + } return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, info, target, subID, partialTicks)); } diff --git a/src/main/java/net/minecraftforge/client/event/DrawBlockHighlightEvent.java b/src/main/java/net/minecraftforge/client/event/DrawBlockHighlightEvent.java index 59685b1c4..30515c6df 100644 --- a/src/main/java/net/minecraftforge/client/event/DrawBlockHighlightEvent.java +++ b/src/main/java/net/minecraftforge/client/event/DrawBlockHighlightEvent.java @@ -19,12 +19,19 @@ package net.minecraftforge.client.event; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.EntityRayTraceResult; import net.minecraftforge.eventbus.api.Cancelable; import net.minecraftforge.eventbus.api.Event; import net.minecraft.util.math.RayTraceResult; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.WorldRenderer; +/** + * An event called whenever the selection highlight around blocks is about to be rendered. + * Canceling this event stops the selection highlight from being rendered. + */ +//TODO: in 1.15 rename to DrawHighlightEvent @Cancelable public class DrawBlockHighlightEvent extends Event { @@ -48,4 +55,41 @@ public class DrawBlockHighlightEvent extends Event public RayTraceResult getTarget() { return target; } public int getSubID() { return subID; } public float getPartialTicks() { return partialTicks; } + + /** + * A variant of the DrawBlockHighlightEvent only called when a block is highlighted. + */ + @Cancelable + public static class HighlightBlock extends DrawBlockHighlightEvent + { + public HighlightBlock(WorldRenderer context, ActiveRenderInfo info, RayTraceResult target, int subID, float partialTicks) + { + super(context, info, target, subID, partialTicks); + } + + @Override + public BlockRayTraceResult getTarget() + { + return (BlockRayTraceResult) super.target; + } + } + + /** + * A variant of the DrawBlockHighlightEvent only called when an entity is highlighted. + * Canceling this event has no effect. + */ + @Cancelable + public static class HighlightEntity extends DrawBlockHighlightEvent + { + public HighlightEntity(WorldRenderer context, ActiveRenderInfo info, RayTraceResult target, int subID, float partialTicks) + { + super(context, info, target, subID, partialTicks); + } + + @Override + public EntityRayTraceResult getTarget() + { + return (EntityRayTraceResult) super.target; + } + } }