Skip to content

Commit

Permalink
allow small overshoot of power use
Browse files Browse the repository at this point in the history
Signed-off-by: Glease <[email protected]>
  • Loading branch information
Glease committed Sep 16, 2023
1 parent 0a92304 commit c790ed0
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public String validatePacketTravelEvent(EntityPlayerMP toTp, int x, int y, int z
double dist = getDistanceSquared(toTp, target);
// allow 15% overshoot to account for rounding
if (dist * 100 > source.getMaxDistanceTravelledSq() * 115) return "dist check fail";
if (getRequiredPower(toTp, source, target) > powerUse) return "power use to little";
// allow 4 blocks of c/s player pos desync
if (getPower(toTp, source, target, -4F) > powerUse) return "power use too little";
ItemStack equippedItem = toTp.getCurrentEquippedItem();
switch (source) {
case TELEPAD:
Expand Down Expand Up @@ -674,7 +675,7 @@ public int getRequiredPower(EntityPlayer player, TravelSource source, BlockCoord
}
int requiredPower;
ItemStack staff = player.getCurrentEquippedItem();
requiredPower = (int) (getDistance(player, coord) * source.getPowerCostPerBlockTraveledRF());
requiredPower = getPower(player, source, coord, 0F);
int canUsePower = getEnergyInTravelItem(staff);
if (requiredPower > canUsePower) {
// make sure chat is sent only once per trial
Expand All @@ -687,6 +688,10 @@ public int getRequiredPower(EntityPlayer player, TravelSource source, BlockCoord
return requiredPower;
}

private int getPower(EntityPlayer player, TravelSource source, BlockCoord coord, float distanceWavier) {
return (int) ((getDistance(player, coord) + distanceWavier) * source.getPowerCostPerBlockTraveledRF());
}

private boolean isInRangeTarget(EntityPlayer player, BlockCoord bc, float maxSq) {
return getDistanceSquared(player, bc) <= maxSq;
}
Expand Down

0 comments on commit c790ed0

Please sign in to comment.