More glyph work

This commit is contained in:
Pahimar 2014-10-07 16:20:41 -04:00
parent a1e502c295
commit 6e727a5a7f
13 changed files with 320 additions and 97 deletions

View file

@ -1,5 +1,5 @@
#
#Sat Dec 28 00:14:08 EST 2013
minecraft_version = 1.7.10
forge_version = 10.13.1.1217
forge_version = 10.13.1.1222
mod_version = 0.2

View file

@ -1,6 +1,6 @@
package com.pahimar.ee3;
import com.pahimar.ee3.array.GlyphRegistry;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.command.CommandSetCurrentItemValue;
import com.pahimar.ee3.command.CommandSetValue;
import com.pahimar.ee3.command.CommandSyncValues;
@ -145,8 +145,8 @@ public class EquivalentExchange3
return SkillRegistry.getInstance();
}
public GlyphRegistry getGlyphRegistry()
public GlyphTextureRegistry getGlyphRegistry()
{
return GlyphRegistry.getInstance();
return GlyphTextureRegistry.getInstance();
}
}

View file

@ -9,7 +9,7 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
public class AlchemyArray
public class AlchemyArray implements Comparable<AlchemyArray>
{
private SortedSet<Glyph> glyphs;
private int largestGlyphSize;
@ -130,4 +130,36 @@ public class AlchemyArray
return stringBuilder.toString();
}
@Override
public boolean equals(Object object)
{
if (object instanceof AlchemyArray)
{
return this.compareTo((AlchemyArray) object) == 0;
}
return false;
}
@Override
public int compareTo(AlchemyArray alchemyArray)
{
if (this.glyphs.size() == alchemyArray.glyphs.size())
{
for (Glyph glyph : this.glyphs)
{
if (!alchemyArray.glyphs.contains(glyph))
{
return -1;
}
}
return 0;
}
else
{
return this.glyphs.size() - alchemyArray.glyphs.size();
}
}
}

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.api;
import com.pahimar.ee3.util.ResourceLocationHelper;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
@ -9,6 +8,7 @@ public class Glyph implements Comparable<Glyph>
private ResourceLocation texture;
private String unLocalizedName;
private int size;
private int rotation;
private Glyph()
{
@ -20,28 +20,27 @@ public class Glyph implements Comparable<Glyph>
this(texture, unLocalizedName, 1);
}
public Glyph(String texture, String unLocalizedName)
{
this(texture, unLocalizedName, 1);
}
public Glyph(String texture, String unLocalizedName, int size)
{
this(ResourceLocationHelper.getResourceLocation(texture), unLocalizedName, size);
}
public Glyph(ResourceLocation texture, String unLocalizedName, int size)
{
this(texture, unLocalizedName, size, 0);
}
public Glyph(ResourceLocation texture, String unLocalizedName, int size, int rotation)
{
this.texture = texture;
this.unLocalizedName = unLocalizedName;
this.size = size;
this.rotation = rotation;
}
public Glyph(Glyph glyph, int size)
{
this.texture = glyph.texture;
this.unLocalizedName = glyph.unLocalizedName;
this.size = size;
this(glyph, size, glyph.rotation);
}
public Glyph(Glyph glyph, int size, int rotation)
{
this(glyph.texture, glyph.unLocalizedName, size, rotation);
}
public ResourceLocation getTexture()
@ -59,19 +58,57 @@ public class Glyph implements Comparable<Glyph>
return size;
}
public int getRotation()
{
return rotation;
}
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
if (nbtTagCompound != null && nbtTagCompound.hasKey("textureDomain") && nbtTagCompound.hasKey("texturePath") && nbtTagCompound.hasKey("unLocalizedName") && nbtTagCompound.hasKey("size"))
if (nbtTagCompound != null)
{
if (nbtTagCompound.hasKey("textureDomain") && nbtTagCompound.hasKey("texturePath"))
{
this.texture = new ResourceLocation(nbtTagCompound.getString("textureDomain"), nbtTagCompound.getString("texturePath"));
}
else
{
this.texture = new ResourceLocation("");
}
if (nbtTagCompound.hasKey("unLocalizedName"))
{
this.unLocalizedName = nbtTagCompound.getString("unLocalizedName");
}
else
{
this.unLocalizedName = "";
}
if (nbtTagCompound.hasKey("size"))
{
this.size = nbtTagCompound.getInteger("size");
}
else
{
this.size = 0;
}
if (nbtTagCompound.hasKey("rotation"))
{
this.rotation = nbtTagCompound.getInteger("rotation");
}
else
{
this.rotation = 0;
}
}
else
{
this.texture = new ResourceLocation("");
this.unLocalizedName = "";
this.size = 0;
this.rotation = 0;
}
}
@ -81,6 +118,7 @@ public class Glyph implements Comparable<Glyph>
nbtTagCompound.setString("texturePath", texture.getResourcePath());
nbtTagCompound.setString("unLocalizedName", unLocalizedName);
nbtTagCompound.setInteger("size", size);
nbtTagCompound.setInteger("rotation", rotation);
}
public static Glyph readGlyphFromNBT(NBTTagCompound nbtTagCompound)
@ -93,7 +131,7 @@ public class Glyph implements Comparable<Glyph>
@Override
public String toString()
{
return String.format("texture: %s, unLocalizedName: %s, size: %s", texture.getResourceDomain() + ":" + texture.getResourcePath(), unLocalizedName, size);
return String.format("texture: %s, unLocalizedName: %s, size: %s, orientation: %s", texture.getResourceDomain() + ":" + texture.getResourcePath(), unLocalizedName, size, rotation);
}
@Override
@ -113,9 +151,16 @@ public class Glyph implements Comparable<Glyph>
if (this.texture.getResourceDomain().equalsIgnoreCase(glyph.getTexture().getResourceDomain()))
{
if (this.texture.getResourcePath().equalsIgnoreCase(glyph.getTexture().getResourcePath()))
{
if (this.size == glyph.size)
{
return this.rotation - glyph.rotation;
}
else
{
return this.size - glyph.size;
}
}
else
{
return this.texture.getResourcePath().compareToIgnoreCase(glyph.getTexture().getResourcePath());

View file

@ -2,13 +2,14 @@ package com.pahimar.ee3.api;
import com.pahimar.ee3.EquivalentExchange3;
import cpw.mods.fml.common.Mod;
import net.minecraft.util.ResourceLocation;
public class GlyphRegistryProxy
public class GlyphTextureRegistryProxy
{
@Mod.Instance("EE3")
private static Object ee3Mod;
public static void addGlyph(Glyph glyph)
public static void addGlyph(ResourceLocation glyphTexture, String unLocalizedName)
{
init();
@ -18,7 +19,7 @@ public class GlyphRegistryProxy
return;
}
EE3Wrapper.ee3mod.getGlyphRegistry().addGlyph(glyph);
EE3Wrapper.ee3mod.getGlyphRegistry().addGlyph(glyphTexture, unLocalizedName);
}
private static class EE3Wrapper

View file

@ -1,44 +0,0 @@
package com.pahimar.ee3.array;
import com.google.common.collect.ImmutableSet;
import com.pahimar.ee3.api.Glyph;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
public class GlyphRegistry
{
private static GlyphRegistry glyphRegistry = null;
private SortedSet<Glyph> glyphSortedSet;
private GlyphRegistry()
{
}
public static GlyphRegistry getInstance()
{
if (glyphRegistry == null)
{
glyphRegistry = new GlyphRegistry();
glyphRegistry.init();
}
return glyphRegistry;
}
private void init()
{
glyphSortedSet = new TreeSet<Glyph>();
}
public void addGlyph(Glyph glyph)
{
glyphSortedSet.add(new Glyph(glyph, 1));
}
public Set<Glyph> getGlyphs()
{
return ImmutableSet.copyOf(glyphSortedSet);
}
}

View file

@ -0,0 +1,73 @@
package com.pahimar.ee3.array;
import com.google.common.collect.ImmutableMap;
import com.pahimar.ee3.api.Glyph;
import net.minecraft.util.ResourceLocation;
import java.util.Comparator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
public class GlyphTextureRegistry
{
private static GlyphTextureRegistry glyphTextureRegistry = null;
private SortedMap<ResourceLocation, String> glyphTextureSortedMap;
private GlyphTextureRegistry()
{
}
public static GlyphTextureRegistry getInstance()
{
if (glyphTextureRegistry == null)
{
glyphTextureRegistry = new GlyphTextureRegistry();
glyphTextureRegistry.init();
}
return glyphTextureRegistry;
}
private void init()
{
glyphTextureSortedMap = new TreeMap<ResourceLocation, String>(comparator);
}
public void addGlyph(Glyph glyph)
{
if (glyph.getTexture() != null)
{
glyphTextureSortedMap.put(glyph.getTexture(), glyph.getUnLocalizedName());
}
}
public void addGlyph(ResourceLocation glyphTexture, String unLocalizedName)
{
if (glyphTexture != null)
{
glyphTextureSortedMap.put(glyphTexture, unLocalizedName);
}
}
public Map<ResourceLocation, String> getGlyphs()
{
return ImmutableMap.copyOf(glyphTextureSortedMap);
}
private static Comparator<ResourceLocation> comparator = new Comparator<ResourceLocation>()
{
@Override
public int compare(ResourceLocation resourceLocation1, ResourceLocation resourceLocation2)
{
if (resourceLocation1.getResourceDomain().equalsIgnoreCase(resourceLocation2.getResourceDomain()))
{
return resourceLocation1.getResourcePath().compareToIgnoreCase(resourceLocation2.getResourcePath());
}
else
{
return resourceLocation1.getResourceDomain().compareToIgnoreCase(resourceLocation2.getResourceDomain());
}
}
};
}

View file

@ -11,6 +11,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
@ -57,11 +58,17 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
{
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
((TileEntityEE) world.getTileEntity(x, y, z)).setOrientation(world.getBlockMetadata(x, y, z));
if (world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray)
{
// TODO: Place the first glyph of the alchemy glyphs from the player's currently selected glyph
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.BASE_CIRCLE, 3);
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.BASE_CIRCLE, 3, facing);
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.BASE_CIRCLE, 2, facing);
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.BASE_CIRCLE, 1, facing);
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.TRIANGLE, 1, facing);
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.TRIANGLE, 2);
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(Glyphs.TRIANGLE, 3);
}
}
@ -74,7 +81,7 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
return null;
}
/**

View file

@ -8,6 +8,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
@ -26,7 +27,7 @@ public class TileEntityRendererAlchemyArray extends TileEntitySpecialRenderer
for (Glyph glyph : tileEntityAlchemyArray.getAlchemyArray().getGlyphs())
{
this.bindTexture(glyph.getTexture());
renderSymbol(glyph, x, y, z);
renderSymbol(glyph, x, y, z, tileEntityAlchemyArray.getOrientation());
}
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_LIGHTING);
@ -34,19 +35,64 @@ public class TileEntityRendererAlchemyArray extends TileEntitySpecialRenderer
}
}
private void renderSymbol(Glyph glyph, double x, double y, double z)
private void renderSymbol(Glyph glyph, double x, double y, double z, ForgeDirection orientation)
{
// TODO handle facing variants of glyphs
Tessellator tessellator = Tessellator.instance;
GL11.glPushMatrix();
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0f, 0.5f - (glyph.getSize() / 2f));
tessellator.startDrawingQuads();
if (orientation == ForgeDirection.DOWN)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0f, 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.999d, z + glyph.getSize(), 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.999d, z, 0, 1);
tessellator.addVertexWithUV(x, y + 0.999d, z, 1, 1);
tessellator.addVertexWithUV(x, y + 0.999d, z + glyph.getSize(), 1, 0);
}
else if (orientation == ForgeDirection.UP)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0f, 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.001d, z + glyph.getSize(), 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.001d, z, 0, 1);
tessellator.addVertexWithUV(x, y + 0.001d, z, 1, 1);
tessellator.addVertexWithUV(x, y + 0.001d, z + glyph.getSize(), 1, 0);
}
else if (orientation == ForgeDirection.NORTH)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f), 0f);
tessellator.addVertexWithUV(x, y + glyph.getSize(), z + 0.999d, 1, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + glyph.getSize(), z + 0.999d, 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y, z + 0.999d, 0, 1);
tessellator.addVertexWithUV(x, y, z + 0.999d, 1, 1);
}
else if (orientation == ForgeDirection.SOUTH)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f), 0f);
tessellator.addVertexWithUV(x, y + glyph.getSize(), z + 0.001d, 1, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + glyph.getSize(), z + 0.001d, 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y, z + 0.001d, 0, 1);
tessellator.addVertexWithUV(x, y, z + 0.001d, 1, 1);
}
else if (orientation == ForgeDirection.WEST)
{
GL11.glTranslatef(0f, 0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + 0.999d, y + glyph.getSize(), z, 0, 0);
tessellator.addVertexWithUV(x + 0.999d, y + glyph.getSize(), z + glyph.getSize(), 0, 1);
tessellator.addVertexWithUV(x + 0.999d, y, z + glyph.getSize(), 1, 1);
tessellator.addVertexWithUV(x + 0.999d, y, z, 1, 0);
}
else if (orientation == ForgeDirection.EAST)
{
GL11.glTranslatef(0f, 0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + 0.001d, y + glyph.getSize(), z, 0, 0);
tessellator.addVertexWithUV(x + 0.001d, y + glyph.getSize(), z + glyph.getSize(), 0, 1);
tessellator.addVertexWithUV(x + 0.001d, y, z + glyph.getSize(), 1, 1);
tessellator.addVertexWithUV(x + 0.001d, y, z, 1, 0);
}
tessellator.draw();
GL11.glPopMatrix();
}

View file

@ -4,9 +4,11 @@ import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.network.message.MessageSyncEnergyValues;
import com.pahimar.ee3.reference.Reference;
import com.pahimar.ee3.util.EntityHelper;
import com.pahimar.ee3.util.LogHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.entity.player.PlayerEvent;
import java.io.*;
@ -53,8 +55,37 @@ public class PlayerEventHandler
}
@SubscribeEvent
public void onPlayerLoggedInEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
public void syncEnergyValuesOnLogin(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
{
PacketHandler.INSTANCE.sendTo(new MessageSyncEnergyValues(EnergyValueRegistry.getInstance()), (EntityPlayerMP) event.player);
}
@SubscribeEvent
public void initPlayerCustomData(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
{
if (event.player != null)
{
if (EntityHelper.getCustomEntityData(event.player) == null)
{
NBTTagCompound playerCustomData = new NBTTagCompound();
NBTTagCompound glyphCustomData = new NBTTagCompound();
glyphCustomData.setInteger("index", 0);
glyphCustomData.setInteger("size", 1);
glyphCustomData.setInteger("rotation", 0);
playerCustomData.setTag("chalkSettings", glyphCustomData);
EntityHelper.saveCustomEntityData(event.player, playerCustomData);
}
else
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(event.player);
for (Object object : playerCustomData.func_150296_c())
{
LogHelper.info(String.format("key: %s, value: %s", object.toString(), playerCustomData.getTag(object.toString())));
}
}
}
}
}

View file

@ -1,7 +1,7 @@
package com.pahimar.ee3.init;
import com.pahimar.ee3.api.Glyph;
import com.pahimar.ee3.api.GlyphRegistryProxy;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.reference.Textures;
@ -24,17 +24,17 @@ public class Glyphs
public static void init()
{
GlyphRegistryProxy.addGlyph(BASE_CIRCLE);
GlyphRegistryProxy.addGlyph(DOT);
GlyphRegistryProxy.addGlyph(LINE);
GlyphRegistryProxy.addGlyph(CIRCLE);
GlyphRegistryProxy.addGlyph(TRIANGLE);
GlyphRegistryProxy.addGlyph(INVERTED_TRIANGLE);
GlyphRegistryProxy.addGlyph(SQUARE);
GlyphRegistryProxy.addGlyph(DIAMOND);
GlyphRegistryProxy.addGlyph(PENTAGON);
GlyphRegistryProxy.addGlyph(HEXAGON);
GlyphRegistryProxy.addGlyph(HEPTAGON);
GlyphRegistryProxy.addGlyph(OCTAGON);
GlyphTextureRegistry.getInstance().addGlyph(BASE_CIRCLE);
GlyphTextureRegistry.getInstance().addGlyph(DOT);
GlyphTextureRegistry.getInstance().addGlyph(LINE);
GlyphTextureRegistry.getInstance().addGlyph(CIRCLE);
GlyphTextureRegistry.getInstance().addGlyph(TRIANGLE);
GlyphTextureRegistry.getInstance().addGlyph(INVERTED_TRIANGLE);
GlyphTextureRegistry.getInstance().addGlyph(SQUARE);
GlyphTextureRegistry.getInstance().addGlyph(DIAMOND);
GlyphTextureRegistry.getInstance().addGlyph(PENTAGON);
GlyphTextureRegistry.getInstance().addGlyph(HEXAGON);
GlyphTextureRegistry.getInstance().addGlyph(HEPTAGON);
GlyphTextureRegistry.getInstance().addGlyph(OCTAGON);
}
}

View file

@ -35,11 +35,17 @@ public class TileEntityAlchemyArray extends TileEntityEE
alchemyArray.addGlyph(new Glyph(glyph, size));
}
public void addGlyphToAlchemyArray(Glyph glyph, int size, int facing)
{
alchemyArray.addGlyph(new Glyph(glyph, size, facing));
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getBoundingBox(xCoord - alchemyArray.getLargestGlyphSize(), yCoord, zCoord - alchemyArray.getLargestGlyphSize(), xCoord + alchemyArray.getLargestGlyphSize(), yCoord, zCoord + alchemyArray.getLargestGlyphSize());
// TODO: Make this glyph size and orientation sensitive
return AxisAlignedBB.getBoundingBox(xCoord - alchemyArray.getLargestGlyphSize(), yCoord - alchemyArray.getLargestGlyphSize(), zCoord - alchemyArray.getLargestGlyphSize(), xCoord + alchemyArray.getLargestGlyphSize(), yCoord + alchemyArray.getLargestGlyphSize(), zCoord + alchemyArray.getLargestGlyphSize());
}
@Override

View file

@ -0,0 +1,26 @@
package com.pahimar.ee3.util;
import com.pahimar.ee3.reference.Reference;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
public class EntityHelper
{
public static NBTTagCompound getCustomEntityData(Entity entity)
{
if (entity != null && entity.getEntityData().hasKey(Reference.MOD_ID.toLowerCase()) && entity.getEntityData().getTag(Reference.MOD_ID.toLowerCase()) instanceof NBTTagCompound)
{
return entity.getEntityData().getCompoundTag(Reference.MOD_ID.toLowerCase());
}
return null;
}
public static void saveCustomEntityData(Entity entity, NBTTagCompound nbtTagCompound)
{
if (entity != null)
{
entity.getEntityData().setTag(Reference.MOD_ID.toLowerCase(), nbtTagCompound);
}
}
}