Integrating transporter (wip)

This commit is contained in:
Unknown 2018-03-06 02:59:51 +01:00
parent 6e456f5efc
commit 4960c996bb
3 changed files with 27 additions and 31 deletions

View file

@ -47,7 +47,6 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
// persistent properties
private int beamFrequency = -1;
private boolean isConnected = false;
private boolean isEnabled = true;
private boolean isLockRequested = false;
private boolean isEnergizeRequested = false;
@ -59,6 +58,7 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
private EnumTransporterState transporterState = EnumTransporterState.DISABLED;
// computed properties
private boolean isConnected = false;
private int energyCostForTransfer = 0;
private double lockStrengthOptimal = -1.0D;
private double lockStrengthSpeed = 0.0D;
@ -108,50 +108,50 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
return;
}
// frequency is not set
final boolean new_isConnected = beamFrequency > 0 && beamFrequency <= IBeamFrequency.BEAM_FREQUENCY_MAX;
if (isConnected != new_isConnected) {
isConnected = new_isConnected;
markDirty();
// frequency status
isConnected = beamFrequency > 0 && beamFrequency <= IBeamFrequency.BEAM_FREQUENCY_MAX;
// always cooldown
if (tickCooldown > 0) {
tickCooldown--;
} else {
tickCooldown = 0;
}
// global override
boolean isActive = isEnabled && isConnected;
// consume power and apply general lock strength increase and decay
boolean isPowered;
if (!isEnabled) {
transporterState = EnumTransporterState.DISABLED;
isPowered = false;
// (lock strength is cleared in state machine)
} else {
// energy consumption
final int energyRequired = getEnergyRequired(transporterState);
if (energyRequired > 0) {
final boolean isPowered = energy_consume(energyRequired, false);
isPowered = energy_consume(energyRequired, false);
if (!isPowered) {
transporterState = EnumTransporterState.IDLE;
isActive = false;
}
}
// apply cooldown when enabled
if (tickCooldown > 0) {
tickCooldown--;
} else {
tickCooldown = 0;
isPowered = true;
}
// lock strength always decays
lockStrengthActual *= WarpDriveConfig.TRANSPORTER_LOCKING_STRENGTH_FACTOR_PER_TICK;
lockStrengthActual = Math.max(0.0D, lockStrengthActual * WarpDriveConfig.TRANSPORTER_LOCKING_STRENGTH_FACTOR_PER_TICK);
// lock strength is capped at optimal, increasing when powered
// a slight overshoot is added to force convergence
final double overshoot = 0.01D;
if (isActive) {
if ( isPowered
&& ( transporterState == EnumTransporterState.ACQUIRING
|| transporterState == EnumTransporterState.ENERGIZING ) ) {
final double overshoot = 0.01D;
lockStrengthActual = Math.min(lockStrengthOptimal,
lockStrengthActual + lockStrengthSpeed * (lockStrengthOptimal - lockStrengthActual + overshoot));
} else {
lockStrengthActual = Math.max(0.0D, lockStrengthActual);
}
}
// state feedback
final boolean isActive = isEnabled && isConnected && isPowered;
updateMetadata(isActive ? 1 : 0);
if (isActive && isLockRequested && isJammed) {
PacketHandler.sendSpawnParticlePacket(worldObj, "jammed", (byte) 5, new Vector3(this).translate(0.5F),
@ -161,6 +161,7 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
32);
}
// execute state transitions
switch (transporterState) {
case DISABLED:
isLockRequested = false;
@ -655,7 +656,6 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
super.writeToNBT(tagCompound);
tagCompound.setInteger(IBeamFrequency.BEAM_FREQUENCY_TAG, beamFrequency);
tagCompound.setBoolean("isConnected", isConnected);
tagCompound.setBoolean("isEnabled", isEnabled);
tagCompound.setBoolean("isLockRequested", isLockRequested);
tagCompound.setBoolean("isEnergizeRequested", isEnergizeRequested);
@ -674,7 +674,6 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
super.readFromNBT(tagCompound);
beamFrequency = tagCompound.getInteger(IBeamFrequency.BEAM_FREQUENCY_TAG);
isConnected = tagCompound.getBoolean("isConnected");
isEnabled = tagCompound.getBoolean("isEnabled");
isLockRequested = tagCompound.getBoolean("isLockRequested");
isEnergizeRequested = tagCompound.getBoolean("isEnergizeRequested");

View file

@ -202,11 +202,11 @@ public class MessageTransporterEffect implements IMessage, IMessageHandler<Messa
// add particle
final EntityFX effect = new EntityFXDot(world, v3Position,
v3Motion, v3Acceleration, 0.98D,
redBase + redFactor * world.rand.nextFloat(),
greenBase+ greenFactor * world.rand.nextFloat(),
blueBase + blueFactor * world.rand.nextFloat(),
1.0F,
30);
effect.setRBGColorF(redBase + redFactor * world.rand.nextFloat(),
greenBase + greenFactor * world.rand.nextFloat(),
blueBase + blueFactor * world.rand.nextFloat() );
effect.setAlphaF(1.0F);
FMLClientHandler.instance().getClient().effectRenderer.addEffect(effect);
}
}

View file

@ -19,11 +19,8 @@ public class EntityFXDot extends EntityFX {
public EntityFXDot(final World world, final Vector3 v3Position,
final Vector3 v3Motion, final Vector3 v3Acceleration, final double friction,
final float red, final float green, final float blue, final float alpha,
final int age) {
super(world, v3Position.x, v3Position.y, v3Position.z, 0.0D, 0.0D, 0.0D);
this.setRBGColorF(red, green, blue);
this.setAlphaF(alpha);
this.setSize(0.02F, 0.02F);
this.noClip = true;
this.motionX = v3Motion.x;
@ -34,7 +31,7 @@ public class EntityFXDot extends EntityFX {
this.particleMaxAge = age;
// defaults to vanilla water drip
this.setParticleTextureIndex(113);
setParticleTextureIndex(113);
// refresh bounding box
setPosition(v3Position.x, v3Position.y, v3Position.z);