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

Commit

Permalink
Impl RenderPlayerEvent (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikka0w0 authored Aug 21, 2020
1 parent 04cbc4c commit b9a9155
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
1 change: 1 addition & 0 deletions patchwork-events-entity/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"depends": {
"patchwork-api-base": "*",
"patchwork-extensions": "*",
"patchwork-extensions-item": "*"
},
"mixins": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"MixinClientPlayerEntity",
"MixinClientWorld",
"MixinItemStack",
"MixinOtherClientPlayerEntity"
"MixinOtherClientPlayerEntity",
"MixinPlayerEntityRenderer"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b9a9155

Please sign in to comment.