aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/ob
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/ob')
-rw-r--r--src/main/java/gtPlusPlus/xmod/ob/GliderHandler.java202
-rw-r--r--src/main/java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java41
-rw-r--r--src/main/java/gtPlusPlus/xmod/ob/SprinklerHandler.java89
3 files changed, 152 insertions, 180 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/ob/GliderHandler.java b/src/main/java/gtPlusPlus/xmod/ob/GliderHandler.java
index a190511b02..bb079c42c1 100644
--- a/src/main/java/gtPlusPlus/xmod/ob/GliderHandler.java
+++ b/src/main/java/gtPlusPlus/xmod/ob/GliderHandler.java
@@ -1,127 +1,119 @@
package gtPlusPlus.xmod.ob;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
+import org.apache.commons.lang3.StringUtils;
public class GliderHandler {
- private static final AutoMap<Integer> mDimensionalBlacklist = new AutoMap<Integer>();
-
- @SubscribeEvent
- public void onItemUsageEx(final PlayerInteractEvent event) {
- if (event != null && event.entityPlayer != null) {
-
- if (event.action != Action.RIGHT_CLICK_BLOCK && event.action != Action.RIGHT_CLICK_AIR) {
- Logger.WARNING("[OpenBlocks] Wrong type of PlayerInteractEvent, skipping.");
- }
- if (event.entityPlayer.worldObj.isRemote) {
- return;
- }
-
- ItemStack aItem = PlayerUtils.getItemStackInPlayersHand(event.entityPlayer);
- if (ItemUtils.checkForInvalidItems(aItem)) {
- Class aItemGliderClass = ReflectionUtils.getClass("openblocks.common.item.ItemHangGlider");
- if (aItemGliderClass.isInstance(aItem.getItem())) {
- if (!canPlayerGlideInThisDimension(event.entityPlayer)){
- event.setCanceled(true);
- PlayerUtils.messagePlayer(event.entityPlayer, "Glider is blacklisted in this dimension.");
- Logger.WARNING("[OpenBlocks] "+event.entityPlayer.getCommandSenderName()+" tried to use glider in dimension "+event.entityPlayer.getEntityWorld().provider.dimensionId+".");
- }
- else {
- Logger.WARNING("[OpenBlocks] "+event.entityPlayer.getCommandSenderName()+" used glider in dimension "+event.entityPlayer.getEntityWorld().provider.dimensionId+".");
- }
- }
- else {
- Logger.WARNING("[OpenBlocks] Item was not a glider.");
- }
- }
- else {
- Logger.WARNING("[OpenBlocks] Bad Item in player hand.");
- }
- }
- else {
- Logger.WARNING("[OpenBlocks] Bad event or player.");
- }
-
+ private static final AutoMap<Integer> mDimensionalBlacklist = new AutoMap<Integer>();
- }
+ @SubscribeEvent
+ public void onItemUsageEx(final PlayerInteractEvent event) {
+ if (event != null && event.entityPlayer != null) {
- private static final boolean canPlayerGlideInThisDimension(EntityPlayer aPlayer) {
- World aWorld = aPlayer.worldObj;
- if (aWorld == null) {
- return false;
- }
- else {
- if (aWorld.provider == null) {
- return false;
- }
- else {
- int aDimID = aWorld.provider.dimensionId;
- for (int i : mDimensionalBlacklist) {
- if (i == aDimID) {
- return false;
- }
- }
- }
- }
- return true;
- }
+ if (event.action != Action.RIGHT_CLICK_BLOCK && event.action != Action.RIGHT_CLICK_AIR) {
+ Logger.WARNING("[OpenBlocks] Wrong type of PlayerInteractEvent, skipping.");
+ }
+ if (event.entityPlayer.worldObj.isRemote) {
+ return;
+ }
- static final void populateBlacklist() {
- if (!mDimensionalBlacklist.isEmpty()) {
- return;
- }
- File aBlacklist = gtPlusPlus.core.util.data.FileUtils.getFile("config/GTplusplus/", "GliderBlacklist", "cfg");
- List<String> lines = new ArrayList<String>();
- try {
- lines = org.apache.commons.io.FileUtils.readLines(aBlacklist, "utf-8");
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (lines.isEmpty()) {
- FileWriter fw;
- try {
- String aInfoTip = "# Add one dimension ID per line. Lines with a # are comments and are ignored.";
- fw = new FileWriter(aBlacklist);
- fw.write(aInfoTip);
- fw.close();
- lines.add(aInfoTip);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (!lines.isEmpty()) {
- for (String s : lines) {
- if (s != null && !s.equals("") && !s.contains("#")) {
- s = StringUtils.remove(s, " ");
- s = StringUtils.trim(s);
- s = StringUtils.remove(s, ",");
- Integer g = Integer.decode(s);
- if (g != null) {
- mDimensionalBlacklist.add(g);
- Logger.INFO("[OpenBlocks] Added Dimension with ID '"+g+"' to Blacklist for Glider.");
- }
- }
- }
- }
- }
+ ItemStack aItem = PlayerUtils.getItemStackInPlayersHand(event.entityPlayer);
+ if (ItemUtils.checkForInvalidItems(aItem)) {
+ Class aItemGliderClass = ReflectionUtils.getClass("openblocks.common.item.ItemHangGlider");
+ if (aItemGliderClass.isInstance(aItem.getItem())) {
+ if (!canPlayerGlideInThisDimension(event.entityPlayer)) {
+ event.setCanceled(true);
+ PlayerUtils.messagePlayer(event.entityPlayer, "Glider is blacklisted in this dimension.");
+ Logger.WARNING("[OpenBlocks] " + event.entityPlayer.getCommandSenderName()
+ + " tried to use glider in dimension "
+ + event.entityPlayer.getEntityWorld().provider.dimensionId + ".");
+ } else {
+ Logger.WARNING("[OpenBlocks] " + event.entityPlayer.getCommandSenderName()
+ + " used glider in dimension "
+ + event.entityPlayer.getEntityWorld().provider.dimensionId + ".");
+ }
+ } else {
+ Logger.WARNING("[OpenBlocks] Item was not a glider.");
+ }
+ } else {
+ Logger.WARNING("[OpenBlocks] Bad Item in player hand.");
+ }
+ } else {
+ Logger.WARNING("[OpenBlocks] Bad event or player.");
+ }
+ }
+ private static final boolean canPlayerGlideInThisDimension(EntityPlayer aPlayer) {
+ World aWorld = aPlayer.worldObj;
+ if (aWorld == null) {
+ return false;
+ } else {
+ if (aWorld.provider == null) {
+ return false;
+ } else {
+ int aDimID = aWorld.provider.dimensionId;
+ for (int i : mDimensionalBlacklist) {
+ if (i == aDimID) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+ static final void populateBlacklist() {
+ if (!mDimensionalBlacklist.isEmpty()) {
+ return;
+ }
+ File aBlacklist = gtPlusPlus.core.util.data.FileUtils.getFile("config/GTplusplus/", "GliderBlacklist", "cfg");
+ List<String> lines = new ArrayList<String>();
+ try {
+ lines = org.apache.commons.io.FileUtils.readLines(aBlacklist, "utf-8");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (lines.isEmpty()) {
+ FileWriter fw;
+ try {
+ String aInfoTip = "# Add one dimension ID per line. Lines with a # are comments and are ignored.";
+ fw = new FileWriter(aBlacklist);
+ fw.write(aInfoTip);
+ fw.close();
+ lines.add(aInfoTip);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (!lines.isEmpty()) {
+ for (String s : lines) {
+ if (s != null && !s.equals("") && !s.contains("#")) {
+ s = StringUtils.remove(s, " ");
+ s = StringUtils.trim(s);
+ s = StringUtils.remove(s, ",");
+ Integer g = Integer.decode(s);
+ if (g != null) {
+ mDimensionalBlacklist.add(g);
+ Logger.INFO("[OpenBlocks] Added Dimension with ID '" + g + "' to Blacklist for Glider.");
+ }
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java b/src/main/java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java
index c1b678f5ee..065b28c7e7 100644
--- a/src/main/java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java
+++ b/src/main/java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java
@@ -1,38 +1,23 @@
package gtPlusPlus.xmod.ob;
-import static gtPlusPlus.core.creative.AddToCreativeTab.tabMisc;
-
-import gtPlusPlus.core.item.ModItems;
-import gtPlusPlus.core.item.base.BaseItemBurnable;
-import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.lib.LoadedMods;
-import gtPlusPlus.core.recipe.common.CI;
import gtPlusPlus.core.util.Utils;
-import gtPlusPlus.core.util.minecraft.FluidUtils;
-import gtPlusPlus.core.util.minecraft.ItemUtils;
-import gtPlusPlus.xmod.railcraft.utils.RailcraftUtils;
-import net.minecraft.init.Blocks;
-import net.minecraft.init.Items;
-import net.minecraft.item.ItemStack;
public class HANDLER_OpenBlocks {
- public static void preInit() {
- if (LoadedMods.OpenBlocks) {
-
- }
- }
-
- public static void init() {
- if (LoadedMods.OpenBlocks) {
- GliderHandler.populateBlacklist();
- }
- }
+ public static void preInit() {
+ if (LoadedMods.OpenBlocks) {}
+ }
- public static void postInit() {
- if (LoadedMods.OpenBlocks) {
- Utils.registerEvent(new GliderHandler());
- }
- }
+ public static void init() {
+ if (LoadedMods.OpenBlocks) {
+ GliderHandler.populateBlacklist();
+ }
+ }
+ public static void postInit() {
+ if (LoadedMods.OpenBlocks) {
+ Utils.registerEvent(new GliderHandler());
+ }
+ }
}
diff --git a/src/main/java/gtPlusPlus/xmod/ob/SprinklerHandler.java b/src/main/java/gtPlusPlus/xmod/ob/SprinklerHandler.java
index 85f8ded290..7478d51dec 100644
--- a/src/main/java/gtPlusPlus/xmod/ob/SprinklerHandler.java
+++ b/src/main/java/gtPlusPlus/xmod/ob/SprinklerHandler.java
@@ -1,12 +1,10 @@
package gtPlusPlus.xmod.ob;
-import java.util.HashMap;
-
import com.google.common.base.Objects;
-
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.util.minecraft.ItemUtils;
+import java.util.HashMap;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@@ -17,50 +15,47 @@ import net.minecraft.item.ItemStack;
*/
public class SprinklerHandler {
+ private static final HashMap<Integer, ItemStack> mValidFerts = new HashMap<Integer, ItemStack>();
+
+ /**
+ * @return - A valid {@link Map} of all Fertilizers for the OB Sprinkler.
+ */
+ public static HashMap<Integer, ItemStack> getValidFerts() {
+ return mValidFerts;
+ }
+
+ /**
+ * @param aFert - An {@link ItemStack} which is to be registered for OB Sprinklers.
+ */
+ public static void registerSprinklerFertilizer(ItemStack aFert) {
+ int aHash = Objects.hashCode(aFert.getItem(), aFert.getItemDamage());
+ if (!mValidFerts.containsKey(aHash)) {
+ Logger.INFO("Registering " + aFert.getDisplayName() + " as OB Sprinkler Fertilizer.");
+ mValidFerts.put(aHash, aFert.copy());
+ }
+ }
+
+ public static void registerModFerts() {
+ ItemStack f;
- private static final HashMap<Integer, ItemStack> mValidFerts = new HashMap<Integer, ItemStack>();
-
- /**
- * @return - A valid {@link Map} of all Fertilizers for the OB Sprinkler.
- */
- public static HashMap<Integer, ItemStack> getValidFerts() {
- return mValidFerts;
- }
-
- /**
- * @param aFert - An {@link ItemStack} which is to be registered for OB Sprinklers.
- */
- public static void registerSprinklerFertilizer(ItemStack aFert) {
- int aHash = Objects.hashCode(aFert.getItem(), aFert.getItemDamage());
- if (!mValidFerts.containsKey(aHash)) {
- Logger.INFO("Registering "+aFert.getDisplayName()+" as OB Sprinkler Fertilizer.");
- mValidFerts.put(aHash, aFert.copy());
- }
- }
-
- public static void registerModFerts() {
- ItemStack f;
+ f = new ItemStack(Items.dye, 1, 15);
+ SprinklerHandler.registerSprinklerFertilizer(f);
- f = new ItemStack(Items.dye, 1, 15);
- SprinklerHandler.registerSprinklerFertilizer(f);
-
- if (LoadedMods.Forestry) {
- f = ItemUtils.getCorrectStacktype("Forestry:fertilizerBio", 1);
- if (f != null) {
- registerSprinklerFertilizer(f);
- }
- f = ItemUtils.getCorrectStacktype("Forestry:fertilizerCompound", 1);
- if (f != null) {
- registerSprinklerFertilizer(f);
- }
- }
- if (LoadedMods.IndustrialCraft2) {
- f = ItemUtils.getCorrectStacktype("IC2:itemFertilizer", 1);
- if (f != null) {
- registerSprinklerFertilizer(f);
- }
-
- }
- }
-
+ if (LoadedMods.Forestry) {
+ f = ItemUtils.getCorrectStacktype("Forestry:fertilizerBio", 1);
+ if (f != null) {
+ registerSprinklerFertilizer(f);
+ }
+ f = ItemUtils.getCorrectStacktype("Forestry:fertilizerCompound", 1);
+ if (f != null) {
+ registerSprinklerFertilizer(f);
+ }
+ }
+ if (LoadedMods.IndustrialCraft2) {
+ f = ItemUtils.getCorrectStacktype("IC2:itemFertilizer", 1);
+ if (f != null) {
+ registerSprinklerFertilizer(f);
+ }
+ }
+ }
}