Add BukkitThinFence. Remove unneeded flag.
(Configurability is another step.)
This commit is contained in:
parent
b89c3af589
commit
4a7fd059dd
|
@ -10,6 +10,7 @@ import fr.neatmonster.nocheatplus.compat.blocks.init.BlockInit;
|
||||||
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitShapeModel;
|
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitShapeModel;
|
||||||
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitSlab;
|
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitSlab;
|
||||||
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitStairs;
|
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitStairs;
|
||||||
|
import fr.neatmonster.nocheatplus.compat.bukkit.model.BukkitFence;
|
||||||
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||||
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||||
import fr.neatmonster.nocheatplus.utilities.map.BlockFlags;
|
import fr.neatmonster.nocheatplus.utilities.map.BlockFlags;
|
||||||
|
@ -22,6 +23,8 @@ public class MCAccessBukkitModern extends MCAccessBukkit {
|
||||||
|
|
||||||
private static final BukkitShapeModel MODEL_SLAB = new BukkitSlab();
|
private static final BukkitShapeModel MODEL_SLAB = new BukkitSlab();
|
||||||
private static final BukkitShapeModel MODEL_STAIRS= new BukkitStairs();
|
private static final BukkitShapeModel MODEL_STAIRS= new BukkitStairs();
|
||||||
|
private static final BukkitShapeModel MODEL_THIN_FENCE = new BukkitFence(
|
||||||
|
0.1375 + 0.3, 0.8625 - 0.3, 1.0);
|
||||||
|
|
||||||
public MCAccessBukkitModern() {
|
public MCAccessBukkitModern() {
|
||||||
super();
|
super();
|
||||||
|
@ -50,23 +53,24 @@ public class MCAccessBukkitModern extends MCAccessBukkit {
|
||||||
processedBlocks.add(mat);
|
processedBlocks.add(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pre-process for flags.
|
|
||||||
// TODO: Also consider removing flags (passable_x4 etc).
|
// TODO: Also consider removing flags (passable_x4 etc).
|
||||||
for (final Material mat : Material.values()) {
|
|
||||||
if (MaterialUtil.SLABS.contains(mat)) {
|
// Thin fence: Glass panes, iron bars.
|
||||||
BlockFlags.addFlags(mat, BlockProperties.F_MODEL_SLAB);
|
for (final Material mat : MaterialUtil.addBlocks(
|
||||||
}
|
MaterialUtil.GLASS_PANES, BridgeMaterial.IRON_BARS)) {
|
||||||
|
processedBlocks.add(mat);
|
||||||
|
shapeModels.put(mat, MODEL_THIN_FENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slabs
|
||||||
|
for (final Material mat : MaterialUtil.SLABS) {
|
||||||
|
processedBlocks.add(mat);
|
||||||
|
shapeModels.put(mat, MODEL_SLAB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort to processed by flags.
|
// Sort to processed by flags.
|
||||||
for (final Material mat : Material.values()) {
|
for (final Material mat : Material.values()) {
|
||||||
final long flags = BlockProperties.getBlockFlags(mat);
|
final long flags = BlockProperties.getBlockFlags(mat);
|
||||||
// Step.
|
|
||||||
if (BlockFlags.hasAnyFlag(flags, BlockProperties.F_MODEL_SLAB)) {
|
|
||||||
// TODO: Should scrap the flag and just register the shape model.
|
|
||||||
processedBlocks.add(mat);
|
|
||||||
shapeModels.put(mat, MODEL_SLAB);
|
|
||||||
}
|
|
||||||
// Stairs.
|
// Stairs.
|
||||||
if (BlockFlags.hasAnyFlag(flags, BlockProperties.F_STAIRS)) {
|
if (BlockFlags.hasAnyFlag(flags, BlockProperties.F_STAIRS)) {
|
||||||
processedBlocks.add(mat);
|
processedBlocks.add(mat);
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package fr.neatmonster.nocheatplus.compat.bukkit.model;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.MultipleFacing;
|
||||||
|
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||||
|
|
||||||
|
public class BukkitFence implements BukkitShapeModel {
|
||||||
|
|
||||||
|
private final double minXZ;
|
||||||
|
private final double maxXZ;
|
||||||
|
private final double height;
|
||||||
|
|
||||||
|
public BukkitFence(double minXZ, double maxXZ, double height) {
|
||||||
|
this.minXZ = minXZ;
|
||||||
|
this.maxXZ = maxXZ;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double[] getShape(final BlockCache blockCache,
|
||||||
|
final World world, final int x, final int y, final int z) {
|
||||||
|
|
||||||
|
// 13749998807909
|
||||||
|
// 86250001192093
|
||||||
|
// 0.1375, 0.8625
|
||||||
|
|
||||||
|
final Block block = world.getBlockAt(x, y, z);
|
||||||
|
final BlockState state = block.getState();
|
||||||
|
final BlockData blockData = state.getBlockData();
|
||||||
|
|
||||||
|
if (blockData instanceof MultipleFacing) {
|
||||||
|
// Note isPassableWorkaround for these (no voxel shapes / multi cuboid yet).
|
||||||
|
final MultipleFacing fence = (MultipleFacing) blockData;
|
||||||
|
// TODO: If height > 1.0, check if it needs to be capped, provided relevant.
|
||||||
|
double[] res = new double[] {minXZ, 0.0, minXZ, maxXZ, height, maxXZ};
|
||||||
|
for (final BlockFace face : fence.getFaces()) {
|
||||||
|
switch (face) {
|
||||||
|
case EAST:
|
||||||
|
res[3] = 1.0;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
res[2] = 0.0;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
res[0] = 0.0;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
res[5] = 1.0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFakeData(final BlockCache blockCache,
|
||||||
|
final World world, final int x, final int y, final int z) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -854,12 +854,6 @@ public class BlockProperties {
|
||||||
*/
|
*/
|
||||||
public static final long F_VARIABLE_REDSTONE = f_flag();
|
public static final long F_VARIABLE_REDSTONE = f_flag();
|
||||||
|
|
||||||
/**
|
|
||||||
* BukkitModern model flag, set by MCAccessBukkitModern for routing, iff
|
|
||||||
* available.
|
|
||||||
*/
|
|
||||||
public static final long F_MODEL_SLAB = f_flag();
|
|
||||||
|
|
||||||
/** Height 15/16 (0.9375 = 1 - 0.0625). */
|
/** Height 15/16 (0.9375 = 1 - 0.0625). */
|
||||||
public static final long F_HEIGHT16_15 = f_flag();
|
public static final long F_HEIGHT16_15 = f_flag();
|
||||||
|
|
||||||
|
|
|
@ -74,13 +74,37 @@ public class MaterialUtil {
|
||||||
* @param names
|
* @param names
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static Set<Material> addBlocks(Set<Material> set, String... names) {
|
public static Set<Material> addBlocks(Set<Material> set, String... names) {
|
||||||
final LinkedHashSet<Material> res = new LinkedHashSet<Material>(set);
|
final LinkedHashSet<Material> res = new LinkedHashSet<Material>(set);
|
||||||
res.addAll(BridgeMaterial.getAllBlocks(names));
|
res.addAll(BridgeMaterial.getAllBlocks(names));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<Material> join(final Set<Material>...sets ) {
|
/**
|
||||||
|
* Get a new set containing the given set, as well as all non-null Material entries.
|
||||||
|
*
|
||||||
|
* @param set Set is not checked.
|
||||||
|
* @param materials
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Set<Material> addBlocks(final Set<Material> set, final Material... materials) {
|
||||||
|
final LinkedHashSet<Material> res = new LinkedHashSet<Material>(set);
|
||||||
|
for (final Material mat : materials) {
|
||||||
|
if (mat != null && mat.isBlock()) {
|
||||||
|
res.add(mat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new set containing all elements of the given sets.
|
||||||
|
*
|
||||||
|
* @param sets
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Set<Material> join(final Set<Material>...sets ) {
|
||||||
final Set<Material> res = new LinkedHashSet<Material>();
|
final Set<Material> res = new LinkedHashSet<Material>();
|
||||||
for (final Set<Material> set : sets) {
|
for (final Set<Material> set : sets) {
|
||||||
res.addAll(set);
|
res.addAll(set);
|
||||||
|
|
Loading…
Reference in New Issue