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.getTranslucencyLevel(wearable) == 2) {
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 @@ -21,6 +21,11 @@ public boolean isDamageable() {
return false;
}

@Override
public boolean isItemTool(ItemStack stack) {
return true;
}

@Override
public int getItemEnchantability() {
return 0;
Expand All @@ -36,6 +41,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
50 changes: 30 additions & 20 deletions src/main/java/com/darkona/adventurebackpack/util/EnchUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.darkona.adventurebackpack.util;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;

import com.darkona.adventurebackpack.config.ConfigHandler;
import com.darkona.adventurebackpack.reference.LoadedMods;
Expand All @@ -16,6 +14,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,28 +29,38 @@ 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) {
for (int i = 0; i < stackEnch.tagCount(); i++) {
int id = stackEnch.getCompoundTagAt(i).getInteger("id");
if (id == SOUL_BOUND_ID) return true;
}
if (SOUL_BOUND_ID > 0) return EnchantmentHelper.getEnchantmentLevel(SOUL_BOUND_ID, stack) > 0;
else return false;

}

public static int getTranslucencyLevel(ItemStack stack) {
if (TRANSLUCENCY_ID > 0) return EnchantmentHelper.getEnchantmentLevel(TRANSLUCENCY_ID, stack);
else return 0;
}

public static boolean isSoulBook(ItemStack book) {
if (EnchantmentHelper.getEnchantments(book).size() == 1) { // only pure soulbook allowed
return EnchantmentHelper.getEnchantments(book).get(SOUL_BOUND_ID) != null;
}
return false;
}

public static boolean isSoulBook(ItemStack book) {
if (SOUL_BOUND_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 soulbook allowed
{
int id = bookEnch.getCompoundTagAt(0).getInteger("id");
return id == SOUL_BOUND_ID;
}
}
public static boolean isTranslucencyBook(ItemStack book) {
if (EnchantmentHelper.getEnchantments(book).size() == 1) {
return EnchantmentHelper.getEnchantments(book).get(TRANSLUCENCY_ID) != null;
}
return false;
}
Expand Down