From 511bcfd4adbcb35c51cb6ccac3ca0c002d1a84e0 Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 28 Nov 2016 00:04:30 +0100 Subject: [PATCH] More useful method naming and behavior for getting IBlockCacheNodeS. --- .../compat/blocks/BlockChangeTracker.java | 2 +- .../nocheatplus/utilities/map/BlockCache.java | 31 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlockChangeTracker.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlockChangeTracker.java index 9550599e..f2b103d1 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlockChangeTracker.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/BlockChangeTracker.java @@ -582,7 +582,7 @@ public class BlockChangeTracker { // TODO: Test which ones can actually move a player (/how). // Add this block. addBlockChange(changeId, tick, worldNode, x, y, z, Direction.getDirection(blockFace), - blockCache.getBlockCacheNode(x, y, z, true)); + blockCache.getOrCreateBlockCacheNode(x, y, z, true)); } /** diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockCache.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockCache.java index cb7084b9..e3e5fa8c 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockCache.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/map/BlockCache.java @@ -348,31 +348,42 @@ public abstract class BlockCache { } /** - * Get the internally stored BlockCacheNode instance for the given - * coordinates. Creation/updating is controlled with forceSetAll. + * Get an IBlockCacheNode instance for the given coordinates. With + * forceSetAll set to true, it will be ensured that all properties are set + * for the returned node. * * @param x * @param y * @param z * @param forceSetAll * @return If forceSetAll is true, a node will always be returned with all - * properties set. If forceSetAll is false, null might be returned, - * if no node is present for the given coordinates. + * properties set. If forceSetAll is false, a node with at least the + * id set will be returned. */ - public IBlockCacheNode getBlockCacheNode(int x, int y, int z, boolean forceSetAll) { + public IBlockCacheNode getOrCreateBlockCacheNode(int x, int y, int z, boolean forceSetAll) { + final BlockCacheNode node = getOrCreateNode(x, y, z); if (forceSetAll) { - final BlockCacheNode node = getOrCreateNode(x, y, z); if (!node.isDataFetched()) { node.setData(fetchData(x, y, z)); } if (!node.isBoundsFetched()) { node.setBounds(fetchBounds(x, y, z)); } - return node; - } - else { - return nodeMap.get(x, y, z); } + return node; + } + + /** + * Just return the internally stored node for these coordinates, or null if + * none is there. + * + * @param x + * @param y + * @param z + * @return + */ + public IBlockCacheNode getBlockCacheNode(int x, int y, int z) { + return nodeMap.get(x, y, z); } /**