From 15f08f13a9b7d319ecd3838c402d02dc7d2a86fd Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 13 Mar 2013 10:16:56 +0100 Subject: [PATCH] Prepare 1.5 blocks with block flags. Add unused stuff. More like a safety commit. 1. Add compatibility block flags for MC 1.5 blocks. 2. Add commented out / unused stuff (not really for 1.5). --- .../compat/blocks/BlocksMC1_5.java | 79 +++++++++++++++ .../utilities/BlockProperties.java | 97 ++++++++++++++++--- .../nocheatplus/utilities/PlayerLocation.java | 5 +- .../compat/cbdev/BlockCacheCBDev.java | 2 +- .../nocheatplus/checks/moving/Passable.java | 3 + .../checks/moving/SurvivalFly.java | 8 ++ 6 files changed, 180 insertions(+), 14 deletions(-) create mode 100644 NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java new file mode 100644 index 00000000..576671ba --- /dev/null +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlocksMC1_5.java @@ -0,0 +1,79 @@ +package fr.neatmonster.nocheatplus.compat.blocks; + +import org.bukkit.Material; + +import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup; +import fr.neatmonster.nocheatplus.config.WorldConfigProvider; +import fr.neatmonster.nocheatplus.utilities.BlockProperties; + +/** + * This is an attempt to add Minecraft 1.5 blocks information without actual 1.5 dependency. + * @author mc_dev + * + */ +public class BlocksMC1_5 implements BlockPropertiesSetup { + + public BlocksMC1_5(){ + // Test if materials exist. + if (Material.getMaterial(152) == null){ + throw new RuntimeException("Material for 1.5 does not exist."); + } + } + + @Override + public void setupBlockProperties(WorldConfigProvider worldConfigProvider) { + + // TODO: Block flag info ... + // TODO: Tool and breaking time infos... + + // TODO: This is guessing ! + + // 146 Trapped Chest + setFlagsAs(146, Material.CHEST); + BlockProperties.setBlockProps(146, BlockProperties.getBlockProps(Material.CHEST.getId())); + + // 147 Weighted Pressure Plate (Light) + // 148 Weighted Pressure Plate (Heavy) + addFlags(147, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + addFlags(148, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + + // 149 Redstone Comparator (inactive) + // 150 Redstone Comparator (active) + addFlags(149, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + addFlags(150, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + + // 151 Daylight Sensor + addFlags(151, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT); + + // 152 Block of Redstone + // 153 Nether Quartz Ore + // 155 Block of Quartz + + // 154 Hopper + addFlags(144, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT); + + // 158 Dropper + setFlagsAs(158, Material.DISPENSER); + + // 156 Quartz Stairs + setFlagsAs(156, Material.COBBLESTONE_STAIRS); + + // 157 Activator Rail + setFlagsAs(157, Material.DETECTOR_RAIL); + + } + + /** + * Set flags of id same as with material. + * @param id + * @param mat + */ + public static void setFlagsAs(int id, Material mat){ + BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(mat.getId())); + } + + public static void addFlags(int id, long flags){ + BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(id) | flags); + } + +} diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index 40e1ca6b..219fff84 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -23,6 +23,7 @@ import org.bukkit.potion.PotionEffectType; import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup; import fr.neatmonster.nocheatplus.compat.MCAccess; +import fr.neatmonster.nocheatplus.compat.blocks.BlocksMC1_5; import fr.neatmonster.nocheatplus.config.RawConfigFile; import fr.neatmonster.nocheatplus.config.RootConfPaths; import fr.neatmonster.nocheatplus.config.WorldConfigProvider; @@ -347,6 +348,20 @@ public class BlockProperties { LogUtil.logSevere(t); } } + // Extra hand picked setups. + // TODO: Add registry for further BlockPropertiesSetup instances. + try{ + BlockPropertiesSetup bpSetup = new BlocksMC1_5(); + try{ + bpSetup.setupBlockProperties(worldConfigProvider); + LogUtil.logInfo("[NoCheatPlus] Added block-info for Minecraft 1.5 blocks."); + } + catch(Throwable t){ + LogUtil.logSevere("[NoCheatPlus] BlocksMC1_5.setupBlockProperties could not execute properly: " + t.getClass().getSimpleName()); + LogUtil.logSevere(t); + } + } + catch(Throwable t){} } catch(Throwable t){ LogUtil.logSevere(t); @@ -1165,7 +1180,7 @@ public class BlockProperties { } /** - * Test if a position can be passed through (collidesBlock + passable test).
+ * Test if a position can be passed through (collidesBlock + passable test, no fences yet).
* NOTE: This is experimental. * @param world * @param x @@ -1176,30 +1191,88 @@ public class BlockProperties { */ public static final boolean isPassable(final BlockCache access, final double x, final double y, final double z, final int id){ // Simple exclusion check first. - if (isPassable(id)) return true; + if (isPassable(id)){ + return true; + } // Check if the position is inside of a bounding box. final int bx = Location.locToBlock(x); final int by = Location.locToBlock(y); final int bz = Location.locToBlock(z); final double[] bounds = access.getBounds(bx, by, bz); - if (bounds == null) return true; - if (!collidesBlock(access, x, y, z, x, y, z, bx, by, bz, id, bounds, blockFlags[id])){ + if (bounds == null || !collidesBlock(access, x, y, z, x, y, z, bx, by, bz, id, bounds, blockFlags[id])){ return true; } final double fx = x - bx; final double fy = y - by; final double fz = z - bz; -// if (fx < block.minX || fx >= block.maxX || fy < block.minY || fy >= block.maxY || fz < block.minZ || fz >= block.maxZ) return true; -// if (fx < bounds[0] || fx >= bounds[3] || fy < bounds[1] || fy >= bounds[4] || fz < bounds[2] || fz >= bounds[5]){ -// return true; -// } -// else{ - // TODO: Check f_itchy if/once exists. - return isPassableWorkaround(access, bx, by, bz, fx, fy, fz, id, 0, 0, 0, 0); -// } + // TODO: Check f_itchy if/once exists. + // Check workarounds (blocks with bigger collision box but passable on some spots). + if (!isPassableWorkaround(access, bx, by, bz, fx, fy, fz, id, 0, 0, 0, 0)){ + // Not passable. + return false; + } + return true; } + /** + * Checking the block below to account for fences and such. This must be called extra to isPassable(...). + * @param access + * @param x + * @param y + * @param z + * @param id + * @return + */ + public static final boolean isPassableH150(final BlockCache access, final double x, final double y, final double z){ + // Check for fences. + final int by = Location.locToBlock(y) - 1; + final double fy = y - by; + if (fy >= 1.5){ + return true; + } + final int bx = Location.locToBlock(x); + final int bz = Location.locToBlock(z); + final int belowId = access.getTypeId(bx, by, bz); + final long belowFlags = blockFlags[belowId]; + if ((belowFlags & F_HEIGHT150) == 0 || isPassable(belowId)){ + return true; + } + final double[] belowBounds = access.getBounds(bx, by, bz); + if (belowBounds == null){ + return true; + } + if (!collidesBlock(access, x, y, z, x, y, z, bx, by, bz, belowId, belowBounds, belowFlags)){ + return true; + } + final double fx = x - bx; + final double fz = z - bz; + return isPassableWorkaround(access, bx, by, bz, fx, fy, fz, belowId, 0, 0, 0, 0); + } + + /** + * Check if passable, including blocks with height 1.5. + * @param access + * @param x + * @param y + * @param z + * @return + */ + public static final boolean isPassableExact(final BlockCache access, final double x, final double y, final double z, final int id){ + return isPassable(access, x, y, z, id) && isPassableH150(access, x, y, z); + } + + /** + * Check if passable, including blocks with height 1.5. + * @param access + * @param loc + * @return + */ + public static final boolean isPassableExact(final BlockCache access, final Location loc){ + return isPassableExact(access, loc.getX(), loc.getY(), loc.getZ(), access.getTypeId(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + } + + /** * Requires the hit-box of the block is hit (...): this checks for special blocks properties such as glass panes and similar.
* Ray-tracing version for passable-workarounds. diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java index 88a107c1..2b6fd130 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java @@ -617,7 +617,10 @@ public class PlayerLocation { * @return */ public boolean isPassable() { - if (passable == null) passable = BlockProperties.isPassable(blockCache, x, y, z, getTypeId()); + if (passable == null){ + passable = BlockProperties.isPassable(blockCache, x, y, z, getTypeId()); +// passable = BlockProperties.isPassableExact(blockCache, x, y, z, getTypeId()); + } return passable; } diff --git a/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/BlockCacheCBDev.java b/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/BlockCacheCBDev.java index 113e5688..6f35e180 100644 --- a/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/BlockCacheCBDev.java +++ b/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/BlockCacheCBDev.java @@ -68,7 +68,7 @@ public class BlockCacheCBDev extends BlockCache implements IBlockAccess{ @SuppressWarnings("rawtypes") final List list = world.getEntities(mcEntity, box); @SuppressWarnings("rawtypes") - Iterator iterator = list.iterator(); + final Iterator iterator = list.iterator(); while (iterator.hasNext()) { final net.minecraft.server.v1_4_R1.Entity other = (net.minecraft.server.v1_4_R1.Entity) iterator.next(); if (!(other instanceof EntityBoat) && !(other instanceof EntityMinecart)) continue; diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java index 221b5356..a3d2fbc4 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java @@ -61,6 +61,7 @@ public class Passable extends Check { // From should be the set-back. loc = null; } else if (BlockProperties.isPassable(from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))){ +// } else if (BlockProperties.isPassableExact(from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))){ // (Mind that this can be the case on the same block theoretically.) // Keep loc as set-back. } @@ -68,6 +69,7 @@ public class Passable extends Check { // Otherwise keep loc as set-back. } else if (to.isBlockAbove(from) && BlockProperties.isPassable(from.getBlockCache(), from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), from.getBlockZ()))){ +// else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(), from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), from.getBlockZ()))){ // Allow the move up if the head is free. return null; } @@ -84,6 +86,7 @@ public class Passable extends Check { if (data.hasSetBack()){ final Location ref = data.getSetBack(to); if (BlockProperties.isPassable(from.getBlockCache(), ref)){ +// if (BlockProperties.isPassableExact(from.getBlockCache(), ref)){ loc = ref; } } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 42799f5f..1cf8bfe5 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -409,6 +409,14 @@ public class SurvivalFly extends Check { } } +// // Check maximal absolute distance (jumping). +// if (!data.sfDirty && yDistance > 0.57 + data.jumpAmplifier * 0.2 && !toOnGround && from.isPassable()){ +// // TODO: Side conditions... from.isPassable is checked because of pistons. +// // TODO: Pistons don't work. +// vDistanceAboveLimit = Math.max(vDistanceAboveLimit, yDistance - 0.53 + data.jumpAmplifier * 0.2); +// tags.add("fastascend"); +// } + // TODO: Velocity handling here [concept: set vdistAbove.. almost always]? // TODO: This might need max(0, for ydiff)