[BLIND] Add blocks for MC 1.8.

This commit is contained in:
asofold 2014-10-26 16:38:35 +01:00
parent f965ea0610
commit 43dea0830a
3 changed files with 200 additions and 82 deletions

View File

@ -12,87 +12,96 @@ import fr.neatmonster.nocheatplus.utilities.BlockProperties;
*/
public class BlockInit {
// TODO: Change to assert names only?, would be better with being able to feed MC names or map them as well, though.
// TODO: Change to assert names only?, would be better with being able to feed MC names or map them as well, though.
/**
* Check for Material existence, throw RuntimeException if not.
* @param id
*/
public static void assertMaterialExists(int id) {
if (BlockProperties.getMaterial(id) == null) {
throw new RuntimeException("Material " + id + " does not exist.");
}
}
/**
* Check for Material existence, throw RuntimeException if not.
* @param id
*/
public static void assertMaterialExists(int id) {
if (BlockProperties.getMaterial(id) == null) {
throw new RuntimeException("Material " + id + " does not exist.");
}
}
/**
* Check for material existence and naming (exact match).
* @param id
* @param name
*/
public static void assertMaterialName(int id, String name) {
Material mat = BlockProperties.getMaterial(id);
if ( mat == null) {
throw new RuntimeException("Material " + id + " does not exist.");
}
if (mat.name().equals(name)) {
throw new RuntimeException("Name for Material " + id + " ('" + mat.name() + "') does not match '" + name + "'.");
}
}
/**
* Check for material existence and naming (exact match).
* @param id
* @param name
*/
public static void assertMaterialName(int id, String name) {
Material mat = BlockProperties.getMaterial(id);
if ( mat == null) {
throw new RuntimeException("Material " + id + " does not exist.");
}
if (mat.name().equals(name)) {
throw new RuntimeException("Name for Material " + id + " ('" + mat.name() + "') does not match '" + name + "'.");
}
}
/**
* Check for material existence and naming (parts must all be contained with ignored case).
* @param id
* @param parts
*/
public static void assertMaterialNameMatch(int id, String... parts) {
Material mat = BlockProperties.getMaterial(id);
if ( mat == null) {
throw new RuntimeException("Material " + id + " does not exist.");
}
String name = mat.name().toLowerCase();
for (String part : parts) {
if (name.indexOf(part.toLowerCase()) < 0) {
throw new RuntimeException("Name for Material " + id + " ('" + mat.name() + "') should contain '" + part + "'.");
}
}
}
/**
* Check for material existence and naming (parts must all be contained with ignored case).
* @param id
* @param parts
*/
public static void assertMaterialNameMatch(int id, String... parts) {
Material mat = BlockProperties.getMaterial(id);
if ( mat == null) {
throw new RuntimeException("Material " + id + " does not exist.");
}
String name = mat.name().toLowerCase();
for (String part : parts) {
if (name.indexOf(part.toLowerCase()) < 0) {
throw new RuntimeException("Name for Material " + id + " ('" + mat.name() + "') should contain '" + part + "'.");
}
}
}
/**
* Set block breaking properties same as the block of the given material.
* @param newId
* @param mat
*/
public static void setPropsAs(int newId, Material mat) {
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(mat));
}
/**
* Set block breaking properties same as the block of the given material.
* @param newId
* @param mat
*/
public static void setPropsAs(int newId, Material mat) {
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(mat));
}
/**
* Set block breaking properties same as the block of the given id.
* @param newId
* @param mat
*/
public static void setPropsAs(int newId, int otherId) {
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(otherId));
}
/**
* Set block breaking properties same as the block of the given id.
* @param newId
* @param mat
*/
public static void setPropsAs(int newId, int otherId) {
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(otherId));
}
/**
* Set block breaking and shape properties same as the block of the given material.
* @param newId
* @param mat
*/
public static void setAs(int newId, Material mat) {
BlockFlags.setFlagsAs(newId, mat);
setPropsAs(newId, mat);
}
/**
* Set block breaking and shape properties same as the block of the given material.
* @param newId
* @param mat
*/
public static void setAs(int newId, Material mat) {
BlockFlags.setFlagsAs(newId, mat);
setPropsAs(newId, mat);
}
/**
* Set block breaking and shape properties same as the block of the given id.
* @param newId
* @param mat
*/
public static void setAs(int newId, int otherId) {
BlockFlags.setFlagsAs(newId, otherId);
setPropsAs(newId, otherId);
}
/**
* Set block breaking and shape properties same as the block of the given id.
* @param newId
* @param mat
*/
public static void setAs(int newId, int otherId) {
BlockFlags.setFlagsAs(newId, otherId);
setPropsAs(newId, otherId);
}
/**
* Set like air, plus instantly breakable.
* @param newId
*/
public static void setInstantAir(int newId) {
BlockFlags.setFlagsAs(newId, Material.AIR);
BlockProperties.setBlockProps(newId, BlockProperties.instantType);
}
}

View File

@ -0,0 +1,108 @@
package fr.neatmonster.nocheatplus.compat.blocks.init.vanilla;
import org.bukkit.Material;
import fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup;
import fr.neatmonster.nocheatplus.compat.blocks.init.BlockInit;
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.utilities.BlockFlags;
public class BlocksMC1_8 implements BlockPropertiesSetup {
public BlocksMC1_8() {
BlockInit.assertMaterialNameMatch(166, "barrier");
BlockInit.assertMaterialNameMatch(165, "slime", "block");
BlockInit.assertMaterialNameMatch(187, "fence", "gate");
BlockInit.assertMaterialNameMatch(176, "banner");
BlockInit.assertMaterialNameMatch(169, "sea", "lantern");
}
@Override
public void setupBlockProperties(WorldConfigProvider<?> worldConfigProvider) {
// 165(SLIME_BLOCK
BlockInit.setAs(165, Material.TNT); // Full block, instant break.
// 166(BARRIER
BlockInit.setAs(166, Material.BEDROCK); // Full block, unbreakable.
// 167(IRON_TRAP_DOOR
BlockFlags.setFlagsAs(167, Material.TRAP_DOOR);
BlockInit.setPropsAs(167, Material.IRON_DOOR_BLOCK);
// 168(PRISMARINE
BlockInit.setAs(168, Material.STONE);
// 169(SEA_LANTERN
BlockInit.setAs(169, Material.REDSTONE_LAMP_OFF);
// 176(STANDING_BANNER
BlockInit.setInstantAir(176);
// 177(WALL_BANNER
BlockInit.setInstantAir(177);
// 178(DAYLIGHT_DETECTOR_INVERTED
BlockInit.setAs(178, Material.DAYLIGHT_DETECTOR);
// 179(RED_SANDSTONE
BlockInit.setAs(179, Material.SANDSTONE);
// 180(RED_SANDSTONE_STAIRS
BlockInit.setAs(180, Material.SANDSTONE_STAIRS);
// 181(DOUBLE_STEP_2
BlockInit.setAs(181, Material.DOUBLE_STEP); // TODO: red sandstone / prismarine ?
// 182(STEP_2
BlockInit.setAs(182, Material.STEP); // TODO: red sandstone / prismarine ?
// 183(SPRUCE_FENCE_GATE
BlockInit.setAs(183, Material.FENCE_GATE);
// 184(BIRCH_FENCE_GATE
BlockInit.setAs(184, Material.FENCE_GATE);
// 185(JUNGLE_FENCE_GATE
BlockInit.setAs(185, Material.FENCE_GATE);
// 186(DARK_OAK_FENCE_GATE
BlockInit.setAs(186, Material.FENCE_GATE);
// 187(ACACIA_FENCE_GATE
BlockInit.setAs(187, Material.FENCE_GATE);
// 188(SPRUCE_FENCE
BlockInit.setAs(188, Material.FENCE);
// 189(BIRCH_FENCE
BlockInit.setAs(189, Material.FENCE);
// 190(JUNGLE_FENCE
BlockInit.setAs(190, Material.FENCE);
// 191(DARK_OAK_FENCE
BlockInit.setAs(191, Material.FENCE);
// 192(ACACIA_FENCE
BlockInit.setAs(192, Material.FENCE);
// 193(SPRUCE_DOOR
BlockInit.setAs(193, Material.WOODEN_DOOR);
// 194(BIRCH_DOOR
BlockInit.setAs(194, Material.WOODEN_DOOR);
// 195(JUNGLE_DOOR
BlockInit.setAs(195, Material.WOODEN_DOOR);
// 196(ACACIA_DOOR
BlockInit.setAs(196, Material.WOODEN_DOOR);
// 197(DARK_OAK_DOOR
BlockInit.setAs(197, Material.WOODEN_DOOR);
LogUtil.logInfo("[NoCheatPlus] Added block-info for Minecraft 1.8 blocks.");
}
}

View File

@ -17,6 +17,7 @@ public class VanillaBlocksFactory implements BlockPropertiesSetup{
setups.add(new BlocksMC1_5());
setups.add(new BlocksMC1_6_1());
setups.add(new BlocksMC1_7_2());
setups.add(new BlocksMC1_8());
}
catch(Throwable t){}
for (final BlockPropertiesSetup setup : setups){