Skip to content

Commit

Permalink
Merge 'origin/1.7-TiM' into 1.12.1-TiM
Browse files Browse the repository at this point in the history
  • Loading branch information
EternalBlueFlame committed Aug 8, 2023
1 parent 848a6b5 commit ccfcbbb
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 422 deletions.
8 changes: 7 additions & 1 deletion src/main/java/ebf/tim/blocks/TileSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ public int checkBlockPower(int[] ... offset){
public int checkBlockPower(int[] offset, int depth){
int signalStrength=0;
for(int o =-1;o<depth-1;o++) {
signalStrength = getWorld().getStrongPower(pos.add(offset[0], offset[1], offset[2]));
signalStrength = worldObj.getBlockPowerInput(xCoord + offset[0], yCoord + offset[1]+o, zCoord + offset[2]);
if(signalStrength==0){
//1.12 use getMaxCurrentStrength
signalStrength = CommonUtil.getBlockAt(getWorld(),xCoord + offset[0], yCoord + offset[1]+o, zCoord + offset[2])
.isProvidingStrongPower(getWorld(),xCoord + offset[0], yCoord + offset[1]+o, zCoord + offset[2],0);
//the 0 as the last arg is something with direction i think.
}
if(signalStrength!=0) {
return signalStrength;
}
Expand Down
223 changes: 123 additions & 100 deletions src/main/java/ebf/tim/entities/EntityBogie.java

Large diffs are not rendered by default.

88 changes: 32 additions & 56 deletions src/main/java/ebf/tim/entities/EntityTrainCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import ebf.tim.registry.NBTKeys;
import ebf.tim.utility.CommonProxy;
import ebf.tim.utility.CommonUtil;
import ebf.tim.utility.DebugUtil;
import ebf.tim.utility.FuelHandler;
import fexcraft.tmt.slim.Vec3d;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -99,9 +99,6 @@ public void initInventorySlots(){
}


@Override
public boolean hasDrag(){return getAccelerator()==0;}

//gets the throttle position as a percentage with 1 as max and -1 as max reverse
public float getAcceleratorPercentage(){
switch (Math.abs(getAccelerator())){
Expand All @@ -121,7 +118,7 @@ public float getAcceleratorPercentage(){
*/
public void calculateAcceleration(){
//core accel speed from TC4
float accel=0.02f* getAcceleratorPercentage();
float accel=0.0025f* getAcceleratorPercentage();
//buff to match engine type
if(getTypes().contains(STEAM)){
accel*=0.35f;
Expand All @@ -131,26 +128,14 @@ public void calculateAcceleration(){
accel*=0.7f;
}
//scale based on power and velocity
//TODO: velocity breaks this hard. dont do that. BS a similar result.
cachedVectors[2].xCoord=accel* (100f * (float)Math.pow(8f,((2.35f * -(0.3557/getPower()))-2.35f)));

//add back in the speed from last tick, if speed was nulled from going into neutral, get it from the velocity.
if(cachedVectors[2].yCoord!=0) {
cachedVectors[2].xCoord += cachedVectors[2].yCoord;
} else {
cachedVectors[2].xCoord += getVelocity()*0.99;
}
cachedVectors[2].xCoord=accel* (10000f * (float)Math.pow(8f,((2.35f * -(0.3557/getPower()))-2.35f)));

//if speed is greater than top speed from km/h to m/s divided by 20 to get per tick
if (cachedVectors[2].xCoord < -unRatio(transportTopSpeed())) {
cachedVectors[2].xCoord = -unRatio(transportTopSpeed());
} else if (cachedVectors[2].xCoord > unRatio(transportTopSpeedReverse())) {
cachedVectors[2].xCoord = unRatio(transportTopSpeedReverse());
if (Math.abs(frontBogie.velocity[0])+Math.abs(frontBogie.velocity[1]) >
unRatio(accelerator>0?transportTopSpeed():transportTopSpeedReverse())) {
cachedVectors[2].xCoord=0;
}

//set the last tick speed to this speed.
cachedVectors[2].yCoord=cachedVectors[2].xCoord;

//handle ice slipping
if(!getBoolean(boolValues.BRAKE)) {
float slip = !getBoolean(boolValues.DERAILED)?-1.0f:
Expand Down Expand Up @@ -191,40 +176,27 @@ public int getAccelerator(){
*/
@Override
public void onUpdate() {
if(frontBogie != null && backBogie != null) {

if (!world.isRemote) {
//twice a second, re-calculate the speed.
if (accelerator!=0 && getBoolean(boolValues.RUNNING)) {
if(Math.abs(accelerator)!=8 && ticksExisted % 10 == 0) {
calculateAcceleration();
}
} else {
accelerator = 0;
this.dataManager.set(ACCELERATOR, accelerator);
if(!worldObj.isRemote && backBogie != null && frontBogie != null) {
cachedVectors[2].xCoord = 0;
//twice a second, re-calculate the speed.
if (getAccelerator()!=0 && getBoolean(boolValues.RUNNING)) {
if(Math.abs(getAccelerator())!=8 && ticksExisted % 10 == 0) {
calculateAcceleration();
}

if(accelerator==0 && getBoolean(boolValues.BRAKE) && getVelocity()==0){
frontBogie.setVelocity(0,0,0);
backBogie.setVelocity(0,0,0);
cachedVectors[2].xCoord = 0;
} else {
//add drag to the accelerator
if(accelerator==0){
cachedVectors[2].yCoord*=0.99f;
} else {
Vec3d velocity = CommonUtil.rotateDistance(cachedVectors[2].xCoord, 0, rotationYaw);
moveBogies(velocity.xCoord,velocity.zCoord);
}
}

} else {
accelerator = 0;
this.dataWatcher.updateObject(18, getAccelerator());
}

updatePosition();
if(getAccelerator()==0 && getBoolean(boolValues.BRAKE) && getVelocity()==0){
backBogie.setVelocity(0,0,0);
frontBogie.setVelocity(0,0,0);
} else if(getAccelerator()!=0){
appendMovement(cachedVectors[2].xCoord);
}
}

super.onUpdate();
updatePosition();

if(hornDelay >0) {
hornDelay--;
Expand Down Expand Up @@ -299,7 +271,7 @@ public boolean interact(int player, boolean isFront, boolean isBack, int key) {
switch (key){
case 8:{ //toggle ignition
setBoolean(boolValues.RUNNING, !getBoolean(boolValues.RUNNING));
updateConsist();
updateLinks();
return true;
}case 9:{ //plays a sound on all clients within hearing distance
if(hornDelay ==0){
Expand All @@ -317,8 +289,8 @@ public boolean interact(int player, boolean isFront, boolean isBack, int key) {
} else {
accelerator--;
}
updateConsist();
this.dataManager.set(ACCELERATOR, accelerator);
updateLinks();
this.dataWatcher.updateObject(18, accelerator);
}
return true;
}case 3:{ //increase speed
Expand All @@ -332,8 +304,8 @@ public boolean interact(int player, boolean isFront, boolean isBack, int key) {
} else {
accelerator++;
}
updateConsist();
this.dataManager.set(ACCELERATOR, accelerator);
updateLinks();
this.dataWatcher.updateObject(18, accelerator);
}
return true;
} case 16:{//reset speed
Expand All @@ -343,33 +315,37 @@ public boolean interact(int player, boolean isFront, boolean isBack, int key) {
return true;
}
accelerator = 0;
updateConsist();
this.dataManager.set(ACCELERATOR, accelerator);
updateLinks();
this.dataWatcher.updateObject(18, accelerator);
}
return true;
} case 11:{//TC control forward
if(getBoolean(boolValues.RUNNING)) {
accelerator = 7;
this.dataManager.set(ACCELERATOR, accelerator);
}
updateLinks();
return true;
}case 12:{//TC control reverse
if(getBoolean(boolValues.RUNNING)) {
accelerator = -7;
this.dataManager.set(ACCELERATOR, accelerator);
}
updateLinks();
return true;
}case 4: {//TC control, keep speed
if(getBoolean(boolValues.RUNNING)) {
accelerator = (int)Math.copySign(8,accelerator);
this.dataManager.set(ACCELERATOR, accelerator);
}
updateLinks();
return true;
}case 14: {//TC control, keep speed
if(getBoolean(boolValues.RUNNING)) {
accelerator = 0;
this.dataManager.set(ACCELERATOR, accelerator);
}
updateLinks();
return true;
}
}
Expand Down
Loading

0 comments on commit ccfcbbb

Please sign in to comment.