Skip to content

Commit

Permalink
Prevented normally worn armor pieces from rendering if they are not c…
Browse files Browse the repository at this point in the history
…hiseled and with blocks/items to render, and added a config to change those conditions. #23
  • Loading branch information
Phylogeny committed Jul 28, 2018
1 parent 7e49bb3 commit 7477e65
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 74 deletions.
Expand Up @@ -11,7 +11,6 @@
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor.ArmorType;
import com.phylogeny.extrabitmanipulation.packet.PacketSyncArmorSlot;
import com.phylogeny.extrabitmanipulation.reference.NBTKeys;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void setSize(int size)
public static boolean isItemValid(int slot, ItemStack stack)
{
return ItemStackHelper.isChiseledArmorStack(stack) && ((ItemChiseledArmor) stack.getItem()).armorType.ordinal() == slot
&& ItemStackHelper.getArmorData(ItemStackHelper.getNBTOrNew(stack)).getBoolean(NBTKeys.ARMOR_NOT_EMPTY);
&& ItemStackHelper.isChiseledArmorNotEmpty(stack);
}

@Override
Expand Down
@@ -1,47 +1,10 @@
package com.phylogeny.extrabitmanipulation.client;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import mod.chiselsandbits.api.APIExceptions.CannotBeChiseled;
import mod.chiselsandbits.api.IBitAccess;
import mod.chiselsandbits.api.IBitBrush;
import mod.chiselsandbits.api.IBitLocation;
import mod.chiselsandbits.api.IChiselAndBitsAPI;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.api.ModKeyBinding;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumFacing.AxisDirection;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.Cylinder;
import org.lwjgl.util.glu.Disk;
Expand All @@ -52,6 +15,8 @@
import com.google.common.base.Stopwatch;
import com.phylogeny.extrabitmanipulation.ExtraBitManipulation;
import com.phylogeny.extrabitmanipulation.api.ChiselsAndBitsAPIAccess;
import com.phylogeny.extrabitmanipulation.armor.capability.ChiseledArmorSlotsHandler;
import com.phylogeny.extrabitmanipulation.armor.capability.IChiseledArmorSlotsHandler;
import com.phylogeny.extrabitmanipulation.client.gui.GuiBitToolSettingsMenu;
import com.phylogeny.extrabitmanipulation.config.ConfigShapeRender;
import com.phylogeny.extrabitmanipulation.config.ConfigShapeRenderPair;
Expand All @@ -64,6 +29,7 @@
import com.phylogeny.extrabitmanipulation.helper.BitToolSettingsHelper.SculptingData;
import com.phylogeny.extrabitmanipulation.helper.ItemStackHelper;
import com.phylogeny.extrabitmanipulation.init.KeyBindingsExtraBitManipulation;
import com.phylogeny.extrabitmanipulation.init.ModelRegistration.ArmorModelRenderWithVanityMode;
import com.phylogeny.extrabitmanipulation.init.RenderLayersExtraBitManipulation;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor;
import com.phylogeny.extrabitmanipulation.item.ItemModelingTool;
Expand All @@ -82,6 +48,48 @@
import com.phylogeny.extrabitmanipulation.reference.Reference;
import com.phylogeny.extrabitmanipulation.reference.Utility;

import mod.chiselsandbits.api.APIExceptions.CannotBeChiseled;
import mod.chiselsandbits.api.IBitAccess;
import mod.chiselsandbits.api.IBitBrush;
import mod.chiselsandbits.api.IBitLocation;
import mod.chiselsandbits.api.IChiselAndBitsAPI;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.api.ModKeyBinding;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumFacing.AxisDirection;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;

public class ClientEventHandler
{
private float millisecondsElapsed;
Expand All @@ -102,6 +110,7 @@ public class ClientEventHandler
private static final int[] SHAPE_FLAT = new int[]{3, 3, 3, 6, 3, 3, 3};
private boolean keyThrowBitIsDown;
private static double BOUNDING_BOX_OFFSET = 0.0020000000949949026D;
private static Map<UUID, ItemStack[]> invisibleArmorMap = new HashMap<>();

@SubscribeEvent
public void registerTextures(@SuppressWarnings("unused") TextureStitchEvent.Pre event)
Expand Down Expand Up @@ -133,6 +142,70 @@ public void run()
});
}

@SubscribeEvent
public void preventArmorRendering(RenderPlayerEvent.Pre event)
{
if (Configs.armorModelRenderWithVanityMode == ArmorModelRenderWithVanityMode.ALWAYS)
return;

EntityPlayer player = event.getEntityPlayer();
IChiseledArmorSlotsHandler cap = ChiseledArmorSlotsHandler.getCapability(player);
if (cap == null)
return;

ItemStack[] armor = new ItemStack[4];
NonNullList<ItemStack> armorInventory = player.inventory.armorInventory;
boolean found = false;
for (int i = 0; i < 4; i++)
{
ItemStack stack = armorInventory.get(i);
ItemStack stackVanity = cap.getStackInSlot(3 - i);
if (!stackVanity.isEmpty() && !stack.isEmpty())
{
boolean hide;
switch (Configs.armorModelRenderWithVanityMode)
{
case IF_CHISELED: hide = !ItemStackHelper.isChiseledArmorStack(stack);
break;
case IF_CHISELED_NOT_EMPTY: hide = !ItemStackHelper.isChiseledArmorStack(stack) || !ItemStackHelper.isChiseledArmorNotEmpty(stack);
break;
default: hide = true;
}
if (hide)
{
armor[i] = stack;
armorInventory.set(i, ItemStack.EMPTY);
found = true;
}
}
}
if (found)
invisibleArmorMap.put(player.getUniqueID(), armor);
}

@SubscribeEvent
public void preventArmorRendering(RenderPlayerEvent.Post event)
{
if (Configs.armorModelRenderWithVanityMode == ArmorModelRenderWithVanityMode.ALWAYS)
return;

EntityPlayer player = event.getEntityPlayer();
IChiseledArmorSlotsHandler cap = ChiseledArmorSlotsHandler.getCapability(player);
if (cap == null)
return;

ItemStack[] armor = invisibleArmorMap.get(player.getUniqueID());
if (armor == null)
return;

for (int i = 0; i < 4; i++)
{
if (armor[i] != null)
player.inventory.armorInventory.set(i, armor[i]);
}
invisibleArmorMap.remove(player.getUniqueID());
}

@SubscribeEvent
public void onKeyInput(@SuppressWarnings("unused") InputEvent.KeyInputEvent event)
{
Expand Down
Expand Up @@ -3,20 +3,14 @@
import java.io.File;
import java.util.Arrays;

import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import com.phylogeny.extrabitmanipulation.armor.ChiseledArmorStackHandeler.ArmorStackModelRenderMode;
import com.phylogeny.extrabitmanipulation.armor.capability.ChiseledArmorSlotsEventHandler.ArmorButtonVisibiltyMode;
import com.phylogeny.extrabitmanipulation.helper.BitIOHelper;
import com.phylogeny.extrabitmanipulation.helper.BitToolSettingsHelper;
import com.phylogeny.extrabitmanipulation.helper.LogHelper;
import com.phylogeny.extrabitmanipulation.init.ItemsExtraBitManipulation;
import com.phylogeny.extrabitmanipulation.init.ModelRegistration.ArmorModelRenderMode;
import com.phylogeny.extrabitmanipulation.init.ModelRegistration.ArmorModelRenderWithVanityMode;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor;
import com.phylogeny.extrabitmanipulation.item.ItemModelingTool;
import com.phylogeny.extrabitmanipulation.item.ItemSculptingTool;
Expand All @@ -28,6 +22,13 @@
import com.phylogeny.extrabitmanipulation.reference.Utility;
import com.phylogeny.extrabitmanipulation.shape.Shape;

import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ConfigHandlerExtraBitManipulation
{
public static Configuration configFileClient, configFileServer, configFileCommon, modelingMapConfigFile, sculptingConfigFile, chiseledArmorConfigFile;
Expand Down Expand Up @@ -405,7 +406,7 @@ private static void updateConfigs()
ARMOR_SETTINGS, configFileClient, 0,
"Specifies when to render the default Chiseled Armor model for a given armor piece. If set to 'If Empty', it will only render for " +
"an armor piece if there are no non-empty itemstacks in the itemstack lists of any of its moving parts. It will never/always render, " +
"if set to 'Never'/'Always', respectively");
"if set to 'Never'/'Always', respectively.");

Configs.armorStackModelRenderMode = getEnumValueFromStringArray("Rendered Armor Stack Models", ArmorStackModelRenderMode.class,
ARMOR_SETTINGS, configFileClient, 0,
Expand Down Expand Up @@ -435,6 +436,12 @@ private static void updateConfigs()
ARMOR_SETTINGS, 0.05F, 0.0F, Float.MAX_VALUE,
"The items of both feet will be translated down by this many pixels to prevent z-fighting with the items of both legs.");

Configs.armorModelRenderWithVanityMode = getEnumValueFromStringArray("Render Armor With Vanity Armor", ArmorModelRenderWithVanityMode.class,
ARMOR_SETTINGS, configFileClient, 0,
"Specifies when to render a normally worn armor piece while a chiseled armor piece is worn in a corresponding vanity slot. "
+ "'If Chiseled' will only render the normally worn piece if it is also chiseled armor. 'If Chiseled Not Empty' additionally requires "
+ "the piece to have some blocks/items to render. The normally worn piece will never/always render, if set to 'Never'/'Always', respectively.");

Configs.armorTargetBits = getBitToolSettingBoolean("Target Bits", DATA_CATAGORY_ARMOR,
chiseledArmorConfigFile, false, true, false,
"targeting mode",
Expand Down
Expand Up @@ -2,13 +2,6 @@

import javax.annotation.Nullable;

import mod.chiselsandbits.api.ItemType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import com.phylogeny.extrabitmanipulation.api.ChiselsAndBitsAPIAccess;
import com.phylogeny.extrabitmanipulation.armor.capability.ChiseledArmorSlotsHandler;
import com.phylogeny.extrabitmanipulation.armor.capability.IChiseledArmorSlotsHandler;
Expand All @@ -19,6 +12,13 @@
import com.phylogeny.extrabitmanipulation.item.ItemSculptingTool;
import com.phylogeny.extrabitmanipulation.reference.NBTKeys;

import mod.chiselsandbits.api.ItemType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public class ItemStackHelper
{

Expand Down Expand Up @@ -130,4 +130,9 @@ else if (mainArmor)
return cap == null ? ItemStack.EMPTY : cap.getStackInSlot(3 - equipmentSlot.getIndex());
}

public static boolean isChiseledArmorNotEmpty(ItemStack stack)
{
return getArmorData(getNBTOrNew(stack)).getBoolean(NBTKeys.ARMOR_NOT_EMPTY);
}

}
@@ -1,5 +1,16 @@
package com.phylogeny.extrabitmanipulation.init;

import com.phylogeny.extrabitmanipulation.armor.ChiseledArmorStackHandeler.ChiseledArmorBakedModel;
import com.phylogeny.extrabitmanipulation.armor.ModelChiseledArmor;
import com.phylogeny.extrabitmanipulation.armor.ModelChiseledArmorLeggings;
import com.phylogeny.extrabitmanipulation.block.BlockExtraBitManipulationBase;
import com.phylogeny.extrabitmanipulation.helper.ItemStackHelper;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor.ArmorMovingPart;
import com.phylogeny.extrabitmanipulation.item.ItemExtraBitManipulationBase;
import com.phylogeny.extrabitmanipulation.reference.Configs;
import com.phylogeny.extrabitmanipulation.reference.Reference;

import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
Expand All @@ -12,18 +23,6 @@
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import com.phylogeny.extrabitmanipulation.armor.ChiseledArmorStackHandeler.ChiseledArmorBakedModel;
import com.phylogeny.extrabitmanipulation.armor.ModelChiseledArmor;
import com.phylogeny.extrabitmanipulation.armor.ModelChiseledArmorLeggings;
import com.phylogeny.extrabitmanipulation.block.BlockExtraBitManipulationBase;
import com.phylogeny.extrabitmanipulation.helper.ItemStackHelper;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor;
import com.phylogeny.extrabitmanipulation.item.ItemChiseledArmor.ArmorMovingPart;
import com.phylogeny.extrabitmanipulation.item.ItemExtraBitManipulationBase;
import com.phylogeny.extrabitmanipulation.reference.Configs;
import com.phylogeny.extrabitmanipulation.reference.NBTKeys;
import com.phylogeny.extrabitmanipulation.reference.Reference;

public class ModelRegistration
{
private static final String ARMOR_TEXTURE_PATH_DIANOND = Reference.MOD_ID + ":textures/armor/chiseled_armor_diamond.png";
Expand Down Expand Up @@ -133,12 +132,17 @@ public static String getArmorTexture(ItemStack stack, ArmorMaterial material)
private static boolean shouldRenderEmptymodel(ItemStack stack)
{
return Configs.armorModelRenderMode == ArmorModelRenderMode.NEVER || (Configs.armorModelRenderMode == ArmorModelRenderMode.IF_EMPTY
&& ItemStackHelper.getArmorData(ItemStackHelper.getNBTOrNew(stack)).getBoolean(NBTKeys.ARMOR_NOT_EMPTY));
&& ItemStackHelper.isChiseledArmorNotEmpty(stack));
}

public static enum ArmorModelRenderMode
{
IF_EMPTY, NEVER, ALWAYS;
}

public static enum ArmorModelRenderWithVanityMode
{
IF_CHISELED_NOT_EMPTY, IF_CHISELED, NEVER, ALWAYS;
}

}
Expand Up @@ -3,10 +3,6 @@
import java.util.HashMap;
import java.util.Map;

import mod.chiselsandbits.api.IBitBrush;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;

import com.phylogeny.extrabitmanipulation.armor.ChiseledArmorStackHandeler.ArmorStackModelRenderMode;
import com.phylogeny.extrabitmanipulation.armor.capability.ChiseledArmorSlotsEventHandler.ArmorButtonVisibiltyMode;
import com.phylogeny.extrabitmanipulation.config.ConfigBitStack;
Expand All @@ -18,12 +14,18 @@
import com.phylogeny.extrabitmanipulation.config.ConfigShapeRenderPair;
import com.phylogeny.extrabitmanipulation.helper.BitIOHelper;
import com.phylogeny.extrabitmanipulation.init.ModelRegistration.ArmorModelRenderMode;
import com.phylogeny.extrabitmanipulation.init.ModelRegistration.ArmorModelRenderWithVanityMode;
import com.phylogeny.extrabitmanipulation.packet.PacketThrowBit.BitBagBitSelectionMode;

import mod.chiselsandbits.api.IBitBrush;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;

public class Configs
{
//CHISELED ARMOR SETTINGS
public static ArmorModelRenderMode armorModelRenderMode;
public static ArmorModelRenderWithVanityMode armorModelRenderWithVanityMode;
public static ArmorStackModelRenderMode armorStackModelRenderMode;
public static ArmorButtonVisibiltyMode armorButtonVisibiltyMode;
public static boolean armorSlotsGuiExitToMainInventory;
Expand Down

0 comments on commit 7477e65

Please sign in to comment.