|
81 | 81 | import net.minecraft.world.phys.Vec3; |
82 | 82 | import net.neoforged.bus.api.SubscribeEvent; |
83 | 83 | import net.neoforged.neoforge.client.ClientHooks; |
| 84 | +import net.neoforged.neoforge.client.event.ClientTickEvent; |
84 | 85 | import net.neoforged.neoforge.client.event.RenderArmEvent; |
85 | 86 | import net.neoforged.neoforge.client.event.RenderGuiLayerEvent; |
86 | 87 | import net.neoforged.neoforge.client.event.RenderHighlightEvent; |
|
90 | 91 | import net.neoforged.neoforge.client.gui.VanillaGuiLayers; |
91 | 92 | import net.neoforged.neoforge.client.model.data.ModelData; |
92 | 93 | import net.neoforged.neoforge.common.util.Lazy; |
93 | | -import net.neoforged.neoforge.event.TickEvent.ClientTickEvent; |
94 | | -import net.neoforged.neoforge.event.TickEvent.Phase; |
95 | 94 | import org.jetbrains.annotations.NotNull; |
96 | 95 | import org.jetbrains.annotations.Nullable; |
97 | 96 | import org.joml.Matrix3f; |
@@ -223,81 +222,79 @@ public void renderArm(RenderArmEvent event) { |
223 | 222 | } |
224 | 223 |
|
225 | 224 | @SubscribeEvent |
226 | | - public void tickEnd(ClientTickEvent event) { |
227 | | - if (event.phase == Phase.END) { |
228 | | - //Note: We check that the game mode is not null as if it is that means the world is unloading, and we don't actually want to be rendering |
229 | | - // as our data may be out of date or invalid. For example configs could unload while it is still unloading |
230 | | - if (minecraft.player != null && minecraft.player.level() != null && !minecraft.isPaused() && minecraft.gameMode != null) { |
231 | | - Player player = minecraft.player; |
232 | | - Level world = minecraft.player.level(); |
233 | | - //Traverse active jetpacks and do animations |
234 | | - for (UUID uuid : Mekanism.playerState.getActiveJetpacks()) { |
235 | | - Player p = world.getPlayerByUUID(uuid); |
236 | | - if (p != null) { |
237 | | - Pos3D playerPos = new Pos3D(p).translate(0, p.getEyeHeight(), 0); |
238 | | - Vec3 playerMotion = p.getDeltaMovement(); |
239 | | - float random = (world.random.nextFloat() - 0.5F) * 0.1F; |
240 | | - //This positioning code is somewhat cursed, but it seems to be mostly working and entity pose code seems cursed in general |
241 | | - float xRot; |
242 | | - if (p.isCrouching()) { |
243 | | - xRot = 20; |
244 | | - playerPos = playerPos.translate(0, 0.125, 0); |
| 225 | + public void tickEnd(ClientTickEvent.Post event) { |
| 226 | + //Note: We check that the game mode is not null as if it is that means the world is unloading, and we don't actually want to be rendering |
| 227 | + // as our data may be out of date or invalid. For example configs could unload while it is still unloading |
| 228 | + if (minecraft.player != null && minecraft.player.level() != null && !minecraft.isPaused() && minecraft.gameMode != null) { |
| 229 | + Player player = minecraft.player; |
| 230 | + Level world = minecraft.player.level(); |
| 231 | + //Traverse active jetpacks and do animations |
| 232 | + for (UUID uuid : Mekanism.playerState.getActiveJetpacks()) { |
| 233 | + Player p = world.getPlayerByUUID(uuid); |
| 234 | + if (p != null) { |
| 235 | + Pos3D playerPos = new Pos3D(p).translate(0, p.getEyeHeight(), 0); |
| 236 | + Vec3 playerMotion = p.getDeltaMovement(); |
| 237 | + float random = (world.random.nextFloat() - 0.5F) * 0.1F; |
| 238 | + //This positioning code is somewhat cursed, but it seems to be mostly working and entity pose code seems cursed in general |
| 239 | + float xRot; |
| 240 | + if (p.isCrouching()) { |
| 241 | + xRot = 20; |
| 242 | + playerPos = playerPos.translate(0, 0.125, 0); |
| 243 | + } else { |
| 244 | + float f = p.getSwimAmount(minecraft.getPartialTick()); |
| 245 | + if (p.isFallFlying()) { |
| 246 | + float f1 = (float) p.getFallFlyingTicks() + minecraft.getPartialTick(); |
| 247 | + float f2 = Mth.clamp(f1 * f1 / 100.0F, 0.0F, 1.0F); |
| 248 | + xRot = f2 * (-90.0F - p.getXRot()); |
245 | 249 | } else { |
246 | | - float f = p.getSwimAmount(minecraft.getPartialTick()); |
247 | | - if (p.isFallFlying()) { |
248 | | - float f1 = (float) p.getFallFlyingTicks() + minecraft.getPartialTick(); |
249 | | - float f2 = Mth.clamp(f1 * f1 / 100.0F, 0.0F, 1.0F); |
250 | | - xRot = f2 * (-90.0F - p.getXRot()); |
251 | | - } else { |
252 | | - float f3 = p.isInWater() ? -90.0F - p.getXRot() : -90.0F; |
253 | | - xRot = Mth.lerp(f, 0.0F, f3); |
254 | | - } |
255 | | - xRot = -xRot; |
256 | | - Pos3D eyeAdjustments; |
257 | | - if (p.isFallFlying() && (p != player || !minecraft.options.getCameraType().isFirstPerson())) { |
258 | | - eyeAdjustments = new Pos3D(0, p.getEyeHeight(Pose.STANDING), 0).xRot(xRot).yRot(p.yBodyRot); |
259 | | - } else if (p.isVisuallySwimming()) { |
260 | | - eyeAdjustments = new Pos3D(0, p.getEyeHeight(), 0).xRot(xRot).yRot(p.yBodyRot).translate(0, 0.5, 0); |
261 | | - } else { |
262 | | - eyeAdjustments = new Pos3D(0, p.getEyeHeight(), 0).xRot(xRot).yRot(p.yBodyRot); |
263 | | - } |
264 | | - playerPos = new Pos3D(p.getX() + eyeAdjustments.x, p.getY() + eyeAdjustments.y, p.getZ() + eyeAdjustments.z); |
| 250 | + float f3 = p.isInWater() ? -90.0F - p.getXRot() : -90.0F; |
| 251 | + xRot = Mth.lerp(f, 0.0F, f3); |
| 252 | + } |
| 253 | + xRot = -xRot; |
| 254 | + Pos3D eyeAdjustments; |
| 255 | + if (p.isFallFlying() && (p != player || !minecraft.options.getCameraType().isFirstPerson())) { |
| 256 | + eyeAdjustments = new Pos3D(0, p.getEyeHeight(Pose.STANDING), 0).xRot(xRot).yRot(p.yBodyRot); |
| 257 | + } else if (p.isVisuallySwimming()) { |
| 258 | + eyeAdjustments = new Pos3D(0, p.getEyeHeight(), 0).xRot(xRot).yRot(p.yBodyRot).translate(0, 0.5, 0); |
| 259 | + } else { |
| 260 | + eyeAdjustments = new Pos3D(0, p.getEyeHeight(), 0).xRot(xRot).yRot(p.yBodyRot); |
265 | 261 | } |
266 | | - Pos3D vLeft = new Pos3D(-0.43, -0.55, -0.54).xRot(xRot).yRot(p.yBodyRot); |
267 | | - renderJetpackSmoke(world, playerPos.translate(vLeft, playerMotion), vLeft.scale(0.2).translate(playerMotion, vLeft.scale(random))); |
268 | | - Pos3D vRight = new Pos3D(0.43, -0.55, -0.54).xRot(xRot).yRot(p.yBodyRot); |
269 | | - renderJetpackSmoke(world, playerPos.translate(vRight, playerMotion), vRight.scale(0.2).translate(playerMotion, vRight.scale(random))); |
270 | | - Pos3D vCenter = new Pos3D((world.random.nextFloat() - 0.5) * 0.4, -0.86, -0.30).xRot(xRot).yRot(p.yBodyRot); |
271 | | - renderJetpackSmoke(world, playerPos.translate(vCenter, playerMotion), vCenter.scale(0.2).translate(playerMotion)); |
| 262 | + playerPos = new Pos3D(p.getX() + eyeAdjustments.x, p.getY() + eyeAdjustments.y, p.getZ() + eyeAdjustments.z); |
272 | 263 | } |
| 264 | + Pos3D vLeft = new Pos3D(-0.43, -0.55, -0.54).xRot(xRot).yRot(p.yBodyRot); |
| 265 | + renderJetpackSmoke(world, playerPos.translate(vLeft, playerMotion), vLeft.scale(0.2).translate(playerMotion, vLeft.scale(random))); |
| 266 | + Pos3D vRight = new Pos3D(0.43, -0.55, -0.54).xRot(xRot).yRot(p.yBodyRot); |
| 267 | + renderJetpackSmoke(world, playerPos.translate(vRight, playerMotion), vRight.scale(0.2).translate(playerMotion, vRight.scale(random))); |
| 268 | + Pos3D vCenter = new Pos3D((world.random.nextFloat() - 0.5) * 0.4, -0.86, -0.30).xRot(xRot).yRot(p.yBodyRot); |
| 269 | + renderJetpackSmoke(world, playerPos.translate(vCenter, playerMotion), vCenter.scale(0.2).translate(playerMotion)); |
273 | 270 | } |
| 271 | + } |
274 | 272 |
|
275 | | - if (world.getGameTime() % 4 == 0) { |
276 | | - //Traverse active scuba masks and do animations |
277 | | - for (UUID uuid : Mekanism.playerState.getActiveScubaMasks()) { |
278 | | - Player p = world.getPlayerByUUID(uuid); |
279 | | - if (p != null && p.isInWater()) { |
280 | | - Pos3D vec = new Pos3D(0.4, 0.4, 0.4).multiply(p.getViewVector(1)).translate(0, -0.2, 0); |
281 | | - Pos3D motion = vec.scale(0.2).translate(p.getDeltaMovement()); |
282 | | - Pos3D v = new Pos3D(p).translate(0, p.getEyeHeight(), 0).translate(vec); |
283 | | - world.addParticle(MekanismParticleTypes.SCUBA_BUBBLE.get(), v.x, v.y, v.z, motion.x, motion.y + 0.2, motion.z); |
284 | | - } |
| 273 | + if (world.getGameTime() % 4 == 0) { |
| 274 | + //Traverse active scuba masks and do animations |
| 275 | + for (UUID uuid : Mekanism.playerState.getActiveScubaMasks()) { |
| 276 | + Player p = world.getPlayerByUUID(uuid); |
| 277 | + if (p != null && p.isInWater()) { |
| 278 | + Pos3D vec = new Pos3D(0.4, 0.4, 0.4).multiply(p.getViewVector(1)).translate(0, -0.2, 0); |
| 279 | + Pos3D motion = vec.scale(0.2).translate(p.getDeltaMovement()); |
| 280 | + Pos3D v = new Pos3D(p).translate(0, p.getEyeHeight(), 0).translate(vec); |
| 281 | + world.addParticle(MekanismParticleTypes.SCUBA_BUBBLE.get(), v.x, v.y, v.z, motion.x, motion.y + 0.2, motion.z); |
285 | 282 | } |
286 | | - //Traverse players and do animations for idle flamethrowers |
287 | | - for (Player p : world.players()) { |
288 | | - if (!p.swinging) { |
289 | | - if (player.isUsingItem()) { |
290 | | - InteractionHand usedHand = player.getUsedItemHand(); |
291 | | - if (!(player.getItemInHand(usedHand).getItem() instanceof ItemFlamethrower)) { |
292 | | - //If we the used item isn't a flamethrower, grab the other hand's item for checks |
293 | | - // if it was an active flamethrower we just skip adding the idle particles |
294 | | - tryAddIdleFlamethrowerParticles(minecraft, p, usedHand == InteractionHand.MAIN_HAND ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND); |
295 | | - } |
296 | | - } else if (!tryAddIdleFlamethrowerParticles(minecraft, p, InteractionHand.MAIN_HAND)) { |
297 | | - //If the player isn't using an item, try to first add particles for a flamethrower in the main hand |
298 | | - // and then add particles for a flamethrower in the offhand if we failed |
299 | | - tryAddIdleFlamethrowerParticles(minecraft, p, InteractionHand.OFF_HAND); |
| 283 | + } |
| 284 | + //Traverse players and do animations for idle flamethrowers |
| 285 | + for (Player p : world.players()) { |
| 286 | + if (!p.swinging) { |
| 287 | + if (player.isUsingItem()) { |
| 288 | + InteractionHand usedHand = player.getUsedItemHand(); |
| 289 | + if (!(player.getItemInHand(usedHand).getItem() instanceof ItemFlamethrower)) { |
| 290 | + //If we the used item isn't a flamethrower, grab the other hand's item for checks |
| 291 | + // if it was an active flamethrower we just skip adding the idle particles |
| 292 | + tryAddIdleFlamethrowerParticles(minecraft, p, usedHand == InteractionHand.MAIN_HAND ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND); |
300 | 293 | } |
| 294 | + } else if (!tryAddIdleFlamethrowerParticles(minecraft, p, InteractionHand.MAIN_HAND)) { |
| 295 | + //If the player isn't using an item, try to first add particles for a flamethrower in the main hand |
| 296 | + // and then add particles for a flamethrower in the offhand if we failed |
| 297 | + tryAddIdleFlamethrowerParticles(minecraft, p, InteractionHand.OFF_HAND); |
301 | 298 | } |
302 | 299 | } |
303 | 300 | } |
|
0 commit comments