Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit b9a9155

Browse files
authored
Impl RenderPlayerEvent (#183)
1 parent 04cbc4c commit b9a9155

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.minecraftforge.client.event;
21+
22+
import net.minecraftforge.event.entity.player.PlayerEvent;
23+
24+
import net.minecraft.client.render.entity.PlayerEntityRenderer;
25+
import net.minecraft.entity.player.PlayerEntity;
26+
27+
public abstract class RenderPlayerEvent extends PlayerEvent {
28+
private final PlayerEntityRenderer renderer;
29+
private final float partialRenderTick;
30+
private final double x;
31+
private final double y;
32+
private final double z;
33+
34+
public RenderPlayerEvent(PlayerEntity player, PlayerEntityRenderer renderer, float partialRenderTick, double x, double y, double z) {
35+
super(player);
36+
this.renderer = renderer;
37+
this.partialRenderTick = partialRenderTick;
38+
this.x = x;
39+
this.y = y;
40+
this.z = z;
41+
}
42+
43+
public PlayerEntityRenderer getRenderer() {
44+
return renderer;
45+
}
46+
47+
public float getPartialRenderTick() {
48+
return partialRenderTick;
49+
}
50+
51+
public double getX() {
52+
return x;
53+
}
54+
55+
public double getY() {
56+
return y;
57+
}
58+
59+
public double getZ() {
60+
return z;
61+
}
62+
63+
public static class Pre extends RenderPlayerEvent {
64+
public Pre(PlayerEntity player, PlayerEntityRenderer renderer, float tick, double x, double y, double z) {
65+
super(player, renderer, tick, x, y, z);
66+
}
67+
68+
@Override
69+
public boolean isCancelable() {
70+
return true;
71+
}
72+
}
73+
74+
public static class Post extends RenderPlayerEvent {
75+
public Post(PlayerEntity player, PlayerEntityRenderer renderer, float tick, double x, double y, double z) {
76+
super(player, renderer, tick, x, y, z);
77+
}
78+
}
79+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.event.entity;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.injection.At;
24+
import org.spongepowered.asm.mixin.injection.At.Shift;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
27+
import net.minecraftforge.client.event.RenderPlayerEvent;
28+
import net.minecraftforge.common.MinecraftForge;
29+
30+
import net.minecraft.client.network.AbstractClientPlayerEntity;
31+
import net.minecraft.client.render.entity.PlayerEntityRenderer;
32+
33+
@Mixin(PlayerEntityRenderer.class)
34+
public class MixinPlayerEntityRenderer {
35+
@Inject(method = "render", at = @At(value = "INVOKE", ordinal = 0, shift = Shift.BEFORE,
36+
target = "net/minecraft/client/network/AbstractClientPlayerEntity.isInSneakingPose()Z"), cancellable = true)
37+
private void preRender(AbstractClientPlayerEntity playerEntity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
38+
PlayerEntityRenderer me = (PlayerEntityRenderer) (Object) this;
39+
40+
if (MinecraftForge.EVENT_BUS.post(new RenderPlayerEvent.Pre(playerEntity, me, partialTicks, x, y, z))) {
41+
ci.cancel();
42+
}
43+
}
44+
45+
@Inject(method = "render", at = @At("RETURN"))
46+
private void postRender(AbstractClientPlayerEntity playerEntity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
47+
PlayerEntityRenderer me = (PlayerEntityRenderer) (Object) this;
48+
MinecraftForge.EVENT_BUS.post(new RenderPlayerEvent.Post(playerEntity, me, partialTicks, x, y, z));
49+
}
50+
}

patchwork-events-entity/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"depends": {
1919
"patchwork-api-base": "*",
20+
"patchwork-extensions": "*",
2021
"patchwork-extensions-item": "*"
2122
},
2223
"mixins": [

patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"MixinClientPlayerEntity",
3232
"MixinClientWorld",
3333
"MixinItemStack",
34-
"MixinOtherClientPlayerEntity"
34+
"MixinOtherClientPlayerEntity",
35+
"MixinPlayerEntityRenderer"
3536
],
3637
"injectors": {
3738
"defaultRequire": 1

0 commit comments

Comments
 (0)