Skip to content

Commit c21adfa

Browse files
authored
Support Witchery's Sticky Items potion (#38)
1 parent 69a1aa9 commit c21adfa

7 files changed

Lines changed: 39 additions & 14 deletions

File tree

src/main/java/com/darkona/adventurebackpack/client/render/RendererWearableEquipped.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import com.darkona.adventurebackpack.config.ConfigHandler;
1717
import com.darkona.adventurebackpack.item.IBackWearableItem;
18-
import com.darkona.adventurebackpack.util.EnchUtils;
18+
import com.darkona.adventurebackpack.util.PotionAndEnchantUtils;
1919
import com.darkona.adventurebackpack.util.Wearing;
2020

2121
public class RendererWearableEquipped extends RendererLivingEntity {
@@ -42,7 +42,7 @@ public void render(Entity entity, double x, double y, double z, float rotX, floa
4242
if (!ConfigHandler.enableBackRendering) {
4343
return;
4444
}
45-
if (EnchUtils.getTranslucencyLevel(wearable) == 2) {
45+
if (PotionAndEnchantUtils.getTranslucencyLevel(wearable) == 2) {
4646
return;
4747
}
4848
GL11.glPushAttrib(GL11.GL_TRANSFORM_BIT);

src/main/java/com/darkona/adventurebackpack/config/ConfigHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ConfigHandler {
1515

1616
public static boolean allowSoulBound = true;
1717
public static boolean allowTranslucency = true;
18+
public static boolean allowStickyItems = true;
1819
public static boolean backpackDeathPlace = true;
1920
public static boolean backpackAbilities = true;
2021
public static boolean enableCampfireSpawn = false;
@@ -104,6 +105,11 @@ private static void loadConfiguration() {
104105
.getBoolean("Allow SoulBound", "gameplay", true, "Allow SoulBound enchant on wearable packs");
105106
allowTranslucency = config
106107
.getBoolean("Allow Translucency", "gameplay", true, "Allow Translucency enchant on wearable packs");
108+
allowStickyItems = config.getBoolean(
109+
"Allow Sticky Items",
110+
"gameplay",
111+
true,
112+
"Allow Sticky Items potion effect on wearable packs");
107113
backpackAbilities = config.getBoolean(
108114
"Backpack Abilities",
109115
"gameplay",

src/main/java/com/darkona/adventurebackpack/handlers/PlayerEventHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import com.darkona.adventurebackpack.playerProperties.BackpackProperty;
3636
import com.darkona.adventurebackpack.proxy.ServerProxy;
3737
import com.darkona.adventurebackpack.reference.BackpackTypes;
38-
import com.darkona.adventurebackpack.util.EnchUtils;
3938
import com.darkona.adventurebackpack.util.LogHelper;
39+
import com.darkona.adventurebackpack.util.PotionAndEnchantUtils;
4040
import com.darkona.adventurebackpack.util.Wearing;
4141

4242
import cpw.mods.fml.common.eventhandler.Event;
@@ -170,7 +170,8 @@ public void playerDies(LivingDeathEvent event) {
170170
player.worldObj.createExplosion(player, player.posX, player.posY, player.posZ, 4.0F, false);
171171
}
172172

173-
if (player.getEntityWorld().getGameRules().getGameRuleBooleanValue("keepInventory")) {
173+
if (player.getEntityWorld().getGameRules().getGameRuleBooleanValue("keepInventory")
174+
|| PotionAndEnchantUtils.hasStickyItems(player)) {
174175
((IBackWearableItem) props.getWearable().getItem())
175176
.onPlayerDeath(player.worldObj, player, props.getWearable());
176177
ServerProxy.storePlayerProps(player);
@@ -189,7 +190,7 @@ public void playerDeathDrop(PlayerDropsEvent event) {
189190
ItemStack pack = Wearing.getWearingWearable(player);
190191
BackpackProperty props = BackpackProperty.get(player);
191192

192-
if (EnchUtils.isSoulBounded(pack)
193+
if (PotionAndEnchantUtils.isSoulBounded(pack)
193194
|| (ConfigHandler.backpackDeathPlace && pack.getItem() instanceof ItemAdventureBackpack)) {
194195
((IBackWearableItem) props.getWearable().getItem())
195196
.onPlayerDeath(player.worldObj, player, props.getWearable());

src/main/java/com/darkona/adventurebackpack/item/ItemAdventure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import net.minecraft.item.ItemStack;
66

77
import com.darkona.adventurebackpack.inventory.ContainerAdventure;
8-
import com.darkona.adventurebackpack.util.EnchUtils;
8+
import com.darkona.adventurebackpack.util.PotionAndEnchantUtils;
99

1010
@SuppressWarnings("WeakerAccess")
1111
public abstract class ItemAdventure extends ItemAB implements IBackWearableItem {
@@ -41,7 +41,7 @@ public boolean onDroppedByPlayer(ItemStack stack, EntityPlayer player) {
4141

4242
@Override
4343
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
44-
return EnchUtils.isSoulBook(book) || EnchUtils.isTranslucencyBook(book);
44+
return PotionAndEnchantUtils.isSoulBook(book) || PotionAndEnchantUtils.isTranslucencyBook(book);
4545

4646
}
4747
}

src/main/java/com/darkona/adventurebackpack/item/ItemAdventureBackpack.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import com.darkona.adventurebackpack.reference.BackpackTypes;
4343
import com.darkona.adventurebackpack.util.BackpackUtils;
4444
import com.darkona.adventurebackpack.util.CoordsUtils;
45-
import com.darkona.adventurebackpack.util.EnchUtils;
45+
import com.darkona.adventurebackpack.util.PotionAndEnchantUtils;
4646
import com.darkona.adventurebackpack.util.Resources;
4747
import com.darkona.adventurebackpack.util.TipUtils;
4848
import com.darkona.adventurebackpack.util.Utils;
@@ -135,7 +135,8 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla
135135
@Override
136136
public void onPlayerDeath(World world, EntityPlayer player, ItemStack stack) {
137137
if (world.isRemote || !ConfigHandler.backpackDeathPlace
138-
|| EnchUtils.isSoulBounded(stack)
138+
|| PotionAndEnchantUtils.isSoulBounded(stack)
139+
|| PotionAndEnchantUtils.hasStickyItems(player)
139140
|| player.getEntityWorld().getGameRules().getGameRuleBooleanValue("keepInventory")) {
140141
return;
141142
}

src/main/java/com/darkona/adventurebackpack/reference/LoadedMods.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class LoadedMods {
1919
public static final boolean THAUMCRAFT = registerMod("Thaumcraft");
2020
public static final boolean WAILA = registerMod("waila");
2121
public static final boolean HUNGEROVERHAUL = registerMod("HungerOverhaul");
22+
public static final boolean WITCHERY = registerMod("witchery");
2223
public static final boolean WITCHINGGADGETS = registerMod("WitchingGadgets");
2324

2425
private LoadedMods() {}

src/main/java/com/darkona/adventurebackpack/util/EnchUtils.java renamed to src/main/java/com/darkona/adventurebackpack/util/PotionAndEnchantUtils.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
import net.minecraft.enchantment.Enchantment;
44
import net.minecraft.enchantment.EnchantmentHelper;
5+
import net.minecraft.entity.player.EntityPlayer;
56
import net.minecraft.item.ItemStack;
7+
import net.minecraft.potion.Potion;
68

79
import com.darkona.adventurebackpack.config.ConfigHandler;
810
import com.darkona.adventurebackpack.reference.LoadedMods;
911

10-
public final class EnchUtils {
12+
public final class PotionAndEnchantUtils {
1113

1214
// -3 - disabled by config
13-
// -2 - EnderIO not found
15+
// -2 - mod not found
1416
// -1 - enchantment not found
1517
private static final int SOUL_BOUND_ID = setSoulBoundID();
16-
1718
private static final int TRANSLUCENCY_ID = setTranslucencyID();
19+
private static final int STICKY_ITEMS_ID = setStickyItemsID();
1820

19-
private EnchUtils() {}
21+
private PotionAndEnchantUtils() {}
2022

2123
private static int setSoulBoundID() {
2224
if (!ConfigHandler.allowSoulBound) return -3;
@@ -40,10 +42,20 @@ private static int setTranslucencyID() {
4042
return -1;
4143
}
4244

45+
private static int setStickyItemsID() {
46+
if (!ConfigHandler.allowStickyItems) return -3;
47+
48+
if (!LoadedMods.WITCHERY) return -2;
49+
50+
for (Potion potion : Potion.potionTypes)
51+
if (potion != null && potion.getName().equals("witchery:potion.keepinventory")) return potion.getId();
52+
53+
return -1;
54+
}
55+
4356
public static boolean isSoulBounded(ItemStack stack) {
4457
if (SOUL_BOUND_ID > 0) return EnchantmentHelper.getEnchantmentLevel(SOUL_BOUND_ID, stack) > 0;
4558
else return false;
46-
4759
}
4860

4961
public static int getTranslucencyLevel(ItemStack stack) {
@@ -64,4 +76,8 @@ public static boolean isTranslucencyBook(ItemStack book) {
6476
}
6577
return false;
6678
}
79+
80+
public static boolean hasStickyItems(EntityPlayer player) {
81+
return (STICKY_ITEMS_ID > 0) && player.isPotionActive(STICKY_ITEMS_ID);
82+
}
6783
}

0 commit comments

Comments
 (0)