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

Backpack z-fighting fix plus a few options #43

Open
wants to merge 2 commits into
base: 1.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ModelBackpack() {

straps = new ModelRenderer(this, 24, 0);
straps.setRotationPoint(0.0F, 0.0F, 0.0F);
straps.addBox(-4.0F, 0.05F, -3.0F, 8, 8, 5, 0.0F);
straps.addBox(-4.0F, 0.05F, -3.01F, 8, 8, 5, 0.0F);
fitting = new ModelRenderer(this, 50, 0);
fitting.setRotationPoint(0.0F, 0.0F, 0.0F);
fitting.addBox(-1.0F, 3.0F, 6.0F, 2, 3, 1, 0.0F);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/vazkii/quark/oddities/feature/Backpacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@
import vazkii.arl.network.NetworkHandler;
import vazkii.arl.recipe.RecipeHandler;
import vazkii.arl.util.InventoryIIH;
import vazkii.quark.base.module.ConfigHelper;
import vazkii.quark.base.module.Feature;
import vazkii.quark.base.network.message.MessageHandleBackpack;
import vazkii.quark.oddities.RecipesBackpackDyes;
import vazkii.quark.oddities.client.gui.GuiBackpackInventory;
import vazkii.quark.oddities.item.ItemBackpack;
import vazkii.quark.oddities.item.ItemBackpackBaubles;

public class Backpacks extends Feature {

public static ItemBackpack backpack;

public static boolean superOpMode, enableTrades, enableCrafting, enablePickUp;
public static boolean superOpMode, enableTrades, enableCrafting, enablePickUp, ignoreShiftClick, enableBaubles;

public static int leatherCount, minEmeralds, maxEmeralds;

Expand All @@ -70,14 +72,16 @@ public void setupConfig() {
enableCrafting = loadPropBool("Enable Crafting", "Set this to true to enable a crafting recipe", false);
enablePickUp = loadPropBool("Enable Backpack Pick-Up", "Set this to true to allow items to be picked up into backpacks when the main inventory is full", false);
superOpMode = loadPropBool("Unbalanced Mode", "Set this to true to allow the backpacks to be unequipped even with items in them", false);
ignoreShiftClick = loadPropBool("Backpack Ignores Shift-Clicking", "Set this to true to make shift-clicking inventory items send them to the hotbar instead of the backpack", false);
leatherCount = loadPropInt("Required Leather", "", 12);
minEmeralds = loadPropInt("Min Required Emeralds", "", 12);
maxEmeralds = loadPropInt("Max Required Emeralds", "", 18);
if (Loader.isModLoaded("baubles")) enableBaubles = loadPropBool("Enable Backpack Bauble", "Set this to true to turn the backpack into a bauble that's equipped in the Body slot", true);
}

@Override
public void preInit(FMLPreInitializationEvent event) {
backpack = new ItemBackpack();
backpack = ((Loader.isModLoaded("baubles") && enableBaubles) ? new ItemBackpackBaubles() : new ItemBackpack());

if (enableCrafting)
RecipeHandler.addOreDictRecipe(new ItemStack(backpack),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void setupConfig() {
"Format is modid:item[:meta]",
new String[0]);
tempSavingItem = loadPropString("Saving Item", "An item that must be in the player inventory for the totem to work. Set to 'none' to disable", "quark:totem_of_holding");
enableTotemItem = loadPropBool("Enable Totem of Holding Item", "", true);
enableTotemItem = loadPropBool("Enable Totem of Holding Item", "", false);
entityScale = (float) loadPropDouble("Totem of Holding Entity Scale", "Displayed scale of the totem of holding entity", 1.0D);
glowRange = loadPropDouble("Totem Glow Range", "Maximum range at which totems visibly glow. Default is 32; set to 0 to disable", 32);
}
Expand Down Expand Up @@ -118,6 +118,7 @@ public void postPreInit() {
.collect(Collectors.toSet());

ItemStack item = (tempSavingItem.equals("none") ? ItemStack.EMPTY : new ArrayList<>(ItemMetaHelper.getFromString("totem holding saving item", tempSavingItem, false)).get(0));
if (tempSavingItem.equals("quark:totem_of_holding") && !enableTotemItem) item = ItemStack.EMPTY;
savingItem = !item.isEmpty() ? Pair.of(item.getItem(), item.getMetadata()) : Pair.of(Items.AIR, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import vazkii.aurelienribon.tweenengine.equations.Back;
import vazkii.quark.base.module.ConfigHelper;
import vazkii.quark.oddities.QuarkOddities;
import vazkii.quark.oddities.feature.Backpacks;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -161,6 +165,11 @@ public boolean mergeItemStack(ItemStack stack, int start, int length, boolean r)
@Nonnull
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if (Backpacks.ignoreShiftClick && clickTypeIn == ClickType.QUICK_MOVE && slotId < 36)
{
return player.inventoryContainer.slotClick(slotId, dragType, clickTypeIn, player);
}

SlotCachingItemHandler.cache(this);
ItemStack stack = super.slotClick(slotId, dragType, clickTypeIn, player);
SlotCachingItemHandler.applyCache(this);
Expand Down
108 changes: 13 additions & 95 deletions src/main/java/vazkii/quark/oddities/item/ItemBackpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,20 @@
import vazkii.arl.interf.IItemColorProvider;
import vazkii.arl.item.ItemModArmor;
import vazkii.arl.util.ItemNBTHelper;
import vazkii.quark.base.Quark;
import vazkii.quark.base.handler.ProxiedItemStackHandler;
import vazkii.quark.base.item.IQuarkItem;
import vazkii.quark.base.lib.LibGuiIDs;
import vazkii.quark.base.lib.LibMisc;
import vazkii.quark.oddities.client.model.ModelBackpack;
import vazkii.quark.oddities.feature.Backpacks;

@Optional.InterfaceList(value = {
@Optional.Interface(iface = "baubles.api.IBauble", modid = "baubles", striprefs = true),
@Optional.Interface(iface = "baubles.api.render.IRenderBauble", modid = "baubles", striprefs = true)
})
public class ItemBackpack extends ItemModArmor implements IBauble, IQuarkItem, IItemColorProvider, IRenderBauble {
public class ItemBackpack extends ItemModArmor implements IQuarkItem, IItemColorProvider {
private static final String WORN_TEXTURE = LibMisc.PREFIX_MOD + "textures/misc/backpack_worn.png";
private static final String WORN_OVERLAY_TEXTURE = LibMisc.PREFIX_MOD + "textures/misc/backpack_worn_overlay.png";

private static final ResourceLocation WORN_TEXTURE_RL = new ResourceLocation(WORN_TEXTURE);
private static final ResourceLocation WORN_OVERLAY_TEXTURE_RL = new ResourceLocation(WORN_OVERLAY_TEXTURE);
protected static final ResourceLocation WORN_TEXTURE_RL = new ResourceLocation(WORN_TEXTURE);
protected static final ResourceLocation WORN_OVERLAY_TEXTURE_RL = new ResourceLocation(WORN_OVERLAY_TEXTURE);

public static final IBehaviorDispenseItem DISPENSER_BEHAVIOR = new BehaviorDefaultDispenseItem() {
/**
Expand Down Expand Up @@ -162,32 +160,15 @@ public Multimap<String, AttributeModifier> getItemAttributeModifiers(@Nonnull En
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
if (Loader.isModLoaded("baubles")) {
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); i++) {
if ((baubles.getStackInSlot(i) == null || baubles.getStackInSlot(i).isEmpty())
&& baubles.isItemValidForSlot(i, stack, player)) {
baubles.setStackInSlot(i, stack.copy());
if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
}
onEquipped(stack, player);

return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
}
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
} else {
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(stack);
ItemStack stackInSlot = player.getItemStackFromSlot(entityequipmentslot);
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(stack);
ItemStack stackInSlot = player.getItemStackFromSlot(entityequipmentslot);

if (stackInSlot.isEmpty()) {
player.setItemStackToSlot(entityequipmentslot, stack.copy());
stack.setCount(stack.getCount()-1);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
}
if (stackInSlot.isEmpty()) {
player.setItemStackToSlot(entityequipmentslot, stack.copy());
stack.setCount(stack.getCount()-1);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
}
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
Expand Down Expand Up @@ -305,24 +286,6 @@ public IItemColor getItemColor() {
return (stack, i) -> i == 1 ? ((ItemBackpack) stack.getItem()).getColor(stack) : -1;
}

@Override
@Optional.Method(modid = "baubles")
public BaubleType getBaubleType(ItemStack itemStack) {
return BaubleType.BODY;
}

@Override
@Optional.Method(modid = "baubles")
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return !Backpacks.isEntityWearingBackpack(player, itemstack);
}

@Override
@Optional.Method(modid = "baubles")
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return Backpacks.superOpMode || !doesBackpackHaveItems(itemstack);
}

public boolean hasColor(@Nonnull ItemStack stack) {
NBTTagCompound nbttagcompound = stack.getTagCompound();
return (nbttagcompound != null)
Expand Down Expand Up @@ -361,51 +324,6 @@ public void setColor(ItemStack stack, int color) {
nbttagcompound1.setInteger("color", color);
}

@Override
@SideOnly(Side.CLIENT)
@Optional.Method(modid = "baubles")
public void onPlayerBaubleRender(ItemStack itemStack, EntityPlayer player, RenderType renderType, float v) {
if (!player.world.isRemote) return;

if (renderType != RenderType.BODY) return;

if (model == null) model = new ModelBackpack();

model.setModelAttributes(new ModelPlayer(0.0F, false));

Minecraft.getMinecraft().renderEngine.bindTexture(WORN_TEXTURE_RL);

int i = backpack.getColor(itemStack);
float red = (float) (i >> 16 & 255) / 255.0F;
float green = (float) (i >> 8 & 255) / 255.0F;
float blue = (float) (i & 255) / 255.0F;

GlStateManager.color(red, green, blue, 1);


float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks();
float f = this.interpolateRotation(player.prevRenderYawOffset, player.renderYawOffset, partialTicks);
float f1 = this.interpolateRotation(player.prevRotationYawHead, player.rotationYawHead, partialTicks);
float f2 = f1 - f;
// float f4 = renderer.prepareScale(player, Minecraft.getMinecraft().getRenderPartialTicks());
float f4 = 0.0625F;
float f8 = (float) player.ticksExisted + partialTicks;
float f5 = player.prevLimbSwingAmount + (player.limbSwingAmount - player.prevLimbSwingAmount) * partialTicks;
float f6 = player.limbSwing - player.limbSwingAmount * (1.0F - partialTicks);
float f7 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;

model.setVisible(false);
model.bipedBody.showModel = true;

model.render(player, f6, f5, f8, f2, f7, f4);

Minecraft.getMinecraft().renderEngine.bindTexture(WORN_OVERLAY_TEXTURE_RL);

GlStateManager.color(1, 1, 1, 1);

model.render(player, 0, 0, 1000, 0, 0, 0.0625F);
}

/**
* Returns a rotation angle that is inbetween two other rotation angles. par1 and par2 are the angles between which
* to interpolate, par3 is probably a float between 0.0 and 1.0 that tells us where "between" the two angles we are.
Expand Down
131 changes: 131 additions & 0 deletions src/main/java/vazkii/quark/oddities/item/ItemBackpackBaubles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package vazkii.quark.oddities.item;

import baubles.api.BaubleType;
import baubles.api.BaublesApi;
import baubles.api.IBauble;
import baubles.api.cap.IBaublesItemHandler;
import baubles.api.render.IRenderBauble;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.quark.oddities.client.model.ModelBackpack;
import vazkii.quark.oddities.feature.Backpacks;

import static vazkii.quark.oddities.feature.Backpacks.backpack;

@Optional.InterfaceList(value = {
@Optional.Interface(iface = "baubles.api.IBauble", modid = "baubles", striprefs = true),
@Optional.Interface(iface = "baubles.api.render.IRenderBauble", modid = "baubles", striprefs = true)
})
public class ItemBackpackBaubles extends ItemBackpack implements IBauble, IRenderBauble {

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); i++) {
if ((baubles.getStackInSlot(i) == null || baubles.getStackInSlot(i).isEmpty())
&& baubles.isItemValidForSlot(i, stack, player)) {
baubles.setStackInSlot(i, stack.copy());
if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
}
onEquipped(stack, player);

return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
}
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}

@Override
@Optional.Method(modid = "baubles")
public BaubleType getBaubleType(ItemStack itemStack) {
return BaubleType.BODY;
}

@Override
@Optional.Method(modid = "baubles")
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return !Backpacks.isEntityWearingBackpack(player, itemstack);
}

@Override
@Optional.Method(modid = "baubles")
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return Backpacks.superOpMode || !doesBackpackHaveItems(itemstack);
}

@Override
@SideOnly(Side.CLIENT)
@Optional.Method(modid = "baubles")
public void onPlayerBaubleRender(ItemStack itemStack, EntityPlayer player, RenderType renderType, float v) {
if (!player.world.isRemote) return;

if (renderType != RenderType.BODY) return;

if (model == null) model = new ModelBackpack();

model.setModelAttributes(new ModelPlayer(0.0F, false));

Minecraft.getMinecraft().renderEngine.bindTexture(WORN_TEXTURE_RL);

int i = backpack.getColor(itemStack);
float red = (float) (i >> 16 & 255) / 255.0F;
float green = (float) (i >> 8 & 255) / 255.0F;
float blue = (float) (i & 255) / 255.0F;

GlStateManager.color(red, green, blue, 1);


float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks();
float f = this.interpolateRotation(player.prevRenderYawOffset, player.renderYawOffset, partialTicks);
float f1 = this.interpolateRotation(player.prevRotationYawHead, player.rotationYawHead, partialTicks);
float f2 = f1 - f;
// float f4 = renderer.prepareScale(player, Minecraft.getMinecraft().getRenderPartialTicks());
float f4 = 0.0625F;
float f8 = (float) player.ticksExisted + partialTicks;
float f5 = player.prevLimbSwingAmount + (player.limbSwingAmount - player.prevLimbSwingAmount) * partialTicks;
float f6 = player.limbSwing - player.limbSwingAmount * (1.0F - partialTicks);
float f7 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;

model.setVisible(false);
model.bipedBody.showModel = true;

model.render(player, f6, f5, f8, f2, f7, f4);

Minecraft.getMinecraft().renderEngine.bindTexture(WORN_OVERLAY_TEXTURE_RL);

GlStateManager.color(1, 1, 1, 1);

model.render(player, 0, 0, 1000, 0, 0, 0.0625F);
}

@Override
public EntityEquipmentSlot getEquipmentSlot() {
return null;
}

@Override
public boolean isValidArmor(ItemStack stack, EntityEquipmentSlot armorType, Entity entity) {
if (stack.getItem() instanceof ItemBackpack && entity instanceof EntityPlayer) {
return false;
}
return super.isValidArmor(stack, armorType, entity);
}
}