Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to hide backpack model from rendering on back and also now works with the Translucency II enchantment #23

Merged
merged 7 commits into from
Oct 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import com.darkona.adventurebackpack.config.ConfigHandler;
import com.darkona.adventurebackpack.item.IBackWearableItem;
import com.darkona.adventurebackpack.util.EnchUtils;
import com.darkona.adventurebackpack.util.Wearing;

public class RendererWearableEquipped extends RendererLivingEntity {
Expand All @@ -37,6 +39,12 @@ public void render(Entity entity, double x, double y, double z, float rotX, floa
if (wearable == null) {
return;
}
if (!ConfigHandler.enableBackRendering) {
return;
}
if (EnchUtils.isTranslucent(wearable)) {
return;
}
GL11.glPushAttrib(GL11.GL_TRANSFORM_BIT);
ItemStack wearableCopy = wearable.copy();
IBackWearableItem wearableItem = (IBackWearableItem) wearableCopy.getItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ConfigHandler {
public static Configuration config;

public static boolean allowSoulBound = true;
public static boolean allowTranslucency = true;
public static boolean backpackDeathPlace = true;
public static boolean backpackAbilities = true;
public static boolean enableCampfireSpawn = false;
Expand All @@ -23,6 +24,7 @@ public class ConfigHandler {
public static boolean portableSleepingBag = true;
public static boolean tinkerToolsMaintenance = true;

public static boolean enableBackRendering = true;
public static boolean enableFullnessBar = false;
public static boolean enableTemperatureBar = false;
public static boolean enableToolsRender = true;
Expand Down Expand Up @@ -99,6 +101,8 @@ private static void loadConfiguration() {
// Gameplay
allowSoulBound = config
.getBoolean("Allow SoulBound", "gameplay", true, "Allow SoulBound enchant on wearable packs");
allowTranslucency = config
.getBoolean("Allow Translucency", "gameplay", true, "Allow Translucency enchant on wearable packs");
backpackAbilities = config.getBoolean(
"Backpack Abilities",
"gameplay",
Expand Down Expand Up @@ -128,6 +132,11 @@ private static void loadConfiguration() {
"Allows to maintenance (repair/upgarde) Tinkers Construct tools in backpacks as if it's Crafting Station");

// Graphics
enableBackRendering = config.getBoolean(
"Show Backpack on Back",
"graphics",
true,
"Whether or not to render the backpack when wearing it.");
typeTankRender = config.getInt(
"Tank Render Type",
"graphics",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public ItemAdventure() {
super();
setFull3D();
setMaxStackSize(1);
setMaxDamage(1000);
Kortako marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean isDamageable() {
return false;
}
/*
* @Override public boolean isDamageable() { return false; }
*/

@Override
public int getItemEnchantability() {
Expand All @@ -36,6 +36,7 @@ public boolean onDroppedByPlayer(ItemStack stack, EntityPlayer player) {

@Override
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
return EnchUtils.isSoulBook(book);
return EnchUtils.isSoulBook(book) || EnchUtils.isTranslucencyBook(book);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class LoadedMods {
public static final boolean THAUMCRAFT = registerMod("Thaumcraft");
public static final boolean WAILA = registerMod("waila");
public static final boolean HUNGEROVERHAUL = registerMod("HungerOverhaul");
public static final boolean WITCHINGGADGETS = registerMod("WitchingGadgets");

private LoadedMods() {}

Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/darkona/adventurebackpack/util/EnchUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public final class EnchUtils {
// -1 - enchantment not found
private static final int SOUL_BOUND_ID = setSoulBoundID();

private static final int TRANSLUCENCY_ID = setTranslucencyID();

private EnchUtils() {}

private static int setSoulBoundID() {
Expand All @@ -29,6 +31,17 @@ private static int setSoulBoundID() {
return -1;
}

private static int setTranslucencyID() {
if (!ConfigHandler.allowTranslucency) return -3;

if (!LoadedMods.WITCHINGGADGETS) return -2;

for (Enchantment ench : Enchantment.enchantmentsList)
if (ench != null && ench.getName().equals("enchantment.wg.invisibleGear")) return ench.effectId;

return -1;
}

public static boolean isSoulBounded(ItemStack stack) {
NBTTagList stackEnch = stack.getEnchantmentTagList();
if (SOUL_BOUND_ID >= 0 && stackEnch != null) {
Expand All @@ -40,6 +53,18 @@ public static boolean isSoulBounded(ItemStack stack) {
return false;
}

public static boolean isTranslucent(ItemStack stack) {
NBTTagList stackEnch = stack.getEnchantmentTagList();
if (TRANSLUCENCY_ID >= 0 && stackEnch != null) {
for (int i = 0; i < stackEnch.tagCount(); i++) {
int id = stackEnch.getCompoundTagAt(i).getInteger("id");
int lvl = stackEnch.getCompoundTagAt(i).getInteger("lvl");
if (id == TRANSLUCENCY_ID && lvl == 2) return true;
}
}
Kortako marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

public static boolean isSoulBook(ItemStack book) {
if (SOUL_BOUND_ID >= 0 && book.hasTagCompound()) {
NBTTagCompound bookData = book.stackTagCompound;
Expand All @@ -54,4 +79,19 @@ public static boolean isSoulBook(ItemStack book) {
}
return false;
}

public static boolean isTranslucencyBook(ItemStack book) {
if (TRANSLUCENCY_ID >= 0 && book.hasTagCompound()) {
NBTTagCompound bookData = book.stackTagCompound;
if (bookData.hasKey("StoredEnchantments")) {
NBTTagList bookEnch = bookData.getTagList("StoredEnchantments", NBT.TAG_COMPOUND);
if (!bookEnch.getCompoundTagAt(1).getBoolean("id")) // only pure book allowed
{
int id = bookEnch.getCompoundTagAt(0).getInteger("id");
return id == TRANSLUCENCY_ID;
}
}
}
return false;
}
}