mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
[BLIND] Add factory for vanilla blocks + early addition of 1.6 blocks.
This commit is contained in:
parent
cd9930d3c0
commit
f894a8da39
@ -0,0 +1,98 @@
|
||||
package fr.neatmonster.nocheatplus.compat.blocks.init;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockFlags;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
|
||||
/**
|
||||
* Auxiliary methods for block initialization.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public class BlockInit {
|
||||
|
||||
// TODO: Add "assertMaterialExist" for id and id + name (name: add assertMaterialMatches) also with name with RuntimeException
|
||||
|
||||
/**
|
||||
* Check for Material existence, throw RuntimeException if not.
|
||||
* @param id
|
||||
*/
|
||||
public static void assertMaterialExists(int id) {
|
||||
if (Material.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 = Material.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 = Material.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){
|
||||
setPropsAs(newId, mat.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 id.
|
||||
* @param newId
|
||||
* @param mat
|
||||
*/
|
||||
public static void setAs(int newId, int otherId){
|
||||
BlockFlags.setFlagsAs(newId, otherId);
|
||||
setPropsAs(newId, otherId);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,9 @@ 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;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
|
||||
@ -14,25 +16,9 @@ import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
*/
|
||||
public class BlocksMC1_5 implements BlockPropertiesSetup {
|
||||
|
||||
/**
|
||||
* TODO: Move somewhere.
|
||||
* @param newId
|
||||
* @param mat
|
||||
*/
|
||||
public static void setPropsAs(int newId, Material mat){
|
||||
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(mat.getId()));
|
||||
}
|
||||
|
||||
public static void setAs(int newId, Material mat){
|
||||
BlockFlags.setFlagsAs(newId, mat);
|
||||
setPropsAs(newId, mat);
|
||||
}
|
||||
|
||||
public BlocksMC1_5(){
|
||||
// Test if materials exist.
|
||||
if (Material.getMaterial(152) == null){
|
||||
throw new RuntimeException("Material for 1.5 does not exist.");
|
||||
}
|
||||
BlockInit.assertMaterialNameMatch(152, "redstone", "block");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,51 +29,51 @@ public class BlocksMC1_5 implements BlockPropertiesSetup {
|
||||
////////////////////
|
||||
|
||||
// 146 Trapped Chest
|
||||
setAs(146, Material.CHEST);
|
||||
BlockInit.setAs(146, Material.CHEST);
|
||||
|
||||
// 147 Weighted Pressure Plate (Light)
|
||||
// BlockFlags.addFlags(147, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT);
|
||||
setAs(147, Material.STONE_PLATE);
|
||||
BlockInit.setAs(147, Material.STONE_PLATE);
|
||||
|
||||
// 148 Weighted Pressure Plate (Heavy)
|
||||
// BlockFlags.addFlags(148, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT);
|
||||
setAs(148, Material.STONE_PLATE);
|
||||
BlockInit.setAs(148, Material.STONE_PLATE);
|
||||
|
||||
// 149 Redstone Comparator (inactive)
|
||||
// BlockFlags.addFlags(149, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT);
|
||||
setAs(149, Material.DIODE_BLOCK_OFF);
|
||||
BlockInit.setAs(149, Material.DIODE_BLOCK_OFF);
|
||||
|
||||
// 150 Redstone Comparator (active)
|
||||
// BlockFlags.addFlags(150, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT);
|
||||
setAs(150, Material.DIODE_BLOCK_ON);
|
||||
BlockInit.setAs(150, Material.DIODE_BLOCK_ON);
|
||||
|
||||
// 151 Daylight Sensor
|
||||
// BlockFlags.addFlags(151, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT);
|
||||
setAs(151, Material.HUGE_MUSHROOM_1);
|
||||
BlockInit.setAs(151, Material.HUGE_MUSHROOM_1);
|
||||
|
||||
// 152 Block of Redstone
|
||||
setAs(152, Material.ENCHANTMENT_TABLE);
|
||||
BlockInit.setAs(152, Material.ENCHANTMENT_TABLE);
|
||||
|
||||
// 153 Nether Quartz Ore
|
||||
setAs(153, Material.COAL_ORE);
|
||||
BlockInit.setAs(153, Material.COAL_ORE);
|
||||
|
||||
// 154 Hopper
|
||||
setAs(154, Material.COAL_ORE);
|
||||
BlockInit.setAs(154, Material.COAL_ORE);
|
||||
// TODO: Needs workaround. [workaround-flag + different purpose flag sets ?]
|
||||
BlockFlags.addFlags(154, BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT);
|
||||
|
||||
// 155 Block of Quartz
|
||||
setAs(155, Material.SANDSTONE);
|
||||
BlockInit.setAs(155, Material.SANDSTONE);
|
||||
|
||||
// 156 Quartz Stairs
|
||||
setAs(156, Material.SANDSTONE_STAIRS);
|
||||
BlockInit.setAs(156, Material.SANDSTONE_STAIRS);
|
||||
|
||||
// 157 Activator Rail
|
||||
setAs(157, Material.DETECTOR_RAIL);
|
||||
BlockInit.setAs(157, Material.DETECTOR_RAIL);
|
||||
|
||||
// 158 Dropper
|
||||
// BlockFlags.setFlagsAs(158, Material.DISPENSER);
|
||||
setAs(158, Material.DISPENSER);
|
||||
BlockInit.setAs(158, Material.DISPENSER);
|
||||
|
||||
|
||||
/////////////////////
|
||||
@ -100,6 +86,8 @@ public class BlocksMC1_5 implements BlockPropertiesSetup {
|
||||
|
||||
// 95 Locked chest
|
||||
BlockProperties.setBlockProps(95, BlockProperties.instantType);
|
||||
|
||||
LogUtil.logInfo("[NoCheatPlus] Added block-info for Minecraft 1.5 blocks.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
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;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties.BlockProps;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BlocksMC1_6_1 implements BlockPropertiesSetup{
|
||||
|
||||
public BlocksMC1_6_1(){
|
||||
BlockInit.assertMaterialNameMatch(173, "coal", "block");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupBlockProperties(WorldConfigProvider<?> worldConfigProvider) {
|
||||
|
||||
// Block of Coal: like block of redstone.
|
||||
BlockInit.setAs(173, 152);
|
||||
|
||||
// Hardened Clay
|
||||
BlockProperties.setBlockProps(172, new BlockProps(BlockProperties.woodPickaxe, 1.25f, BlockProperties.secToMs(6.25, 0.95, 0.5, 0.35, 0.25, 0.2)));
|
||||
BlockFlags.setFlagsAs(172, Material.STONE); // TODO: Assumption (!).
|
||||
|
||||
// Stained Clay: Set as hardened clay.
|
||||
BlockInit.setAs(159, 172);
|
||||
|
||||
// Hay Bale
|
||||
BlockInit.setPropsAs(170, Material.STONE_BUTTON);
|
||||
BlockFlags.setFlagsAs(170, Material.STONE); // TODO: Assumption (!).
|
||||
|
||||
// Carpet
|
||||
BlockProperties.setBlockProps(171, new BlockProps(BlockProperties.noTool, 0.1f, BlockProperties.secToMs(0.15)));
|
||||
BlockProperties.setBlockFlags(171, BlockProperties.F_IGN_PASSABLE);
|
||||
|
||||
LogUtil.logInfo("[NoCheatPlus] Added block-info for Minecraft 1.6.1 blocks.");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package fr.neatmonster.nocheatplus.compat.blocks.init.vanilla;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup;
|
||||
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
||||
|
||||
public class VanillaBlocksFactory implements BlockPropertiesSetup{
|
||||
|
||||
@Override
|
||||
public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvider) {
|
||||
// Standard setups (abort with first failure, low to high MC version).
|
||||
final List<BlockPropertiesSetup> setups = new LinkedList<BlockPropertiesSetup>();
|
||||
try{
|
||||
setups.add(new BlocksMC1_5());
|
||||
setups.add(new BlocksMC1_6_1());
|
||||
}
|
||||
catch(Throwable t){}
|
||||
for (final BlockPropertiesSetup setup : setups){
|
||||
try{
|
||||
// Assume the blocks setup to message success.
|
||||
setup.setupBlockProperties(worldConfigProvider);
|
||||
}
|
||||
catch(Throwable t){
|
||||
LogUtil.logSevere("[NoCheatPlus] " + setup.getClass().getSimpleName() + ".setupBlockProperties could not execute properly: " + t.getClass().getSimpleName() + " - " + t.getMessage());
|
||||
LogUtil.logSevere(t);
|
||||
// Abort further processing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -16,7 +16,16 @@ public class BlockFlags {
|
||||
* @param mat
|
||||
*/
|
||||
public static void setFlagsAs(int id, Material mat){
|
||||
BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(mat.getId()));
|
||||
setFlagsAs(id, mat.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flags of id same as already set with flags for the given material. (Uses BlockProperties.)
|
||||
* @param id
|
||||
* @param mat
|
||||
*/
|
||||
public static void setFlagsAs(int id, int otherId){
|
||||
BlockProperties.setBlockFlags(id, BlockProperties.getBlockFlags(otherId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||
import fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup;
|
||||
import fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.BlocksMC1_5;
|
||||
import fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.VanillaBlocksFactory;
|
||||
import fr.neatmonster.nocheatplus.config.RawConfigFile;
|
||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||
@ -384,24 +385,19 @@ public class BlockProperties {
|
||||
initBlocks(mcAccess, worldConfigProvider);
|
||||
// Extra hand picked setups.
|
||||
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);
|
||||
}
|
||||
new VanillaBlocksFactory().setupBlockProperties(worldConfigProvider);
|
||||
}
|
||||
catch(Throwable t){
|
||||
LogUtil.logSevere("[NoCheatPlus] Could not initialize vanilla blocks: " + t.getClass().getSimpleName() + " - " + t.getMessage());
|
||||
LogUtil.logSevere(t);
|
||||
}
|
||||
catch(Throwable t){}
|
||||
// Allow mcAccess to setup block properties.
|
||||
if (mcAccess instanceof BlockPropertiesSetup){
|
||||
try{
|
||||
((BlockPropertiesSetup) mcAccess).setupBlockProperties(worldConfigProvider);
|
||||
}
|
||||
catch(Throwable t){
|
||||
LogUtil.logSevere("[NoCheatPlus] McAccess.setupBlockProperties could not execute properly: " + t.getClass().getSimpleName());
|
||||
LogUtil.logSevere("[NoCheatPlus] McAccess.setupBlockProperties (" + mcAccess.getClass().getSimpleName() + ") could not execute properly: " + t.getClass().getSimpleName() + " - " + t.getMessage());
|
||||
LogUtil.logSevere(t);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user