Patch up ascending with minecarts.

This commit is contained in:
asofold 2016-06-10 15:12:00 +02:00
parent f1ffb23686
commit 720386a0e2
5 changed files with 37 additions and 5 deletions

View File

@ -37,6 +37,8 @@ public class MagicVehicle {
// TODO: Likely needs adjustments, many thinkable edge cases, also pistons (!).
// TODO: Does trigger on vehicle enter somehow some time.
public static final double maxAscend = 0.27;
public static final double maxRailsVertical = 0.5;
public static final double boatGravityMin = Magic.GRAVITY_MIN / 2.0;
public static final double boatGravityMax = (Magic.GRAVITY_MAX + Magic.GRAVITY_SPAN) / 2.0;

View File

@ -19,8 +19,6 @@ import java.util.UUID;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
/**
* Include vehicle move data for a move.
*
@ -57,10 +55,10 @@ public class VehicleMoveData extends PlayerMoveData {
}
public void setExtraMinecartProperties(final VehicleMoveInfo moveInfo) {
if (BlockProperties.isRails(moveInfo.from.getTypeId())) {
if (moveInfo.from.isOnRails()) {
fromOnRails = true;
}
if (BlockProperties.isRails(moveInfo.to.getTypeId())) {
if (moveInfo.to.isOnRails()) {
toOnRails = true;
}
}

View File

@ -55,6 +55,7 @@ public class VehicleEnvelope extends Check {
public class CheckDetails {
public boolean canClimb;
public boolean canRails;
public boolean canJump, canStepUpBlock; // TODO: Model as heights?
public double maxAscend;
@ -73,7 +74,7 @@ public class VehicleEnvelope extends Check {
public boolean inAir;
public void reset() {
canClimb = canJump = canStepUpBlock = false;
canClimb = canRails = canJump = canStepUpBlock = false;
maxAscend = 0.0;
checkAscendMuch = checkDescendMuch = true;
fromIsSafeMedium = toIsSafeMedium = inAir = false;
@ -189,6 +190,12 @@ public class VehicleEnvelope extends Check {
tags.add("climbspeed");
}
}
else if (checkDetails.canRails && thisMove.fromOnRails) {
// TODO: Might invert to trigger violation if exceeds distance (always disable a/d_much).
if (Math.abs(thisMove.yDistance) < MagicVehicle.maxRailsVertical) {
checkDetails.checkAscendMuch = checkDetails.checkDescendMuch = false;
}
}
else if (thisMove.from.inWater && thisMove.to.inWater) {
// Default in-medium move.
if (data.debug) {
@ -305,6 +312,7 @@ public class VehicleEnvelope extends Check {
else if (vehicle instanceof Minecart) {
checkDetails.simplifiedType = EntityType.MINECART;
// Bind to rails.
checkDetails.canRails = true;
thisMove.setExtraMinecartProperties(moveInfo); // Cheating.
if (thisMove.fromOnRails) {
checkDetails.fromIsSafeMedium = true;

View File

@ -1748,6 +1748,18 @@ public class BlockProperties {
return (blockFlags[id] & F_RAILS) != 0;
}
/**
* Test if the id is rails and if data means ascending.
*
* @param id
* @param data
* @return
*/
public static final boolean isAscendingRails(final int id, final int data) {
// TODO: Configurable magic.
return isRails(id) && (data & 7) > 1;
}
/**
* Test if a position can be passed through (collidesBlock + passable test, no fences yet).<br>
* NOTE: This is experimental.

View File

@ -574,6 +574,18 @@ public class RichBoundsLocation implements IGetBukkitLocation, IGetBlockPosition
return onIce;
}
/**
* Test if the location is on rails (assuming minecarts with some magic
* bounds/behavior).
*
* @return
*/
public boolean isOnRails() {
return BlockProperties.isRails(getTypeId())
// TODO: Checking the block below might be over-doing it.
|| y - blockY < 0.3625 && BlockProperties.isAscendingRails(getTypeIdBelow(), getData(blockX, blockY - 1, blockZ));
}
/**
* Checks if the thing is on ground, including entities such as Minecart, Boat.
*