Skip to content

Commit

Permalink
Patch up ascending with minecarts.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Jun 10, 2016
1 parent f1ffb23 commit 720386a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -19,8 +19,6 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

import fr.neatmonster.nocheatplus.utilities.BlockProperties;

/**
* Include vehicle move data for a move.
*
Expand Down Expand Up @@ -57,10 +55,10 @@ public void setExtraVehicleProperties(final Entity vehicle) {
}

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;
}
}
Expand Down
Expand Up @@ -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;

Expand All @@ -73,7 +74,7 @@ public class CheckDetails {
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;
Expand Down Expand Up @@ -189,6 +190,12 @@ else if (checkDetails.canClimb && thisMove.from.onClimbable) {
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) {
Expand Down Expand Up @@ -305,6 +312,7 @@ protected void prepareCheckDetails(final Entity vehicle, final VehicleMoveInfo m
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;
Expand Down
Expand Up @@ -1748,6 +1748,18 @@ public static final boolean isRails(final int id) {
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.
Expand Down
Expand Up @@ -574,6 +574,18 @@ public boolean isOnIce() {
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.
*
Expand Down

0 comments on commit 720386a

Please sign in to comment.