Skip to content

Commit

Permalink
Refine some complex blocks. Hide unnecessary logs on startup
Browse files Browse the repository at this point in the history
* Changes:
+ Implement multi-bounds for complex blocks
+ Hide "Added block-info for Minecraft 1.x.x blocks" logs on startup
+ Restore some NMS-depend features
Still missing conduit, cake, anvil, grindstone but these blocks still work fine so nah.
Still missing model for powder snow, maybe for another day...
  • Loading branch information
xaw3ep committed Jul 20, 2021
1 parent fb52e44 commit b2d015a
Show file tree
Hide file tree
Showing 24 changed files with 510 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import fr.neatmonster.nocheatplus.compat.bukkit.model.*;
import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectBase;
import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectDamageSource;
import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectLivingEntity;
import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectPlayer;
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
Expand All @@ -39,12 +40,30 @@ public class MCAccessBukkitModern extends MCAccessBukkit {

protected ReflectBase reflectBase = null;
protected ReflectDamageSource reflectDamageSource = null;
protected ReflectPlayer reflectPlayer = null;
protected ReflectLivingEntity reflectLivingEntity = null;

protected final Map<Material, BukkitShapeModel> shapeModels = new HashMap<Material, BukkitShapeModel>();

// Blocks that can automatic fetch bounding box from API
private static final BukkitShapeModel MODEL_AUTO_FETCH = new BukkitFetchableBound();

// Blocks that form from multi-bounds
private static final BukkitShapeModel MODEL_BREWING_STAND = new BukkitStatic(
// Bottom rod
0.0625, 0.0, 0.0625, 0.9375, 0.125, 0.9375,
// Rod
0.4375, 0.125, 0.4375, 0.5625, 0.8749, 0.5625);

private static final BukkitShapeModel MODEL_CANDLE_CAKE = new BukkitStatic(
// Cake
0.0625, 0.0, 0.0625, 0.9375, 0.5, 0.9375,
// Candle
0.4375, 0.5, 0.4375, 0.5625, 0.875, 0.5625);
private static final BukkitShapeModel MODEL_HOPPER = new BukkitHopper();
private static final BukkitShapeModel MODEL_CAULDRON = new BukkitCauldron(0.1875, 0.125, 0.8125, 0.0625);
private static final BukkitShapeModel MODEL_COMPOSTER = new BukkitCauldron(0.0, 0.125, 1.0, 0.125);
private static final BukkitShapeModel MODEL_PISTON_HEAD = new BukkitPistonHead();

// Blocks that change shape based on interaction or redstone.
private static final BukkitShapeModel MODEL_DOOR = new BukkitDoor();
private static final BukkitShapeModel MODEL_TRAP_DOOR = new BukkitTrapDoor();
Expand Down Expand Up @@ -98,9 +117,6 @@ public class MCAccessBukkitModern extends MCAccessBukkit {
0.0625, 0.875);
private static final BukkitShapeModel MODEL_HONEY_BLOCK = new BukkitStatic(
0.0625, 0.9375);
private static final BukkitShapeModel MODEL_HOPPER = new BukkitStatic(
0, 0.25, 0, 1, 1, 1);
private static final BukkitShapeModel MODEL_CHAIN = new BukkitChain();

// Static blocks with full height sorted by inset.
private static final BukkitShapeModel MODEL_INSET16_1_HEIGHT100 = new BukkitStatic(
Expand All @@ -118,8 +134,6 @@ public class MCAccessBukkitModern extends MCAccessBukkit {
0.5625);
private static final BukkitShapeModel MODEL_XZ100_HEIGHT4_3 = new BukkitStatic(
0.75);
private static final BukkitShapeModel MODEL_XZ100_HEIGHT8_7 = new BukkitStatic(
0.875);
private static final BukkitShapeModel MODEL_XZ100_HEIGHT16_15 = new BukkitStatic(
0.9375);

Expand All @@ -138,7 +152,7 @@ public MCAccessBukkitModern() {
try {
this.reflectBase = new ReflectBase();
this.reflectDamageSource = new ReflectDamageSource(this.reflectBase);
this.reflectPlayer = new ReflectPlayer(this.reflectBase, null, this.reflectDamageSource);
this.reflectLivingEntity = new ReflectLivingEntity(this.reflectBase, null, this.reflectDamageSource);
} catch(ClassNotFoundException ex) {

}
Expand Down Expand Up @@ -167,9 +181,6 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
// Variables for repeated flags (Temporary flags, these should be fixed later so that they are not added here)
final long blockFix = BlockFlags.SOLID_GROUND;
// Adjust flags for individual blocks.
BlockProperties.setBlockFlags(Material.CAULDRON,
BlockFlags.SOLID_GROUND | BlockProperties.F_GROUND_HEIGHT
| BlockProperties.F_MIN_HEIGHT4_1);
BlockProperties.setBlockFlags(Material.COCOA, blockFix);
BlockProperties.setBlockFlags(Material.TURTLE_EGG, blockFix);
BlockProperties.setBlockFlags(Material.CHORUS_PLANT, blockFix);
Expand All @@ -182,7 +193,6 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide

// Directly keep blocks as is.
for (final Material mat : new Material[] {
Material.CAULDRON,
BridgeMaterial.COBWEB,
BridgeMaterial.MOVING_PISTON,
Material.SNOW,
Expand All @@ -208,11 +218,19 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
for (Material mat : BridgeMaterial.getAllBlocks(
"azalea", "flowering_azalea",
"big_dripleaf", "sculk_sensor", "pointed_dripstone",
"campfire", "soul_campfire", "stonecutter"
"campfire", "soul_campfire", "stonecutter", "chain"
)) {
addModel(mat, MODEL_AUTO_FETCH);
}


// Cauldron
for (Material mat : MaterialUtil.CAULDRON) {
BlockProperties.setBlockFlags(mat,
BlockFlags.SOLID_GROUND | BlockProperties.F_GROUND_HEIGHT
| BlockProperties.F_MIN_HEIGHT16_5);
addModel(mat, MODEL_CAULDRON);
}

//Anvil
for (Material mat : new Material[] {
Material.ANVIL,
Expand Down Expand Up @@ -269,11 +287,15 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
addModel(mat, MODEL_XZ100_HEIGHT4_3);
}

for (Material mat : MaterialUtil.ALL_CANDLE_CAKE) {
addModel(mat, MODEL_CANDLE_CAKE);
}

// 7/8 height.
for (Material mat : new Material[] {
Material.BREWING_STAND // TODO: base is 1/8, center 0.875 - needs multi-cuboid.
Material.BREWING_STAND
}) {
addModel(mat, MODEL_XZ100_HEIGHT8_7);
addModel(mat, MODEL_BREWING_STAND);
}

// 16/15 height, full xz bounds.
Expand Down Expand Up @@ -389,7 +411,10 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
)) {
addModel(mat, MODEL_PISTON);
}


// Piston Head
addModel(BridgeMaterial.PISTON_HEAD, MODEL_PISTON_HEAD);

// Levelled blocks
for (Material mat : BridgeMaterial.getAllBlocks(
"snow", "water", "lava"
Expand All @@ -405,21 +430,23 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
// Lectern
Material mt = BridgeMaterial.getBlock("lectern");
if (mt != null) addModel(mt, MODEL_LECTERN);

// Bamboo
mt = BridgeMaterial.getBlock("bamboo");
if (mt != null) addModel(mt, MODEL_BAMBOO);

// Bell
mt = BridgeMaterial.getBlock("bell");
if (mt != null) addModel(mt, MODEL_BELL);


// Composter
mt = BridgeMaterial.getBlock("composter");
if (mt != null) addModel(mt, MODEL_COMPOSTER);

// Honey Block
mt = BridgeMaterial.getBlock("honey_block");
if (mt != null) addModel(mt, MODEL_HONEY_BLOCK);

mt = BridgeMaterial.getBlock("chain");
if (mt != null) addModel(mt, MODEL_CHAIN);

// Sort to processed by flags.
for (final Material mat : Material.values()) {
final long flags = BlockProperties.getBlockFlags(mat);
Expand Down Expand Up @@ -448,15 +475,15 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide

private Object getHandle(Player player) {
// TODO: CraftPlayer check (isAssignableFrom)?
if (this.reflectPlayer == null || this.reflectPlayer.obcGetHandle == null) {
if (this.reflectLivingEntity == null || this.reflectLivingEntity.obcGetHandle == null) {
return null;
}
Object handle = ReflectionUtil.invokeMethodNoArgs(this.reflectPlayer.obcGetHandle, player);
Object handle = ReflectionUtil.invokeMethodNoArgs(this.reflectLivingEntity.obcGetHandle, player);
return handle;
}

private boolean canDealFallDamage() {
return this.reflectPlayer != null && this.reflectPlayer.nmsDamageEntity != null && this.reflectDamageSource.nmsFALL != null;
return this.reflectLivingEntity != null && this.reflectLivingEntity.nmsDamageEntity != null && this.reflectDamageSource.nmsFALL != null;
}

@Override
Expand All @@ -470,16 +497,16 @@ public void dealFallDamage(Player player, double damage) {
Object handle = getHandle(player);

if (handle != null)
ReflectionUtil.invokeMethod(this.reflectPlayer.nmsDamageEntity, handle, this.reflectDamageSource.nmsFALL, (float) damage);
ReflectionUtil.invokeMethod(this.reflectLivingEntity.nmsDamageEntity, handle, this.reflectDamageSource.nmsFALL, (float) damage);
} else BridgeHealth.damage(player, damage);
}

@Override
public boolean resetActiveItem(Player player) {
if (this.reflectPlayer != null && this.reflectPlayer.nmsclearActiveItem != null) {
if (this.reflectLivingEntity != null && this.reflectLivingEntity.nmsclearActiveItem != null) {
Object handle = getHandle(player);
if (handle != null) {
ReflectionUtil.invokeMethodNoArgs(this.reflectPlayer.nmsclearActiveItem, handle);
ReflectionUtil.invokeMethodNoArgs(this.reflectLivingEntity.nmsclearActiveItem, handle);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Bell;
import org.bukkit.block.data.type.Bell.Attachment;

import fr.neatmonster.nocheatplus.utilities.map.BlockCache;

Expand All @@ -32,57 +31,94 @@ public double[] getShape(final BlockCache blockCache,
final Block block = world.getBlockAt(x, y, z);
final BlockData blockData = block.getBlockData();
if (blockData instanceof Bell) {
Bell b = (Bell) blockData;
BlockFace face = b.getFacing();
switch (b.getAttachment()) {
case CEILING: return new double[] {0.25, 1-0.75, 0.25, 0.75, 1.0, 0.75};
case DOUBLE_WALL:
switch (face) {
case NORTH:
case SOUTH:
return new double[] {0.25, 0.375, 0.0, 0.75, 0.9375, 1.0};
case WEST:
case EAST:
return new double[] {0.0, 0.375, 0.25, 1.0, 0.9375, 0.75};
default:
break;
}
break;
case FLOOR:
switch (face) {
case NORTH:
case SOUTH:
return new double[] {0.0, 0.0, 0.25, 1.0, 1.0, 0.75};
case WEST:
case EAST:
return new double[] {0.25, 0.0, 0.0, 0.75, 1.0, 1.0};
default:
break;
}
break;
case SINGLE_WALL:
switch (face) {
case NORTH: return new double[] {0.25, 0.375, 0.0, 0.75, 0.9375, 1 - 0.1875};
case SOUTH: return new double[] {0.25, 0.375, 0.1875, 0.75, 0.9375, 1.0};
case WEST: return new double[] {0.0, 0.375, 0.25, 1.0 - 0.1875, 0.9375, 0.75};
case EAST: return new double[] {0.1875, 0.375, 0.25, 1.0, 0.9375, 0.75};
default:
break;
}
}
Bell b = (Bell) blockData;
BlockFace face = b.getFacing();
switch (b.getAttachment()) {
case CEILING: return new double[] {0.25, 1-0.75, 0.25, 0.75, 1.0, 0.75};
case DOUBLE_WALL:
switch (face) {
case NORTH:
case SOUTH:
return new double[] {
// Bottom bell
0.25, 0.25, 0.25, 0.75, 0.375, 0.75,
// Body
0.3125, 0.375, 0.3125, 0.6875, 0.8125, 0.6875,
// Stick hold the bell
0.4375, 0.8125, 0.0, 0.5625, 0.9375, 1.0
//0.0, 0.8125, 0.4375, 1.0, 0.9375, 0.5625
};
case WEST:
case EAST:
return new double[] {
// Bottom bell
0.25, 0.25, 0.25, 0.75, 0.375, 0.75,
// Body
0.3125, 0.375, 0.3125, 0.6875, 0.8125, 0.6875,
// Stick hold the bell
0.0, 0.8125, 0.4375, 1.0, 0.9375, 0.5625
};
default:
break;
}
break;
case FLOOR:
switch (face) {
case NORTH:
case SOUTH:
return new double[] {0.0, 0.0, 0.25, 1.0, 1.0, 0.75};
case WEST:
case EAST:
return new double[] {0.25, 0.0, 0.0, 0.75, 1.0, 1.0};
default:
break;
}
break;
case SINGLE_WALL:
switch (face) {
case NORTH: return new double[] {
// Bottom bell
0.25, 0.25, 0.25, 0.75, 0.375, 0.75,
// Body
0.3125, 0.375, 0.3125, 0.6875, 0.8125, 0.6875,
// Stick hold the bell
0.4375, 0.8125, 0.0, 0.5625, 0.9375, 0.8125
};
case SOUTH: return new double[] {
// Bottom bell
0.25, 0.25, 0.25, 0.75, 0.375, 0.75,
// Body
0.3125, 0.375, 0.3125, 0.6875, 0.8125, 0.6875,
// Stick hold the bell
0.4375, 0.8125, 0.1875, 0.5625, 0.9375, 1.0
};
case WEST: return new double[] {
// Bottom bell
0.25, 0.25, 0.25, 0.75, 0.375, 0.75,
// Body
0.3125, 0.375, 0.3125, 0.6875, 0.8125, 0.6875,
// Stick hold the bell
0.0, 0.8125, 0.4375, 0.8125, 0.9375, 0.5625
};
case EAST: return new double[] {
// Bottom bell
0.25, 0.25, 0.25, 0.75, 0.375, 0.75,
// Body
0.3125, 0.375, 0.3125, 0.6875, 0.8125, 0.6875,
// Stick hold the bell
0.1875, 0.8125, 0.4375, 1.0, 0.9375, 0.5625
};
default:
break;
}
}
}
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) {
final Block block = world.getBlockAt(x, y, z);
final BlockData blockData = block.getBlockData();
if (blockData instanceof Bell) {
Bell b = (Bell) blockData;
if (b.getAttachment() == Attachment.SINGLE_WALL) return 0x4;
}
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@
package fr.neatmonster.nocheatplus.compat.bukkit.model;

import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.util.BoundingBox;

import fr.neatmonster.nocheatplus.compat.Bridge1_13;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;

public class BukkitChain implements BukkitShapeModel {
public class BukkitCauldron implements BukkitShapeModel {
private final double[] bounds;

public BukkitCauldron(double minY, double sideWidth, double sideHeight, double coreHeight) {
bounds = new double[] {
// Core
sideWidth, minY, sideWidth, 1 - sideWidth, minY + coreHeight, 1 - sideWidth,
// 4 side
0.0, minY, 0.0, 1.0, minY + sideHeight, sideWidth,
0.0, minY, 1.0 - sideWidth, 1.0, minY + sideHeight, 1.0,
0.0, minY, 0.0, sideWidth, minY + sideHeight, 1.0,
1.0 - sideWidth, minY, 0.0, 1.0, minY + sideHeight, 1.0
};
}

@Override
public double[] getShape(BlockCache blockCache, World world, int x, int y, int z) {
final Block block = world.getBlockAt(x, y, z);
if (Bridge1_13.hasBoundingBox()) {
BoundingBox bd = block.getBoundingBox();
return new double[] {bd.getMinX()-x, bd.getMinY()-y, bd.getMinZ()-z, bd.getMaxX()-x, bd.getMaxY()-y, bd.getMaxZ()-z};
}
return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
return bounds;
}

@Override
Expand Down
Loading

0 comments on commit b2d015a

Please sign in to comment.