Skip to content

Commit

Permalink
Allow hiding of Traveller's Gear accessories (gloves and belt) throug…
Browse files Browse the repository at this point in the history
…h config option and Translucency enchant (#125)

* Add configuration option to hide Traveller's gear accessories from displaying on player model

* Make Translucency I and II enchantments from WG work properly with traveler's accessories (must enchant from book for now)

* Update src/main/java/tconstruct/armor/ArmorProxyClient.java

Co-authored-by: Alexander Anishin <[email protected]>

* Implement suggested style changes

* spotless fix

---------

Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Alexander Anishin <[email protected]>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent 46e26a7 commit 3ffa69d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 39 deletions.
96 changes: 65 additions & 31 deletions src/main/java/tconstruct/armor/ArmorProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -259,7 +261,7 @@ public void adjustArmor(RenderPlayerEvent.SetArmorModel event) {
ArmorProxyClient.belt.isChild = event.renderer.modelBipedMain.isChild;
ArmorProxyClient.belt.isSneak = event.renderer.modelBipedMain.isSneak;

renderArmorExtras(event);
if (PHConstruct.showTravellerAccessories) renderArmorExtras(event);

break;
case 3:
Expand All @@ -271,6 +273,32 @@ public void adjustArmor(RenderPlayerEvent.SetArmorModel event) {
}
}

// --- WitchingGadgets Translucent II enchant support
private static int translucentID = -6;

public static int getTranslucentID() {
if (translucentID == -6) setTranslucentID();
return translucentID;
}

private static void setTranslucentID() {
for (Enchantment ench : Enchantment.enchantmentsList) {
if (ench != null && ench.getName().equals("enchantment.wg.invisibleGear")) {
translucentID = ench.effectId;
return;
}
}
translucentID = -1;
}

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

// ---

void renderArmorExtras(RenderPlayerEvent.SetArmorModel event) {

EntityPlayer player = event.entityPlayer;
Expand Down Expand Up @@ -313,40 +341,46 @@ void renderArmorExtras(RenderPlayerEvent.SetArmorModel event) {
// TPlayerStats stats = TPlayerStats.get(player);
ArmorExtended armor = ArmorProxyClient.armorExtended; // TODO: Do this for every player, not just the client
if (armor != null && armor.inventory[1] != null) {
Item item = armor.inventory[1].getItem();
ModelBiped model = item.getArmorModel(player, armor.inventory[1], 4);

if (item instanceof IAccessoryModel) {
this.mc.getTextureManager()
.bindTexture(((IAccessoryModel) item).getWearbleTexture(player, armor.inventory[1], 1));
model.setLivingAnimations(player, limbSwingMod, limbSwing, partialTick);
model.render(
player,
limbSwingMod,
limbSwing,
pitch,
yawRotation - yawOffset,
bodyRotation,
zeropointsixtwofive);
if (getTranslucencyLevel(armor.inventory[1]) != 2
&& !(player.isInvisible() && getTranslucencyLevel(armor.inventory[1]) > 0)) {
Item item = armor.inventory[1].getItem();
ModelBiped model = item.getArmorModel(player, armor.inventory[1], 4);

if (item instanceof IAccessoryModel) {
this.mc.getTextureManager()
.bindTexture(((IAccessoryModel) item).getWearbleTexture(player, armor.inventory[1], 1));
model.setLivingAnimations(player, limbSwingMod, limbSwing, partialTick);
model.render(
player,
limbSwingMod,
limbSwing,
pitch,
yawRotation - yawOffset,
bodyRotation,
zeropointsixtwofive);
}
}
}

if (armor != null && armor.inventory[3] != null) {
Item item = armor.inventory[3].getItem();
ModelBiped model = item.getArmorModel(player, armor.inventory[3], 5);

if (item instanceof IAccessoryModel) {
this.mc.getTextureManager()
.bindTexture(((IAccessoryModel) item).getWearbleTexture(player, armor.inventory[1], 1));
model.setLivingAnimations(player, limbSwingMod, limbSwing, partialTick);
model.render(
player,
limbSwingMod,
limbSwing,
pitch,
yawRotation - yawOffset,
bodyRotation,
zeropointsixtwofive);
if (getTranslucencyLevel(armor.inventory[3]) != 2
&& !(player.isInvisible() && getTranslucencyLevel(armor.inventory[3]) > 0)) {
Item item = armor.inventory[3].getItem();
ModelBiped model = item.getArmorModel(player, armor.inventory[3], 5);

if (item instanceof IAccessoryModel) {
this.mc.getTextureManager()
.bindTexture(((IAccessoryModel) item).getWearbleTexture(player, armor.inventory[1], 1));
model.setLivingAnimations(player, limbSwingMod, limbSwing, partialTick);
model.render(
player,
limbSwingMod,
limbSwing,
pitch,
yawRotation - yawOffset,
bodyRotation,
zeropointsixtwofive);
}
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/tconstruct/armor/player/ArmorExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.UUID;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
Expand Down Expand Up @@ -218,14 +219,8 @@ private static void setSoulBoundID() {

public static boolean isSoulBounded(ItemStack stack) {
int soulBound = getSoulBoundID();
NBTTagList stackEnch = stack.getEnchantmentTagList();
if (soulBound >= 0 && stackEnch != null) {
for (int i = 0; i < stackEnch.tagCount(); i++) {
int id = stackEnch.getCompoundTagAt(i).getInteger("id");
if (id == soulBound) return true;
}
}
return false;
if (soulBound > 0) return EnchantmentHelper.getEnchantmentLevel(soulBound, stack) > 0;
else return false;
}

// ---
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tconstruct/util/config/PHConstruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ public static void initProps(File location) {
conTexMode.comment = "0 = disabled, 1 = enabled, 2 = enabled + ignore stained glass meta";
connectedTexturesMode = conTexMode.getInt(2);

showTravellerAccessories = config.get("Looks", "Show Traveller Gear Accessories", true).getBoolean(true);

// dimension blacklist
cfgForbiddenDim = config
.get(
Expand Down Expand Up @@ -482,6 +484,7 @@ public static void initProps(File location) {

// Looks
public static int connectedTexturesMode;
public static boolean showTravellerAccessories;

// dimensionblacklist
public static boolean slimeIslGenDim0Only;
Expand Down

0 comments on commit 3ffa69d

Please sign in to comment.