Skip to content

Commit

Permalink
Fixed rendering of enchantment effect. Fixes #1
Browse files Browse the repository at this point in the history
Also added a command to always render enchantment effect on items.
  • Loading branch information
olee committed Oct 22, 2015
1 parent daa06d9 commit 120c12b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class CommandCustomServerItem extends CommandBase
{

public static final String[] subCommands = new String[] { "texture", "name", "tooltip", "tool", "damage", "durability", "meta", "texturelist" };
public static final String[] subCommands = new String[] { "texture", "name", "tooltip", "tool", "glint", "damage", "durability", "meta", "texturelist" };

@Override
public String getCommandName()
Expand Down Expand Up @@ -67,6 +67,9 @@ public void processCommand(ICommandSender sender, String[] argArray)
case "tool":
parseTool(player, args, stack);
break;
case "glint":
parseGlint(player, args, stack);
break;
case "damage":
parseDamage(player, args, stack);
break;
Expand All @@ -93,6 +96,9 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args)
{
case "texture":
return getListOfStringsFromIterableMatchingLastWord(args, CustomServerItems.getTextureNames());
case "glint":
case "tool":
return getListOfStringsMatchingLastWord(args, "true", "false");
}
}
return null;
Expand Down Expand Up @@ -137,7 +143,17 @@ public void parseTool(EntityPlayer player, LinkedList<String> args, ItemStack st
throw new WrongUsageException("commands.notEnoughArguments");
boolean isTool = parseBoolean(player, args.remove());
stack.func_150996_a(isTool ? CustomServerItems.ITEM_TOOL : CustomServerItems.ITEM);
func_152373_a(player, this, "commands.customservercommand.toolSet", isTool ? "tool" : "item");
func_152373_a(player, this, isTool ? "commands.customservercommand.toolMode" : "commands.customservercommand.itemMode");
}

public void parseGlint(EntityPlayer player, LinkedList<String> args, ItemStack stack)
{
if (args.isEmpty())
throw new WrongUsageException("commands.notEnoughArguments");
boolean glint = parseBoolean(player, args.remove());
NBTTagCompound tag = getOrCreateTag(stack);
tag.setBoolean(CustomServerItems.TAG_GLINT, glint);
func_152373_a(player, this, glint ? "commands.customservercommand.glintOn" : "commands.customservercommand.glintOff");
}

public void parseDamage(EntityPlayer player, LinkedList<String> args, ItemStack stack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
Expand All @@ -18,6 +21,8 @@
public class CustomItemRenderer implements IItemRenderer
{

public static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");

@Override
public boolean handleRenderType(ItemStack stack, ItemRenderType type)
{
Expand Down Expand Up @@ -45,7 +50,8 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data)
{
String id = stack.getTagCompound().getString(CustomServerItems.TAG_TEXTURE);
ResourceLocation texture = TextureRegistry.getTexture(id);
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
textureManager.bindTexture(texture);

Tessellator tessellator = Tessellator.instance;
int iconWidth = 32;
Expand All @@ -65,17 +71,58 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data)
TextureUtil.func_152777_a(false, false, 1.0F);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
ItemRenderer.renderItemIn2D(tessellator, 1, 0, 0, 1, iconWidth, iconHeight, 0.0625F);

if (stack.hasEffect(0) || stack.getTagCompound().getBoolean(CustomServerItems.TAG_GLINT))
{
GL11.glDepthFunc(GL11.GL_EQUAL);
GL11.glDisable(GL11.GL_LIGHTING);
textureManager.bindTexture(RES_ITEM_GLINT);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(768, 1, 1, 0);
GL11.glColor4f(0.5F * 0.76F, 0.25F * 0.76F, 0.8F * 0.76F, 1.0F);
GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glPushMatrix();
float f8 = 0.125F;
GL11.glScalef(f8, f8, f8);
float f9 = Minecraft.getSystemTime() % 3000L / 3000.0F * 8.0F;
GL11.glTranslatef(f9, 0.0F, 0.0F);
GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(f8, f8, f8);
f9 = Minecraft.getSystemTime() % 4873L / 4873.0F * 8.0F;
GL11.glTranslatef(-f9, 0.0F, 0.0F);
GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDepthFunc(GL11.GL_LEQUAL);
}

break;
case INVENTORY:
default:
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
double zLevel = 4;
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

double zLevel = RenderItem.getInstance().zLevel;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(0, 16, zLevel, 0, 1);
tessellator.addVertexWithUV(16, 16, zLevel, 1, 1);
tessellator.addVertexWithUV(16, 0, zLevel, 1, 0);
tessellator.addVertexWithUV(0, 0, zLevel, 0, 0);
tessellator.draw();

if (stack.hasEffect(0) || stack.getTagCompound().getBoolean(CustomServerItems.TAG_GLINT))
RenderItem.getInstance().renderEffect(textureManager, 0, 0);

GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class CustomServerItems implements IMessageHandler<PacketRequestTexture,

public static final String TAG_TOOLTIP = "csi_tooltip";

public static final String TAG_GLINT = "csi_glint";

public static final ItemCustom ITEM = new ItemCustom();

public static final ItemCustom ITEM_TOOL = new ItemCustomTool();
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/customserveritems/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ commands.customservercommand.itemNeeded=You need to equip a custom item first
commands.customservercommand.textures=Available textures: %s
commands.customservercommand.iconSet=Set custom item texture to %s
commands.customservercommand.nameSet=Set custom item name to "%s"
commands.customservercommand.toolSet=Set custom item display to %s-mode
commands.customservercommand.toolMode=Set custom item to render as tool
commands.customservercommand.itemMode=Set custom item to render as item
commands.customservercommand.glintOn=Enabled enchantment effect
commands.customservercommand.glintOff=Disabled enchantment effect
commands.customservercommand.damageSet=Set custom item damage to +%s
commands.customservercommand.tooltipSet=Set custom item tooltip to "%s"
commands.customservercommand.durabilitySet=Set custom item durability to %s
Expand Down

0 comments on commit 120c12b

Please sign in to comment.