Fix for flags + adjust debug output to show flags and exact coordinates

on higher debugLevel.
This commit is contained in:
asofold 2013-03-05 18:26:10 +01:00
parent 354511b88f
commit de44ea43a4
3 changed files with 60 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
@ -17,6 +18,36 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
*/
public class DebugUtil {
/**
* 3 decimal digits after comma (StringUtil.fdec3).
* @param from
* @param to
* @param loc Reference location for from, usually Player.getLocation().
* @param builder
* @return
*/
public static void addFormattedMove(final PlayerLocation from, final PlayerLocation to, final Location loc, final StringBuilder builder){
builder.append(" " + from.getWorld().getName() + " " + StringUtil.fdec3.format(from.getX()) + (from.getX() == loc.getX() ? "" : ("(" + StringUtil.fdec3.format(loc.getX()) + ")")));
builder.append(", " + StringUtil.fdec3.format(from.getY()) + (from.getY() == loc.getY() ? "" : ("(" + StringUtil.fdec3.format(loc.getY()) + ")")));
builder.append(", " + StringUtil.fdec3.format(from.getZ()) + (from.getZ() == loc.getZ() ? "" : ("(" + StringUtil.fdec3.format(loc.getZ()) + ")")));
builder.append(" -> " + StringUtil.fdec3.format(to.getX()) + ", " + StringUtil.fdec3.format(to.getY()) + ", " + StringUtil.fdec3.format(to.getZ()));
}
/**
* Add exact coordinates, multiple lines.
* @param from
* @param to
* @param loc Reference location for from, usually Player.getLocation().
* @param builder
*/
public static void addMove(final PlayerLocation from, final PlayerLocation to, final Location loc, final StringBuilder builder){
builder.append(" " + from.getWorld().getName() + "moves:\nfrom: " + from.getX() + (from.getX() == loc.getX() ? "" : ("(" + loc.getX() + ")")));
builder.append(", " + from.getY() + (from.getY() == loc.getY() ? "" : ("(" + loc.getY() + ")")));
builder.append(", " + from.getZ() + (from.getZ() == loc.getZ() ? "" : ("(" + loc.getZ() + ")")));
builder.append("\nto: " + to.getX() + ", " + to.getY() + ", " + to.getZ());
}
/**
*
* @param player
@ -27,11 +58,14 @@ public class DebugUtil {
public static void outputMoveDebug(final Player player, final PlayerLocation from, final PlayerLocation to, final MCAccess mcAccess) {
final StringBuilder builder = new StringBuilder(250);
final Location loc = player.getLocation();
// TODO: Differentiate debug levels (needs setting up some policy + document in BuildParamteres)?
builder.append(player.getName());
builder.append(" " + from.getWorld().getName() + " " + StringUtil.fdec3.format(from.getX()) + (from.getX() == loc.getX() ? "" : ("(" + StringUtil.fdec3.format(loc.getX()) + ")")));
builder.append(", " + StringUtil.fdec3.format(from.getY()) + (from.getY() == loc.getY() ? "" : ("(" + StringUtil.fdec3.format(loc.getY()) + ")")));
builder.append(", " + StringUtil.fdec3.format(from.getZ()) + (from.getZ() == loc.getZ() ? "" : ("(" + StringUtil.fdec3.format(loc.getZ()) + ")")));
builder.append(" -> " + StringUtil.fdec3.format(to.getX()) + ", " + StringUtil.fdec3.format(to.getY()) + ", " + StringUtil.fdec3.format(to.getZ()));
if (BuildParameters.debugLevel > 0) {
addMove(from, to, loc, builder);
}
else {
addFormattedMove(from, to, loc, builder);
}
final double jump = mcAccess.getJumpAmplifier(player);
final double speed = mcAccess.getFasterMovementAmplifier(player);
if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){
@ -39,9 +73,14 @@ public class DebugUtil {
}
if (BuildParameters.debugLevel > 0){
// Note: the block flags are for normal on-ground checking, not with yOnGrond set to 0.5.
from.collectBlockFlags(from.getyOnGround());
if (from.getBlockFlags() != 0) builder.append("\nfrom flags: " + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+"));
if (from.getTypeId() != 0) addBlockInfo(builder, from, "\nfrom");
if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom");
if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)");
to.collectBlockFlags(to.getyOnGround());
if (to.getBlockFlags() != 0) builder.append("\nto flags: " + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+"));
if (to.getTypeId() != 0) addBlockInfo(builder, to, "\nto");
if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto");
if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");

View File

@ -670,8 +670,9 @@ public class BlockProperties {
* @param flags
* @return
*/
public static Collection<String> getFlagNames(final long flags) {
public static Collection<String> getFlagNames(final Long flags) {
final ArrayList<String> tags = new ArrayList<String>(flagNameMap.size());
if (flags == null) return tags;
addFlagNames(flags, tags);
return tags;
}
@ -1615,7 +1616,12 @@ public class BlockProperties {
continue;
}
// TODO: Check passable workaround without checking ignore flag.
// // Check if the block can be passed through with the bounding box (disregard the ignore flag).
// if (isPassableWorkaround(access, x, y, z, minX - x, minY - y, minZ - z, id, maxX - minX, maxY - minY, maxZ - minZ, 1.0)){
// // Spider !
// System.out.println("*** Continue: passable workaround");
// continue;
// }
// TODO: Shortcut: if bounds[4] > fx return true (careful with fences) ?
@ -1626,7 +1632,7 @@ public class BlockProperties {
}
final int aboveId = access.getTypeId(x, y + 1, z);
final long aboveFlags = blockFlags[aboveId];
if ((flags & aboveFlags & F_IGN_PASSABLE) != 0){
if ((aboveFlags & F_IGN_PASSABLE) != 0){ // flags &
// Ignore these (Note for above block check before ground property).
// TODO: Should this always apply ?
return true;

View File

@ -770,5 +770,13 @@ public class PlayerLocation {
// if (Math.abs(box.a) > 3.2E7D || Math.abs(box.b) > 3.2E7D || Math.abs(box.c) > 3.2E7D || Math.abs(box.d) > 3.2E7D || Math.abs(box.e) > 3.2E7D || Math.abs(box.f) > 3.2E7D) return true;
else return false;
}
/**
* Get the collected block-flags. This will return null if collectBlockFlags has not been called.
* @return
*/
public Long getBlockFlags() {
return blockFlags;
}
}