Skip to content

Commit f64348e

Browse files
authored
Merge pull request #6 from Ugachaga/MC1.7.x
Added forbidden dimensions config
2 parents c2a0079 + f8fc7c7 commit f64348e

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/main/java/de/eydamos/backpack/helper/GuiHelper.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package de.eydamos.backpack.helper;
22

3-
import net.minecraft.client.Minecraft;
4-
import net.minecraft.entity.player.EntityPlayerMP;
5-
import net.minecraft.inventory.Container;
6-
import net.minecraft.inventory.IInventory;
73
import cpw.mods.fml.relauncher.Side;
84
import cpw.mods.fml.relauncher.SideOnly;
95
import de.eydamos.backpack.Backpack;
106
import de.eydamos.backpack.factory.FactoryBackpack;
117
import de.eydamos.backpack.gui.GuiBackpackRename;
8+
import de.eydamos.backpack.misc.ConfigurationBackpack;
129
import de.eydamos.backpack.network.message.MessageGuiCommand;
1310
import de.eydamos.backpack.network.message.MessageOpenBackpack;
1411
import de.eydamos.backpack.network.message.MessageOpenGui;
1512
import de.eydamos.backpack.network.message.MessageOpenPersonalSlot;
1613
import de.eydamos.backpack.network.message.MessageRenameBackpack;
1714
import de.eydamos.backpack.saves.BackpackSave;
1815
import de.eydamos.backpack.saves.PlayerSave;
16+
import net.minecraft.client.Minecraft;
17+
import net.minecraft.entity.player.EntityPlayerMP;
18+
import net.minecraft.inventory.Container;
19+
import net.minecraft.inventory.IInventory;
1920

2021
public class GuiHelper {
2122
@SideOnly(Side.CLIENT)
@@ -24,6 +25,9 @@ public static void displayRenameGui() {
2425
}
2526

2627
public static void displayBackpack(BackpackSave backpackSave, IInventory inventory, EntityPlayerMP entityPlayer) {
28+
29+
if (!isDimensionAllowed(entityPlayer)) return;
30+
2731
prepare(entityPlayer);
2832

2933
MessageOpenBackpack message = new MessageOpenBackpack(backpackSave, inventory, entityPlayer.currentWindowId);
@@ -34,6 +38,9 @@ public static void displayBackpack(BackpackSave backpackSave, IInventory invento
3438
}
3539

3640
public static void displayPersonalSlot(EntityPlayerMP entityPlayer) {
41+
42+
if (!isDimensionAllowed(entityPlayer)) return;
43+
3744
PlayerSave playerSave = new PlayerSave(entityPlayer);
3845
playerSave.setType((byte) -1);
3946

@@ -46,6 +53,14 @@ public static void displayPersonalSlot(EntityPlayerMP entityPlayer) {
4653
openContainer(container, entityPlayer);
4754
}
4855

56+
private static boolean isDimensionAllowed (EntityPlayerMP entityPlayer) {
57+
Integer currentDimID = (entityPlayer.worldObj.provider.dimensionId);
58+
for (String id : ConfigurationBackpack.FORBIDDEN_DIMENSIONS) {
59+
if (id.equals(currentDimID.toString())) return false;
60+
}
61+
return true;
62+
}
63+
4964
@SideOnly(Side.CLIENT)
5065
public static void sendOpenPersonalGui(byte gui) {
5166
MessageOpenGui message = new MessageOpenGui(gui);

src/main/java/de/eydamos/backpack/misc/ConfigurationBackpack.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class ConfigurationBackpack {
2121
public static boolean DISABLE_WORKBENCH_BACKPACKS;
2222
public static boolean BIG_BY_UPGRADE_ONLY;
2323
public static String[] DISALLOW_ITEM_IDS;
24-
public static String[] DEFAULT_ITEM_IDS = {};
24+
public static String[] FORBIDDEN_DIMENSIONS;
25+
public static String[] DEFAULT_IDS = {};
2526

2627
public static boolean NEISupport = false;
2728

@@ -62,7 +63,8 @@ public static void loadConfiguration() {
6263
DISABLE_WORKBENCH_BACKPACKS = config.get(Configuration.CATEGORY_GENERAL, "disableWorkbenchBackpack", false, getDisableWorkbenchBackpacksComment()).getBoolean(false);
6364
BIG_BY_UPGRADE_ONLY = config.get(Configuration.CATEGORY_GENERAL, "bigByUpgradeOnly", false, getBigByUpgradeOnlyComment()).getBoolean(false);
6465

65-
DISALLOW_ITEM_IDS = config.get(Configuration.CATEGORY_GENERAL, "disallowItems", DEFAULT_ITEM_IDS, getDisallowItemsComment()).getStringList();
66+
DISALLOW_ITEM_IDS = config.get(Configuration.CATEGORY_GENERAL, "disallowItems", DEFAULT_IDS, getDisallowItemsComment()).getStringList();
67+
FORBIDDEN_DIMENSIONS = config.get(Configuration.CATEGORY_GENERAL, "forbiddenDimensions", DEFAULT_IDS, getForbiddenDimensionsComment()).getStringList();
6668

6769
if(config.hasChanged()) {
6870
config.save();
@@ -116,4 +118,9 @@ private static String getBigByUpgradeOnlyComment() {
116118
private static String getDisallowItemsComment() {
117119
return "##############\n" + "Example:\n" + "disallowItems: minecraft:dirt\n\n" + "This will disallow dirt in backpacks.\n" + "##############";
118120
}
121+
122+
private static String getForbiddenDimensionsComment() {
123+
return "##############\n" + "Example:\n" + "forbiddenDimensions: 0\n\n" + "This will disallow backpacks inventory for Overworld (id = 0).\n" + "##############";
124+
}
125+
119126
}

0 commit comments

Comments
 (0)