From e9318f3a6186db13d64fc064d49d454eb45bc38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Ducho=C5=88?= Date: Wed, 21 Jun 2017 00:04:12 +0200 Subject: [PATCH] Native axe recognition --- .../common/config/ConfigurationHandler.java | 101 +++++++++++++++++- .../java/treechopper/proxy/CommonProxy.java | 25 +++-- 2 files changed, 118 insertions(+), 8 deletions(-) diff --git a/src/main/java/treechopper/common/config/ConfigurationHandler.java b/src/main/java/treechopper/common/config/ConfigurationHandler.java index f569ce8..180fff2 100644 --- a/src/main/java/treechopper/common/config/ConfigurationHandler.java +++ b/src/main/java/treechopper/common/config/ConfigurationHandler.java @@ -18,6 +18,7 @@ public class ConfigurationHandler { public static boolean plantSapling; public static List axeTypes = new ArrayList<>(); + public static List blockWhiteList = new ArrayList<>(); public static void init(File configFile) { if (config == null) { @@ -32,10 +33,106 @@ private static void loadConfiguration() { reverseShift = config.getBoolean("Reverse shift", "Settings", false, "Reverse shift function - Mod works with shift pressing"); plantSapling = config.getBoolean("Plant sapling", "Settings", false, "Automatic sapling plant on tree chop"); - axeTypes = ImmutableList.copyOf(config.getStringList("Allowed axes", "Data", new String[]{ + axeTypes = ImmutableList.copyOf(config.getStringList("Whitelisted items", "Data", new String[]{ "item.hatchetWood", "item.hatchetStone", - }, "Put here allowed axes - Whitelist")); + "item.hatchetIron", + "item.hatchetGold", + "item.hatchetDiamond", + "item.mud_axe", + "item.psi:psimetalAxe", + "item.tconstruct.lumberaxe", + "item.tconstruct.mattock", + "item.tconstruct.hatchet", + "item.brain_stone_axe", + "item.stable_pulsating_brain_stone_axe", + "item.adobe_axe", + "item.ObsidianAxe", + "item.LazuliAxe", + "item.OsmiumAxe", + "item.BronzeAxe", + "item.GlowstoneAxe", + "item.SteelAxe", + "item.LapisLazuliAxe", + "item.peridotAxe", + "item.rubyAxe", + "item.sapphireAxe", + "item.bronzeAxe", + "item.mud_axe", + "ic2.chainsaw", + "item.itemcrystalaxe", + "item.itemchargedcrystalaxe", + "item.axe_copper", + "item.axe_silver", + "item.axe_lead", + "item.axe_dawnstone", + "item.axe_aluminum", + "item.axe_bronze", + "item.axe_electrum", + "item.axe_nickel", + "item.axe_tin", + "item.WoodPaxel", + "item.StonePaxel", + "item.IronPaxel", + "item.DiamondPaxel", + "item.GoldPaxel", + "item.ObsidianPaxel", + "item.LapisLazuliPaxel", + "item.OsmiumPaxel", + "item.BronzePaxel", + "item.GlowstonePaxel", + "item.SteelPaxel", + "item.ma.inferium_axe", + "item.ma.prudentium_axe", + "item.ma.prudentium_axe", + "item.ma.intermedium_axe", + "item.ma.superium_axe", + "item.ma.supremium_axe", + "item.psimetal_axe", + "item.netheraxt", + "item.stahlaxt", + "item.teufelseisenaxt", + "item.flintAxt", + "item.flint_axe", + "item.bone_axe", + "item.emerald_axe", + "item.obsidian_axe", + "item.diamond_multi", + "item.emerald_multi", + "item.golden_multi", + "item.iron_multi", + "item.obsidian_multi", + "item.stone_multi", + "item.wooden_multi", + "item.natura.ghostwood_axe", + "item.natura.bloodwood_axe", + "item.natura.darkwood_axe", + "item.natura.fusewood_axe", + "item.natura.netherquartz_axe", + "item.terraAxe", + "item.elementiumAxe", + "item.manasteelAxe", + "item.actuallyadditions.item_axe_quartz", + "item.actuallyadditions.item_axe_emerald", + "item.actuallyadditions.item_axe_obsidian", + "item.actuallyadditions.item_axe_crystal_red", + "item.actuallyadditions.item_axe_crystal_blue", + "item.actuallyadditions.item_axe_crystal_light_blue", + "item.actuallyadditions.item_axe_crystal_black", + "item.actuallyadditions.item_axe_crystal_green", + "item.actuallyadditions.item_axe_crystal_white", + "item.daxe", + "item.aaxe", + "item.coraxe", + "item.dreadiumaxe", + "item.ethaxiumaxe", + "item.crystal_axe", + "item.crystal_axe_bone", + }, "Put here allowed items(axes) - whitelist")); + + blockWhiteList = ImmutableList.copyOf(config.getStringList("Whitelisted blocks", "Data", new String[]{ + "", + }, "Put here allowed blocks(wood) - whitelist")); } catch (Exception e) { System.out.printf("Cannot load Tree Chopper config."); diff --git a/src/main/java/treechopper/proxy/CommonProxy.java b/src/main/java/treechopper/proxy/CommonProxy.java index c4e27df..d481125 100644 --- a/src/main/java/treechopper/proxy/CommonProxy.java +++ b/src/main/java/treechopper/proxy/CommonProxy.java @@ -1,6 +1,7 @@ package treechopper.proxy; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemAxe; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerEvent; @@ -85,7 +86,7 @@ public void BreakingBlock(PlayerEvent.BreakSpeed breakSpeed) { } } - System.out.println(breakSpeed.getNewSpeed()); + //System.out.println(breakSpeed.getNewSpeed()); } } @@ -111,12 +112,14 @@ public void DestroyWoodBlock(BlockEvent.BreakEvent breakEvent) { protected boolean CheckWoodenBlock(World world, BlockPos blockPos) { + if (ConfigurationHandler.blockWhiteList.contains(world.getBlockState(blockPos).getBlock().getUnlocalizedName())) { + return true; + } + if (!world.getBlockState(blockPos).getBlock().isWood(world, blockPos)) { return false; } - // TODO Whitelist / Blacklist - return true; } @@ -126,11 +129,21 @@ protected boolean CheckItemInHand(EntityPlayer entityPlayer) { return false; } - if (!ConfigurationHandler.axeTypes.contains(entityPlayer.getHeldItemMainhand().getItem().getUnlocalizedName())) { - return false; + if (ConfigurationHandler.axeTypes.contains(entityPlayer.getHeldItemMainhand().getItem().getUnlocalizedName())) { + return true; } - return true; + boolean test; + + try { + ItemAxe tmp = (ItemAxe) entityPlayer.getHeldItemMainhand().getItem(); + test = true; + } catch (Exception e) { + System.out.println("It is not an axe"); + test = false; + } + + return test; } protected static Map m_PlayerData = new HashMap<>();