From e33bcf8499e4a6a03868875dac34691e4d7b825d Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Tue, 16 Sep 2014 17:54:48 +0800 Subject: [PATCH] Added block black list for teleporting using staff / travel upgrade --- ReleaseNotes.txt | 1 + .../crazypants/enderio/config/Config.java | 13 ++++++++---- .../enderio/teleport/TravelController.java | 20 ++++++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index d95b5df7..6b0e29a6 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -31,6 +31,7 @@ Config - Added config option for painter power use - Added config option to disable tinker's XP bushes in farming station - Added black list for Soul Vial and Powered Spawners +- Added block black list for teleporting using staff / travel upgrade Bugs - Farm 'error messages' flickering on and off diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 7e64aa9c..49229601 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -121,6 +121,9 @@ public final class Config { public static boolean travelStaffBlinkEnabled = true; public static boolean travelStaffBlinkThroughSolidBlocksEnabled = true; public static boolean travelStaffBlinkThroughClearBlocksEnabled = true; + public static String[] travelStaffBlinkBlackList = new String[] { + "minecraft:bedrock" + }; public static int enderIoRange = 8; public static boolean enderIoMeAccessEnabled = true; @@ -316,7 +319,7 @@ public final class Config { public static int spawnGuardPowerPerTickLevelTwo = 300; public static int spawnGuardRangeLevelThree = 128; public static int spawnGuardPowerPerTickLevelThree = 1000; - + public static void load(FMLPreInitializationEvent event) { FMLCommonHandler.instance().bus().register(new Config()); @@ -507,11 +510,11 @@ public final class Config { travelStaffBlinkPauseTicks = config.get(sectionStaff.name, "travelStaffBlinkPauseTicks", travelStaffBlinkPauseTicks, "Minimum number of ticks between 'blinks'. Values of 10 or less allow a limited sort of flight.").getInt(travelStaffBlinkPauseTicks); - travelStaffEnabled = config.get(sectionItems.name, "travelStaffEnabled", travelAnchorEnabled, + travelStaffEnabled = config.get(sectionStaff.name, "travelStaffEnabled", travelAnchorEnabled, "If set to false: the travel staff will not be craftable.").getBoolean(travelStaffEnabled); - travelStaffBlinkEnabled = config.get(sectionItems.name, "travelStaffBlinkEnabled", travelStaffBlinkEnabled, + travelStaffBlinkEnabled = config.get(sectionStaff.name, "travelStaffBlinkEnabled", travelStaffBlinkEnabled, "If set to false: the travel staff can not be used to shift-right click teleport, or blink.").getBoolean(travelStaffBlinkEnabled); - travelStaffBlinkThroughSolidBlocksEnabled = config.get(sectionItems.name, "travelStaffBlinkThroughSolidBlocksEnabled", + travelStaffBlinkThroughSolidBlocksEnabled = config.get(sectionStaff.name, "travelStaffBlinkThroughSolidBlocksEnabled", travelStaffBlinkThroughSolidBlocksEnabled, "If set to false: the travel staff can be used to blink through any block.").getBoolean(travelStaffBlinkThroughSolidBlocksEnabled); travelStaffBlinkThroughClearBlocksEnabled = config @@ -520,6 +523,8 @@ public final class Config { "staff can only be used to blink through transparent or partial blocks (e.g. torches). " + "If both are false: only air blocks may be teleported through.") .getBoolean(travelStaffBlinkThroughClearBlocksEnabled); + travelStaffBlinkBlackList = config.getStringList("travelStaffBlinkBlackList", sectionStaff.name, travelStaffBlinkBlackList, + "Lists the blocks that cannot be teleported through in the form 'modID:blockName'"); enderIoRange = config.get(sectionEfficiency.name, "enderIoRange", enderIoRange, "Range accessable (in blocks) when using the Ender IO.").getInt(enderIoRange); diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java index 93ec6ece..328e38c5 100644 --- a/src/main/java/crazypants/enderio/teleport/TravelController.java +++ b/src/main/java/crazypants/enderio/teleport/TravelController.java @@ -1,5 +1,6 @@ package crazypants.enderio.teleport; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; @@ -22,6 +23,8 @@ import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import crazypants.enderio.EnderIO; @@ -66,8 +69,14 @@ public class TravelController { private double tanFovRad; private Minecraft mc = Minecraft.getMinecraft(); + + private final List blackList = new ArrayList(); private TravelController() { + String[] blackListNames = Config.travelStaffBlinkBlackList; + for(String name : blackListNames) { + blackList.add(new UniqueIdentifier(name)); + } } public boolean activateTravelAccessable(ItemStack equipped, World world, EntityPlayer player, TravelSource source) { @@ -129,7 +138,7 @@ public class TravelController { for (MovingObjectPosition pos : res) { if(pos != null) { Block hitBlock = player.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); - if(hitBlock.getBlockHardness(player.worldObj, pos.blockX, pos.blockY, pos.blockZ) < 0) { + if(isBlackListedBlock(player, pos, hitBlock)) { maxDistance = Math.min(maxDistance, VecmathUtil.distance(eye, new Vector3d(pos.blockX + 0.5, pos.blockY + 0.5, pos.blockZ + 0.5)) - 1.5 - lookComp); } } @@ -173,6 +182,15 @@ public class TravelController { return false; } + private boolean isBlackListedBlock(EntityPlayer player, MovingObjectPosition pos, Block hitBlock) { + UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(hitBlock); + if(ui == null) { + return false; + } + //hitBlock.getBlockHardness(player.worldObj, pos.blockX, pos.blockY, pos.blockZ) < 0; + return blackList.contains(ui); + } + private boolean doBlinkAround(EntityPlayer player, Vector3d sample) { if(doBlink(player, new BlockCoord((int) Math.round(sample.x), (int) Math.round(sample.y) - 1, (int) Math.round(sample.z)))) { return true;