Added entity cooldown to lift

This fix the use of lifts with pressure plates while still allowing
group movement
This commit is contained in:
LemADEC 2017-05-17 10:08:59 +02:00
parent cf28c11070
commit 596634ce3b
2 changed files with 44 additions and 29 deletions
src/main/java/cr0s/warpdrive

View file

@ -23,18 +23,23 @@ import cpw.mods.fml.common.Optional;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityLift extends TileEntityAbstractEnergy {
private static final int MODE_REDSTONE = -1;
private static final int MODE_INACTIVE = 0;
private static final int MODE_UP = 1;
private static final int MODE_DOWN = 2;
private int firstUncoveredY;
final double LIFT_GRAB_RADIUS = 0.4;
// persistent properties
private int mode = MODE_INACTIVE;
private boolean isEnabled = false;
private boolean computerEnabled = true;
private int computerMode = MODE_REDSTONE;
private int tickCount = 0;
// computed properties
private int updateTicks = 0;
private boolean isEnabled = false;
private int firstUncoveredY;
public TileEntityLift() {
super();
@ -55,9 +60,9 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
return;
}
tickCount++;
if (tickCount >= WarpDriveConfig.LIFT_UPDATE_INTERVAL_TICKS) {
tickCount = 0;
updateTicks--;
if (updateTicks < 0) {
updateTicks = WarpDriveConfig.LIFT_UPDATE_INTERVAL_TICKS;
// Switching mode
if ( computerMode == MODE_DOWN
@ -106,7 +111,9 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
0f, 1f, 40, 0, 100);
}
liftEntity();
if (liftEntity()) {
updateTicks = WarpDriveConfig.LIFT_ENTITY_COOLDOWN_TICKS;
}
}
}
}
@ -118,54 +125,59 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
|| block.getCollisionBoundingBoxFromPool(worldObj, xCoord, yPosition, zCoord) == null;
}
private void liftEntity() {
final double CUBE_RADIUS = 0.4;
double xMax, zMax;
double xMin, zMin;
xMin = xCoord + 0.5 - CUBE_RADIUS;
xMax = xCoord + 0.5 + CUBE_RADIUS;
zMin = zCoord + 0.5 - CUBE_RADIUS;
zMax = zCoord + 0.5 + CUBE_RADIUS;
private boolean liftEntity() {
final double xMin = xCoord + 0.5 - LIFT_GRAB_RADIUS;
final double xMax = xCoord + 0.5 + LIFT_GRAB_RADIUS;
final double zMin = zCoord + 0.5 - LIFT_GRAB_RADIUS;
final double zMax = zCoord + 0.5 + LIFT_GRAB_RADIUS;
boolean isTransferDone = false;
// Lift up
if (mode == MODE_UP) {
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xMin, firstUncoveredY, zMin, xMax, yCoord, zMax);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
final AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
xMin, firstUncoveredY, zMin,
xMax, yCoord, zMax);
final List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
if (list != null) {
for (Object o : list) {
if ( o != null
&& o instanceof EntityLivingBase
for (Object object : list) {
if ( object != null
&& object instanceof EntityLivingBase
&& energy_consume(WarpDriveConfig.LIFT_ENERGY_PER_ENTITY, true)) {
((EntityLivingBase) o).setPositionAndUpdate(xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D);
((EntityLivingBase) object).setPositionAndUpdate(xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D);
PacketHandler.sendBeamPacket(worldObj,
new Vector3(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D),
new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D),
1F, 1F, 0F, 40, 0, 100);
worldObj.playSoundEffect(xCoord + 0.5D, yCoord, zCoord + 0.5D, "warpdrive:hilaser", 4F, 1F);
energy_consume(WarpDriveConfig.LIFT_ENERGY_PER_ENTITY, false);
isTransferDone = true;
}
}
}
} else if (mode == MODE_DOWN) {
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xMin,
Math.min(firstUncoveredY + 4.0D, yCoord), zMin, xMax, yCoord + 2.0D, zMax);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
final AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
xMin, Math.min(firstUncoveredY + 4.0D, yCoord), zMin,
xMax, yCoord + 2.0D, zMax);
final List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
if (list != null) {
for (Object o : list) {
if ( o != null
&& o instanceof EntityLivingBase
for (Object object : list) {
if ( object != null
&& object instanceof EntityLivingBase
&& energy_consume(WarpDriveConfig.LIFT_ENERGY_PER_ENTITY, true)) {
((EntityLivingBase) o).setPositionAndUpdate(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D);
((EntityLivingBase) object).setPositionAndUpdate(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D);
PacketHandler.sendBeamPacket(worldObj,
new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D),
new Vector3(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D), 1F, 1F, 0F, 40, 0, 100);
worldObj.playSoundEffect(xCoord + 0.5D, yCoord, zCoord + 0.5D, "warpdrive:hilaser", 4F, 1F);
energy_consume(WarpDriveConfig.LIFT_ENERGY_PER_ENTITY, false);
isTransferDone = true;
}
}
}
}
return isTransferDone;
}
@Override

View file

@ -329,6 +329,7 @@ public class WarpDriveConfig {
public static int LIFT_MAX_ENERGY_STORED = 900;
public static int LIFT_ENERGY_PER_ENTITY = 150;
public static int LIFT_UPDATE_INTERVAL_TICKS = 10;
public static int LIFT_ENTITY_COOLDOWN_TICKS = 40;
// Chunk loader
public static int CL_MAX_ENERGY = 1000000;
@ -818,6 +819,8 @@ public class WarpDriveConfig {
config.get("lift", "energy_per_entity", LIFT_ENERGY_PER_ENTITY, "Energy consumed per entity moved").getInt());
LIFT_UPDATE_INTERVAL_TICKS = Commons.clamp(1, 60,
config.get("lift", "update_interval_ticks", LIFT_UPDATE_INTERVAL_TICKS, "Update speed of the check for entities").getInt());
LIFT_ENTITY_COOLDOWN_TICKS = Commons.clamp(1, 6000,
config.get("lift", "entity_cooldown_ticks", LIFT_ENTITY_COOLDOWN_TICKS, "Cooldown after moving an entity").getInt());
// Dictionary
Dictionary.loadConfig(config);