Skip to content

Commit

Permalink
Basic rendering works
Browse files Browse the repository at this point in the history
Offsets are broken, minimap too
  • Loading branch information
tr7zw committed Jan 26, 2020
1 parent fa00fd8 commit 19bd59d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.3-SNAPSHOT'
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -20,7 +20,7 @@ dependencies {
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
//modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.14.3
yarn_mappings=1.14.3+build.1
loader_version=0.4.8+build.155
minecraft_version=1.15.2
yarn_mappings=1.15.2+build.7
loader_version=0.7.6+build.179

# Mod Properties
mod_version = 1.0.1
mod_version = 1.0.2
maven_group = de.tr7zw
archives_base_name = FirstPersonMod

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
fabric_version=0.3.0+build.197
fabric_version=0.4.9+build.258-1.15
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ protected ArmorRendererMixin(FeatureRendererContext<T, M> featureRendererContext
super(featureRendererContext_1, bipedEntityModel_1, bipedEntityModel_2);
}

@Inject(at = @At("RETURN"), method = "method_4170")
protected void method_4170(A bipedEntityModel_1, EquipmentSlot var2, CallbackInfo info) {
if(FirstPersonModelMod.hideNextHeadArmor && var2 == EquipmentSlot.HEAD) {
@Inject(at = @At("RETURN"), method = "setVisible")
protected void setVisible(A bipedEntityModel_1, EquipmentSlot equipmentSlot_1, CallbackInfo info) {
if(FirstPersonModelMod.hideNextHeadArmor && equipmentSlot_1 == EquipmentSlot.HEAD) {
FirstPersonModelMod.hideNextHeadArmor = false;
bipedEntityModel_1.head.visible = false;
bipedEntityModel_1.headwear.visible = false;
bipedEntityModel_1.helmet.visible = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
import de.tr7zw.firstperson.FirstPersonModelMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;

@Mixin(EntityRenderDispatcher.class)
public class EntityRenderDispatcherMixin {

@Inject(at = @At("HEAD"), method = "render")
public void render(Entity entity_1, float float_1, boolean boolean_1, CallbackInfo info) {
if(MinecraftClient.getInstance().options.perspective != 0)return;
public <E extends Entity> E render(E entity_1, double double_1, double double_2, double double_3, float float_1, float float_2, MatrixStack matrixStack_1, VertexConsumerProvider vertexConsumerProvider_1, int int_1, CallbackInfo info) {
if(MinecraftClient.getInstance().options.perspective != 0)return null;
if(entity_1 instanceof AbstractClientPlayerEntity) {
if(!((PlayerEntity) entity_1).isMainPlayer())return;
if(!((PlayerEntity) entity_1).isMainPlayer())return null;
FirstPersonModelMod.hideNextHeadArmor = true;
FirstPersonModelMod.hideNextHeadItem = true;
FirstPersonModelMod.isRenderingPlayer = true;
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,45 @@

import com.mojang.blaze3d.platform.GlStateManager;

import de.tr7zw.firstperson.FirstPersonModelMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.FirstPersonRenderer;
import net.minecraft.client.render.GuiLighting;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.AbsoluteHand;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;

@Mixin(FirstPersonRenderer.class)
@Mixin(HeldItemRenderer.class)
public abstract class FirstPersonRendererMixin {


@Inject(at = @At("HEAD"), method = "renderFirstPersonItem", cancellable = true)
public void renderFirstPersonItem(float float_1, CallbackInfo info) {
public void renderFirstPersonItem(AbstractClientPlayerEntity abstractClientPlayerEntity_1, float float_1, float float_2, Hand hand_1, float float_3, ItemStack itemStack_1, float float_4, MatrixStack matrixStack_1, VertexConsumerProvider vertexConsumerProvider_1, int int_1, CallbackInfo info) {
if(MinecraftClient.getInstance().player.getMainHandStack().getItem() == Items.FILLED_MAP){
//render only offhand map
//float float_3 = MathHelper.lerp(float_1, MinecraftClient.getInstance().player.prevPitch, MinecraftClient.getInstance().player.pitch);
//float float_4 = MathHelper.lerp(float_1, MinecraftClient.getInstance().player.prevYaw, MinecraftClient.getInstance().player.yaw);
//this.rotate(float_3, float_4);
this.applyLightmap();
//this.applyLightmap();
//this.applyCameraAngles(float_1);
GlStateManager.enableRescaleNormal();
renderMapAsMinimap(MinecraftClient.getInstance().player.getMainHandStack());
GlStateManager.disableRescaleNormal();
GuiLighting.disable();
//GuiLighting.disable();
info.cancel();
}else if(MinecraftClient.getInstance().player.getOffHandStack().getItem() == Items.FILLED_MAP){
//render only offhand map
//float float_3 = MathHelper.lerp(float_1, MinecraftClient.getInstance().player.prevPitch, MinecraftClient.getInstance().player.pitch);
//float float_4 = MathHelper.lerp(float_1, MinecraftClient.getInstance().player.prevYaw, MinecraftClient.getInstance().player.yaw);
//this.rotate(float_3, float_4);
this.applyLightmap();
//this.applyLightmap();
//this.applyCameraAngles(float_1);
GlStateManager.enableRescaleNormal();
renderMapAsMinimap(MinecraftClient.getInstance().player.getOffHandStack());
GlStateManager.disableRescaleNormal();
GuiLighting.disable();
//GuiLighting.disable();
info.cancel();
} else {
info.cancel();
Expand All @@ -55,7 +56,7 @@ public void renderFirstPersonItem(float float_1, CallbackInfo info) {

public void renderMapAsMinimap(ItemStack item) {
GlStateManager.pushMatrix();
float size = (float)MinecraftClient.getInstance().getFramebuffer().viewWidth / (float)MinecraftClient.getInstance().getFramebuffer().viewHeight;
float size = (float)MinecraftClient.getInstance().getFramebuffer().viewportWidth / (float)MinecraftClient.getInstance().getFramebuffer().viewportHeight;
GlStateManager.translatef(0, 0.0f, 0.0f); // 3rd arg is size
float float_3 = 1.0F;
GlStateManager.translatef(float_3 * 0.125F, -0.125F, 0.0F);
Expand All @@ -70,20 +71,16 @@ public void renderMapAsMinimap(ItemStack item) {
GlStateManager.rotatef(float_5 * -45.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotatef(float_3 * float_5 * -30.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.translatef(0.33f, 0.65f, -0.2f);
this.renderFirstPersonMap(item);
//this.renderFirstPersonMap(null, null, 0, item);
GlStateManager.popMatrix();
GlStateManager.popMatrix();
}

@Shadow
abstract void renderFirstPersonMap(ItemStack itemStack_1);
@Shadow
abstract void renderMapInOneHand(float float_1, AbsoluteHand absoluteHand_1, float float_2, ItemStack itemStack_1);
@Shadow
abstract void rotate(float float_1, float float_2);
@Shadow
abstract void applyLightmap();
@Shadow
abstract void applyCameraAngles(float float_1);
abstract void renderFirstPersonMap(MatrixStack matrixStack_1, VertexConsumerProvider vertexConsumerProvider_1, int int_1, ItemStack itemStack_1);
//@Shadow
//abstract void renderMapInOneHand(float float_1, Arm absoluteHand_1, float float_2, ItemStack itemStack_1);
//@Shadow
//abstract void applyLightmap();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;

@Mixin(GameRenderer.class)
public class GameRendererMixin {

@Inject(at = @At("HEAD"), method = "bobView", cancellable = true)
private void bobView(float float_1, CallbackInfo info) {
private void bobView(MatrixStack matrixStack_1, float float_1, CallbackInfo info) {
info.cancel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import de.tr7zw.firstperson.FirstPersonModelMod;
import net.minecraft.client.render.entity.feature.ArmorBipedFeatureRenderer;
import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.feature.HeadFeatureRenderer;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.ModelWithHead;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;

@Mixin(HeadFeatureRenderer.class)
public abstract class HeadFeatureRendererMixin<T extends LivingEntity, M extends EntityModel<T> & ModelWithHead> extends FeatureRenderer<T, M> {

public HeadFeatureRendererMixin(FeatureRendererContext<T, M> featureRendererContext_1) {
super(featureRendererContext_1);
// TODO Auto-generated constructor stub
}

@Inject(at = @At("HEAD"), method = "method_17159", cancellable = true)
protected void method_17159(T livingEntity_1, float float_1, float float_2, float float_3, float float_4, float float_5, float float_6, float float_7, CallbackInfo info) {
@Inject(at = @At("HEAD"), method = "render", cancellable = true)
protected void render(MatrixStack matrixStack_1, VertexConsumerProvider vertexConsumerProvider_1, int int_1, T livingEntity_1, float float_1, float float_2, float float_3, float float_4, float float_5, float float_6, CallbackInfo info) {
if(FirstPersonModelMod.hideNextHeadItem) {
FirstPersonModelMod.hideNextHeadItem = false;
info.cancel();
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/de/tr7zw/firstperson/mixins/PlayerRenderMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import de.tr7zw.firstperson.FirstPersonModelMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.MathHelper;

@Mixin(PlayerEntityRenderer.class)
Expand Down Expand Up @@ -41,7 +43,7 @@ private void setModelPose(AbstractClientPlayerEntity abstractClientPlayerEntity_
if(FirstPersonModelMod.hideNextHeadItem) {
PlayerEntityModel<AbstractClientPlayerEntity> playerEntityModel_1 = (PlayerEntityModel)this.getModel();
playerEntityModel_1.head.visible = false;
playerEntityModel_1.headwear.visible = false;
playerEntityModel_1.helmet.visible = false;
}
}

Expand All @@ -51,7 +53,7 @@ private void setModelPose(AbstractClientPlayerEntity abstractClientPlayerEntity_
private AbstractClientPlayerEntity abstractClientPlayerEntity_1;
private double realYaw;

@ModifyVariable(method = "method_4215",
/*@ModifyVariable(method = "render",
at = @At("HEAD"),
ordinal = 0
)
Expand All @@ -67,7 +69,7 @@ public AbstractClientPlayerEntity playerGetter(AbstractClientPlayerEntity abstra
}
@ModifyVariable(method = "method_4215",
@ModifyVariable(method = "render",
at = @At("HEAD"),
ordinal = 0,
index = 1
Expand All @@ -93,15 +95,15 @@ public double playerCordX(double x) {
return x;
}
@ModifyVariable(method = "method_4215",
@ModifyVariable(method = "render",
at = @At("HEAD"),
ordinal = 1,
index = 2
)
public double playerCordY(double y) {
if (abstractClientPlayerEntity_1 != null && (!abstractClientPlayerEntity_1.isMainPlayer() || this.renderManager.camera != null && this.renderManager.camera.getFocusedEntity() == abstractClientPlayerEntity_1)) {
if(MinecraftClient.getInstance().player.isInSwimmingPose()) {
if(abstractClientPlayerEntity_1.prevPitch > 0 && abstractClientPlayerEntity_1.isInWater()) {
if(abstractClientPlayerEntity_1.prevPitch > 0 && abstractClientPlayerEntity_1.isSubmergedInWater()) {
y += 0.6f * Math.sin(Math.toRadians(abstractClientPlayerEntity_1.prevPitch));
}else {
y += 0.01f * -Math.sin(Math.toRadians(abstractClientPlayerEntity_1.prevPitch));
Expand All @@ -111,7 +113,7 @@ public double playerCordY(double y) {
return y;
}
@ModifyVariable(method = "method_4215",
@ModifyVariable(method = "render",
at = @At("HEAD"),
ordinal = 2,
index = 3
Expand All @@ -137,10 +139,10 @@ public double playerCordZ(double z) {
}
return z;
}
} */

@Inject(at = @At("RETURN"), method = "method_4215")
private void finishedRendering(AbstractClientPlayerEntity abstractClientPlayerEntity_1, double double_1, double double_2, double double_3, float float_1, float float_2, CallbackInfo info) {
@Inject(at = @At("RETURN"), method = "render")
private void finishedRendering(AbstractClientPlayerEntity abstractClientPlayerEntity_1, float float_1, float float_2, MatrixStack matrixStack_1, VertexConsumerProvider vertexConsumerProvider_1, int int_1, CallbackInfo info) {
abstractClientPlayerEntity_1 = null;
FirstPersonModelMod.isRenderingPlayer = false;
}
Expand Down

0 comments on commit 19bd59d

Please sign in to comment.