Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit a8f8976

Browse files
committed
Created HudOverlayEvent
1 parent abaab77 commit a8f8976

7 files changed

Lines changed: 439 additions & 0 deletions

File tree

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.event.defaults.game.render;
18+
19+
import me.zero.alpine.type.Cancellable;
20+
21+
/**
22+
* Called when various hud overlays are rendered. Can be cancelled,
23+
* preventing the overlay from being rendered.
24+
*
25+
* @see Type
26+
*
27+
* @author Brady
28+
* @since 5/24/2018 10:47 AM
29+
*/
30+
public final class HudOverlayEvent extends Cancellable {
31+
32+
/**
33+
* The type of overlay that is being rendered
34+
*/
35+
private final Type type;
36+
37+
public HudOverlayEvent(Type type) {
38+
this.type = type;
39+
}
40+
41+
/**
42+
* @return The type of overlay that is being rendered
43+
*/
44+
public final Type getType() {
45+
return this.type;
46+
}
47+
48+
public enum Type {
49+
/**
50+
* Rendered when the player is in water and their eye height is under the water level
51+
*/
52+
WATER,
53+
54+
/**
55+
* Rendered when the player is in lava and their eye height is under the lava level
56+
*/
57+
LAVA,
58+
59+
/**
60+
* Rendered when the player has a pumpkin on their head
61+
*/
62+
PUMPKIN,
63+
64+
/**
65+
* Transformation to the screen when the player takes damage
66+
*/
67+
HURTCAM,
68+
69+
/**
70+
* The scoreboard that is displayed on the right side of the screen
71+
*/
72+
SCOREBOARD,
73+
74+
/**
75+
* Rendered when the player is on fire
76+
*/
77+
FIRE,
78+
79+
/**
80+
* The entire stat bar
81+
*/
82+
STAT_ALL,
83+
84+
/**
85+
* The stat bar displaying the health level of the player
86+
*/
87+
STAT_HEALTH,
88+
89+
/**
90+
* The stat bar displaying the food level of the player
91+
*/
92+
STAT_FOOD,
93+
94+
/**
95+
* The stat bar displaying the armor level of the player
96+
*/
97+
STAT_ARMOR,
98+
99+
/**
100+
* The stat bar displaying the remaining air that the player has when underwater
101+
*/
102+
STAT_AIR,
103+
104+
/**
105+
* The boss bar rendered at the top of the screen showing the boss health
106+
*/
107+
BOSS_BAR,
108+
109+
/**
110+
* The bar displaying the current player experience level
111+
*/
112+
EXP_BAR,
113+
114+
/**
115+
* The vignette effect overlayed over the game
116+
*/
117+
VIGNETTE,
118+
119+
/**
120+
* The crosshair
121+
*/
122+
CROSSHAIR,
123+
124+
/**
125+
* The attack indicator displaying the remaining time until the player's attack is fully charged
126+
*/
127+
ATTACK_INDICATOR,
128+
129+
/**
130+
* The horse jump bar
131+
*/
132+
JUMP_BAR,
133+
134+
/**
135+
* The health of the currently mounted entity
136+
*/
137+
MOUNT_HEALTH,
138+
139+
/**
140+
* The overlay rendered when the player is inside of a nether portal
141+
*/
142+
PORTAL,
143+
144+
/**
145+
* The tooltip displayed over the hotbar when a new item is selected
146+
*/
147+
SELECTED_ITEM_TOOLTIP,
148+
149+
/**
150+
* The list of potion effects in the top right of the screen
151+
*/
152+
POTION_EFFECTS
153+
}
154+
}

src/main/java/clientapi/load/mixin/MixinEntityRenderer.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
package clientapi.load.mixin;
1818

1919
import clientapi.ClientAPI;
20+
import clientapi.event.defaults.game.render.HudOverlayEvent;
2021
import clientapi.event.defaults.game.render.RenderHudEvent;
2122
import clientapi.event.defaults.game.render.RenderScreenEvent;
2223
import clientapi.event.defaults.game.render.RenderWorldEvent;
2324
import clientapi.util.render.camera.Camera;
25+
import net.minecraft.block.material.Material;
26+
import net.minecraft.block.state.IBlockState;
2427
import net.minecraft.client.gui.GuiIngame;
2528
import net.minecraft.client.renderer.EntityRenderer;
2629
import org.spongepowered.asm.mixin.Mixin;
@@ -30,6 +33,9 @@
3033
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3134
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3235

36+
import static net.minecraft.block.material.Material.AIR;
37+
import static net.minecraft.block.material.Material.WATER;
38+
3339
/**
3440
* @author Brady
3541
* @since 4/27/2017 12:00 PM
@@ -58,4 +64,24 @@ private void onStartHand(int pass, float partialTicks, long finishTimeNano, Call
5864
guiIngame.renderGameOverlay(partialTicks);
5965
ClientAPI.EVENT_BUS.post(new RenderHudEvent(partialTicks));
6066
}
67+
68+
@Inject(method = "hurtCameraEffect", at = @At("HEAD"), cancellable = true)
69+
private void hurtCameraEffect(float partialTicks, CallbackInfo ci) {
70+
HudOverlayEvent event = new HudOverlayEvent(HudOverlayEvent.Type.HURTCAM);
71+
ClientAPI.EVENT_BUS.post(event);
72+
if (event.isCancelled())
73+
ci.cancel();
74+
}
75+
76+
@Redirect(method = "setupFog", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/state/IBlockState;getMaterial()Lnet/minecraft/block/material/Material;"))
77+
private Material setupFog$getMaterial(IBlockState iblockstate) {
78+
Material m = iblockstate.getMaterial();
79+
80+
HudOverlayEvent event = new HudOverlayEvent(m == WATER ? HudOverlayEvent.Type.WATER : HudOverlayEvent.Type.LAVA);
81+
ClientAPI.EVENT_BUS.post(event);
82+
if (!event.isCancelled())
83+
return AIR;
84+
85+
return m;
86+
}
6187
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.load.mixin;
18+
19+
import clientapi.ClientAPI;
20+
import clientapi.event.defaults.game.render.HudOverlayEvent;
21+
import net.minecraft.client.gui.GuiBossOverlay;
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.injection.At;
24+
import org.spongepowered.asm.mixin.injection.Inject;
25+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
26+
27+
/**
28+
* @author Brady
29+
* @since 5/24/2018 10:57 AM
30+
*/
31+
@Mixin(GuiBossOverlay.class)
32+
public class MixinGuiBossOverlay {
33+
34+
@Inject(method = "renderBossHealth", at = @At("HEAD"))
35+
private void renderBossHealth(CallbackInfo ci) {
36+
HudOverlayEvent event = new HudOverlayEvent(HudOverlayEvent.Type.BOSS_BAR);
37+
ClientAPI.EVENT_BUS.post(event);
38+
if (event.isCancelled())
39+
ci.cancel();
40+
}
41+
}

0 commit comments

Comments
 (0)