Skip to content

Commit

Permalink
Player Scaling Rework
Browse files Browse the repository at this point in the history
- Reworked the player scaling to be inline with FVTM/FD (Thanks Ferdinand from Fexcraft for the help)
- to adjust the player scale, simply override getPlayerScale in your entity. Be mindful that you may have to edit the position. Recommended range: 0.5-1; default is 1, TiM was 0.65.
  • Loading branch information
broscolotos committed Jun 22, 2024
1 parent 2ced200 commit 27aa128
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 52 deletions.
32 changes: 0 additions & 32 deletions src/main/java/ebf/tim/utility/EventManager.java

This file was deleted.

32 changes: 30 additions & 2 deletions src/main/java/train/client/core/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.VillagerRegistry;
import ebf.tim.utility.EventManager;
import javazoom.jl.decoder.JavaLayerUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundCategory;
Expand Down Expand Up @@ -59,7 +58,36 @@

public class ClientProxy extends CommonProxy {

public static EventManager eventManager = new EventManager();
public static final net.minecraft.client.renderer.entity.RenderPlayer playerRender = new net.minecraft.client.renderer.entity.RenderPlayer(){
EntityRollingStock stock;
@Override
public void doRender(net.minecraft.client.entity.AbstractClientPlayer player, double x, double y, double z, float f0, float f1){
if(player.ridingEntity instanceof EntityRollingStock){
stock = (EntityRollingStock) player.ridingEntity;
GL11.glPushMatrix();
float scale = stock.getPlayerScale();
scale = player.height * scale / player.height;
GL11.glTranslated(x, (y+.35), z);
GL11.glScalef(scale, scale, scale);
GL11.glTranslated(-x, -(y+.35), -z);
if (player != Minecraft.getMinecraft().thePlayer && stock.getPlayerScale() != 1) {
GL11.glTranslated(0, 1-(stock.getPlayerScale()-0.2), 0); //rough approx. but gets the job done for everything in range 0.5-1
} else {
GL11.glTranslated(0, (1-stock.getPlayerScale()) * -1,0); //rough approx. but gets the job done for everything in range 0.5-1
}
super.doRender(player, x, y, z, f0, f1);
GL11.glPopMatrix();
return;

}
super.doRender(player, x, y, z, f0, f1);
}
};

@Override
public void registerPlayerScaler(){
RenderingRegistry.registerEntityRenderingHandler(EntityPlayer.class, playerRender);
}

public static boolean hdTransportItems=false;
public static boolean preRenderModels=false;
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/train/common/Traincraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.minecraftforge.common.util.EnumHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import train.client.core.ClientProxy;
import train.common.api.AbstractTrains;
import train.common.api.LiquidManager;
import train.common.blocks.TCBlocks;
Expand Down Expand Up @@ -207,12 +206,7 @@ public void init(FMLInitializationEvent event) {


proxy.registerBookHandler();

if (event.getSide().isClient()) {
//register the event handler
FMLCommonHandler.instance().bus().register(ClientProxy.eventManager);
MinecraftForge.EVENT_BUS.register(ClientProxy.eventManager);
}
proxy.registerPlayerScaler();

/* Networking and Packet initialisation, apparently this needs to be in init to prevent conflicts */
PacketHandler.init();
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/train/common/api/EntityRollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public class EntityRollingStock extends AbstractTrains implements ILinkableCart
public boolean isClientInReverse = false;
public boolean serverInReverseSignPositive = false;
public float serverRealPitch;
public float playerScale = 1;
private double rollingPitch;
public float oldClientYaw = 0;//used in rendering class
@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -503,14 +502,9 @@ public void pressKey(int i) {


public float getPlayerScale() {
return playerScale;
return 1;
}

public void setPlayerScale(float t) {
this.playerScale = t;
}


/**
* gets packet from server and distribute for GUI handles motion
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/train/common/core/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public boolean isClient(){
public void setKeyBinding(String name, int value) {
}

public void registerPlayerScaler(){}

public void registerRenderInformation() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,34 @@ public EntityLocoSteamC41(World world, double d, double d1, double d2) {
prevPosZ = d2;
}

@Override
public float getPlayerScale() {
return 0.65f;
}

@Override
public void updateRiderPosition() {
if(riddenByEntity==null){return;}
double pitchRads = this.anglePitchClient * Math.PI / 180.0D;
double distance = -0.2;
double yOffset = 0.5;
double distance = -0.1875; //how far forward/backwards on the entity you ride; forward > 0; backwards < 0;
double distanceLR = -0.375; //how far left/right on the entity you ride; left > 0; right < 0;
double yOffset = 0.46;
float rotationCos1 = (float) Math.cos(Math.toRadians(this.renderYaw + 90));
float rotationSin1 = (float) Math.sin(Math.toRadians((this.renderYaw + 90)));
float rotationCosLR1 = (float) Math.cos(Math.toRadians(this.renderYaw));
float rotationSinLR1 = (float) Math.sin(Math.toRadians((this.renderYaw)));
if(side.isServer()){
rotationCos1 = (float) Math.cos(Math.toRadians(this.serverRealRotation + 90));
rotationSin1 = (float) Math.sin(Math.toRadians((this.serverRealRotation + 90)));
rotationCosLR1 = (float) Math.cos(Math.toRadians(this.serverRealRotation));
rotationSinLR1 = (float) Math.sin(Math.toRadians((this.serverRealRotation)));
anglePitchClient = serverRealPitch*60;
}
float pitch = (float) (posY + ((Math.tan(pitchRads) * distance) + getMountedYOffset())
+ riddenByEntity.getYOffset() + yOffset);
float pitch1 = (float) (posY + getMountedYOffset() + riddenByEntity.getYOffset() + yOffset);
double bogieX1 = (this.posX + (rotationCos1 * distance));
double bogieZ1 = (this.posZ + (rotationSin1* distance));
double bogieX1 = (this.posX + (rotationCos1 * distance) + (rotationCosLR1 * distanceLR));
double bogieZ1 = (this.posZ + (rotationSin1* distance) + (rotationSinLR1 * distanceLR));
// System.out.println(rotationCos1+" "+rotationSin1);
if(anglePitchClient>20 && rotationCos1 == 1){
bogieX1 -= pitchRads * 2;
Expand All @@ -70,6 +80,7 @@ public void updateRiderPosition() {
}
}


@Override
public void setDead() {
super.setDead();
Expand Down

0 comments on commit 27aa128

Please sign in to comment.