Skip to content

Commit

Permalink
Native axe recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Duchoň committed Jun 20, 2017
1 parent c5204e0 commit e9318f3
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 8 deletions.
101 changes: 99 additions & 2 deletions src/main/java/treechopper/common/config/ConfigurationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ConfigurationHandler {
public static boolean plantSapling;

public static List<String> axeTypes = new ArrayList<>();
public static List<String> blockWhiteList = new ArrayList<>();

public static void init(File configFile) {
if (config == null) {
Expand All @@ -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.");
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/treechopper/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void BreakingBlock(PlayerEvent.BreakSpeed breakSpeed) {
}
}

System.out.println(breakSpeed.getNewSpeed());
//System.out.println(breakSpeed.getNewSpeed());
}
}

Expand All @@ -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;
}

Expand All @@ -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<UUID, PlayerInteract> m_PlayerData = new HashMap<>();
Expand Down

0 comments on commit e9318f3

Please sign in to comment.