diff --git a/patchwork-events-entity/src/main/java/net/minecraftforge/client/event/RenderPlayerEvent.java b/patchwork-events-entity/src/main/java/net/minecraftforge/client/event/RenderPlayerEvent.java new file mode 100644 index 00000000..36346cd3 --- /dev/null +++ b/patchwork-events-entity/src/main/java/net/minecraftforge/client/event/RenderPlayerEvent.java @@ -0,0 +1,79 @@ +/* + * Minecraft Forge, Patchwork Project + * Copyright (c) 2016-2020, 2019-2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.client.event; + +import net.minecraftforge.event.entity.player.PlayerEvent; + +import net.minecraft.client.render.entity.PlayerEntityRenderer; +import net.minecraft.entity.player.PlayerEntity; + +public abstract class RenderPlayerEvent extends PlayerEvent { + private final PlayerEntityRenderer renderer; + private final float partialRenderTick; + private final double x; + private final double y; + private final double z; + + public RenderPlayerEvent(PlayerEntity player, PlayerEntityRenderer renderer, float partialRenderTick, double x, double y, double z) { + super(player); + this.renderer = renderer; + this.partialRenderTick = partialRenderTick; + this.x = x; + this.y = y; + this.z = z; + } + + public PlayerEntityRenderer getRenderer() { + return renderer; + } + + public float getPartialRenderTick() { + return partialRenderTick; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public static class Pre extends RenderPlayerEvent { + public Pre(PlayerEntity player, PlayerEntityRenderer renderer, float tick, double x, double y, double z) { + super(player, renderer, tick, x, y, z); + } + + @Override + public boolean isCancelable() { + return true; + } + } + + public static class Post extends RenderPlayerEvent { + public Post(PlayerEntity player, PlayerEntityRenderer renderer, float tick, double x, double y, double z) { + super(player, renderer, tick, x, y, z); + } + } +} diff --git a/patchwork-events-entity/src/main/java/net/patchworkmc/mixin/event/entity/MixinPlayerEntityRenderer.java b/patchwork-events-entity/src/main/java/net/patchworkmc/mixin/event/entity/MixinPlayerEntityRenderer.java new file mode 100644 index 00000000..2096e1ed --- /dev/null +++ b/patchwork-events-entity/src/main/java/net/patchworkmc/mixin/event/entity/MixinPlayerEntityRenderer.java @@ -0,0 +1,50 @@ +/* + * Minecraft Forge, Patchwork Project + * Copyright (c) 2016-2020, 2019-2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.patchworkmc.mixin.event.entity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraftforge.client.event.RenderPlayerEvent; +import net.minecraftforge.common.MinecraftForge; + +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.render.entity.PlayerEntityRenderer; + +@Mixin(PlayerEntityRenderer.class) +public class MixinPlayerEntityRenderer { + @Inject(method = "render", at = @At(value = "INVOKE", ordinal = 0, shift = Shift.BEFORE, + target = "net/minecraft/client/network/AbstractClientPlayerEntity.isInSneakingPose()Z"), cancellable = true) + private void preRender(AbstractClientPlayerEntity playerEntity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) { + PlayerEntityRenderer me = (PlayerEntityRenderer) (Object) this; + + if (MinecraftForge.EVENT_BUS.post(new RenderPlayerEvent.Pre(playerEntity, me, partialTicks, x, y, z))) { + ci.cancel(); + } + } + + @Inject(method = "render", at = @At("RETURN")) + private void postRender(AbstractClientPlayerEntity playerEntity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) { + PlayerEntityRenderer me = (PlayerEntityRenderer) (Object) this; + MinecraftForge.EVENT_BUS.post(new RenderPlayerEvent.Post(playerEntity, me, partialTicks, x, y, z)); + } +} diff --git a/patchwork-events-entity/src/main/resources/fabric.mod.json b/patchwork-events-entity/src/main/resources/fabric.mod.json index f3a9aaed..50574655 100644 --- a/patchwork-events-entity/src/main/resources/fabric.mod.json +++ b/patchwork-events-entity/src/main/resources/fabric.mod.json @@ -17,6 +17,7 @@ }, "depends": { "patchwork-api-base": "*", + "patchwork-extensions": "*", "patchwork-extensions-item": "*" }, "mixins": [ diff --git a/patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json b/patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json index 55275923..57860500 100644 --- a/patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json +++ b/patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json @@ -31,7 +31,8 @@ "MixinClientPlayerEntity", "MixinClientWorld", "MixinItemStack", - "MixinOtherClientPlayerEntity" + "MixinOtherClientPlayerEntity", + "MixinPlayerEntityRenderer" ], "injectors": { "defaultRequire": 1