Skip to content

Commit

Permalink
Add Lighting check box to item morph (suggested by WhereWeWere)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Jul 28, 2020
1 parent 18b5644 commit 5f53ebd
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mchorse.vanilla_pack.editors.panels;

import mchorse.mclib.client.gui.framework.elements.buttons.GuiSlotElement;
import mchorse.mclib.client.gui.framework.elements.buttons.GuiToggleElement;
import mchorse.mclib.client.gui.framework.elements.utils.GuiInventoryElement;
import mchorse.mclib.client.gui.utils.keys.IKey;
import mchorse.metamorph.client.gui.editor.GuiAbstractMorph;
import mchorse.metamorph.client.gui.editor.GuiMorphPanel;
import mchorse.vanilla_pack.morphs.ItemStackMorph;
Expand All @@ -14,6 +16,7 @@ public class GuiItemStackPanel extends GuiMorphPanel<ItemStackMorph, GuiAbstract
{
public GuiSlotElement slot;
public GuiInventoryElement inventory;
public GuiToggleElement lighting;

public GuiItemStackPanel(Minecraft mc, GuiAbstractMorph<? extends ItemStackMorph> editor)
{
Expand All @@ -28,11 +31,13 @@ public GuiItemStackPanel(Minecraft mc, GuiAbstractMorph<? extends ItemStackMorph
this.inventory.setVisible(false);

this.slot = new GuiSlotElement(mc, 0, this.inventory::link);
this.lighting = new GuiToggleElement(mc, IKey.lang("metamorph.gui.label.lighting"), (b) -> this.morph.lighting = b.isToggled());

this.inventory.flex().relative(this.slot).x(0.5F, 0).y(-5).anchor(0.5F, 1);
this.slot.flex().relative(this).x(0.5F, 0).y(1, -10).wh(32, 32).anchor(0.5F, 1);
this.lighting.flex().relative(this).xy(10, 10).w(110);

this.add(this.slot, this.inventory);
this.add(this.slot, this.inventory, this.lighting);
}

@Override
Expand All @@ -41,5 +46,6 @@ public void fillData(ItemStackMorph morph)
super.fillData(morph);

this.slot.stack = morph.getStack();
this.lighting.toggled(morph.lighting);
}
}
14 changes: 14 additions & 0 deletions src/main/java/mchorse/vanilla_pack/morphs/BlockMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.EntityLivingBase;
Expand Down Expand Up @@ -98,6 +99,14 @@ public void render(EntityLivingBase entity, double x, double y, double z, float
{
Minecraft mc = Minecraft.getMinecraft();

float lastBrightnessX = OpenGlHelper.lastBrightnessX;
float lastBrightnessY = OpenGlHelper.lastBrightnessY;

if (!this.lighting)
{
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
}

GlStateManager.enableRescaleNormal();
BlockRendererDispatcher blockrendererdispatcher = mc.getBlockRendererDispatcher();
GlStateManager.pushMatrix();
Expand All @@ -110,6 +119,11 @@ public void render(EntityLivingBase entity, double x, double y, double z, float
GlStateManager.translate(0.0F, 0.0F, 1.0F);
GlStateManager.popMatrix();
GlStateManager.disableRescaleNormal();

if (!this.lighting)
{
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY);
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/mchorse/vanilla_pack/morphs/ItemMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public void renderOnScreen(EntityPlayer player, int x, int y, float scale, float
@SideOnly(Side.CLIENT)
public void render(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks)
{
float lastBrightnessX = OpenGlHelper.lastBrightnessX;
float lastBrightnessY = OpenGlHelper.lastBrightnessY;

if (!this.lighting)
{
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
}

GlStateManager.enableBlend();
GlStateManager.enableAlpha();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
Expand All @@ -83,6 +91,11 @@ public void render(EntityLivingBase entity, double x, double y, double z, float
render.renderItem(this.stack, model);

GlStateManager.popMatrix();

if (!this.lighting)
{
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY);
}
}

@Override
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/mchorse/vanilla_pack/morphs/ItemStackMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,63 @@

import mchorse.metamorph.api.morphs.AbstractMorph;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public abstract class ItemStackMorph extends AbstractMorph
{
public boolean lighting = true;

public abstract void setStack(ItemStack stack);

public abstract ItemStack getStack();

@Override
public boolean equals(Object obj)
{
boolean result = super.equals(obj);

if (obj instanceof ItemStackMorph)
{
ItemStackMorph morph = (ItemStackMorph) obj;

result = result && this.lighting == morph.lighting;
}

return result;
}

@Override
public void copy(AbstractMorph from)
{
super.copy(from);

if (from instanceof ItemStackMorph)
{
ItemStackMorph morph = (ItemStackMorph) from;

this.lighting = morph.lighting;
}
}

@Override
public void toNBT(NBTTagCompound tag)
{
super.toNBT(tag);

if (!this.lighting)
{
tag.setBoolean("Lighting", this.lighting);
}
}

@Override
public void fromNBT(NBTTagCompound tag)
{
super.fromNBT(tag);

if (tag.hasKey("Lighting"))
{
this.lighting = tag.getBoolean("Lighting");
}
}
}

0 comments on commit 5f53ebd

Please sign in to comment.