More glyph work
This commit is contained in:
parent
528e79ac1c
commit
75eeda6cf9
6 changed files with 157 additions and 81 deletions
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
#Sat Dec 28 00:14:08 EST 2013
|
||||
minecraft_version = 1.7.10
|
||||
forge_version = 10.13.1.1222
|
||||
forge_version = 10.13.1.1224
|
||||
mod_version = 0.2
|
||||
|
|
|
@ -8,7 +8,6 @@ public class Glyph implements Comparable<Glyph>
|
|||
private ResourceLocation texture;
|
||||
private String unLocalizedName;
|
||||
private int size;
|
||||
private int rotation;
|
||||
|
||||
private Glyph()
|
||||
{
|
||||
|
@ -21,26 +20,15 @@ public class Glyph implements Comparable<Glyph>
|
|||
}
|
||||
|
||||
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(glyph, size, glyph.rotation);
|
||||
}
|
||||
|
||||
public Glyph(Glyph glyph, int size, int rotation)
|
||||
{
|
||||
this(glyph.texture, glyph.unLocalizedName, size, rotation);
|
||||
this(glyph.texture, glyph.unLocalizedName, size);
|
||||
}
|
||||
|
||||
public ResourceLocation getTexture()
|
||||
|
@ -58,11 +46,6 @@ public class Glyph implements Comparable<Glyph>
|
|||
return size;
|
||||
}
|
||||
|
||||
public int getRotation()
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
if (nbtTagCompound != null)
|
||||
|
@ -93,22 +76,12 @@ public class Glyph implements Comparable<Glyph>
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +91,6 @@ 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)
|
||||
|
@ -131,7 +103,7 @@ public class Glyph implements Comparable<Glyph>
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("texture: %s, unLocalizedName: %s, size: %s, orientation: %s", texture.getResourceDomain() + ":" + texture.getResourcePath(), unLocalizedName, size, rotation);
|
||||
return String.format("texture: %s, unLocalizedName: %s, size: %s", texture.getResourceDomain() + ":" + texture.getResourcePath(), unLocalizedName, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,14 +124,7 @@ public class Glyph implements Comparable<Glyph>
|
|||
{
|
||||
if (this.texture.getResourcePath().equalsIgnoreCase(glyph.getTexture().getResourcePath()))
|
||||
{
|
||||
if (this.size == glyph.size)
|
||||
{
|
||||
return this.rotation - glyph.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.size - glyph.size;
|
||||
}
|
||||
return this.size - glyph.size;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -50,6 +50,18 @@ public class GlyphTextureRegistry
|
|||
}
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation(int index)
|
||||
{
|
||||
if (index >= glyphTextureSortedMap.size() || index < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ResourceLocation[] glyphTextures = glyphTextureSortedMap.keySet().toArray(new ResourceLocation[]{});
|
||||
|
||||
return glyphTextures[index];
|
||||
}
|
||||
|
||||
public Map<ResourceLocation, String> getGlyphs()
|
||||
{
|
||||
return ImmutableMap.copyOf(glyphTextureSortedMap);
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package com.pahimar.ee3.block;
|
||||
|
||||
import com.pahimar.ee3.init.Glyphs;
|
||||
import com.pahimar.ee3.api.Glyph;
|
||||
import com.pahimar.ee3.array.GlyphTextureRegistry;
|
||||
import com.pahimar.ee3.item.ItemChalk;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.reference.RenderIds;
|
||||
import com.pahimar.ee3.settings.ChalkSettings;
|
||||
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
||||
import com.pahimar.ee3.tileentity.TileEntityEE;
|
||||
import com.pahimar.ee3.util.EntityHelper;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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.IBlockAccess;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
|
||||
{
|
||||
|
@ -57,35 +58,17 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
|
|||
return new TileEntityAlchemyArray();
|
||||
}
|
||||
|
||||
@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, 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World world, int x, int y, int z)
|
||||
{
|
||||
return false;
|
||||
// @Override
|
||||
// public boolean canPlaceBlockAt(World world, int x, int y, int z)
|
||||
// {
|
||||
// return super.canPlaceBlockAt(world, x, y, z);
|
||||
}
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// @Override
|
||||
// public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int onBlockPlaced(World world, int x, int y, int z, int sideHit, float hitX, float hitY, float hitZ, int metaData)
|
||||
|
@ -93,6 +76,54 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
|
|||
return sideHit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
|
||||
{
|
||||
((TileEntityEE) world.getTileEntity(x, y, z)).setOrientation(world.getBlockMetadata(x, y, z));
|
||||
|
||||
// TODO: Set rotation
|
||||
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
||||
|
||||
if (world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray && entityLiving instanceof EntityPlayer)
|
||||
{
|
||||
NBTTagCompound customEntityData = EntityHelper.getCustomEntityData(entityLiving);
|
||||
ChalkSettings chalkSettings = new ChalkSettings();
|
||||
chalkSettings.readFromNBT(customEntityData);
|
||||
|
||||
ResourceLocation glyphTexture = GlyphTextureRegistry.getInstance().getResourceLocation(chalkSettings.getIndex());
|
||||
|
||||
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(new Glyph(glyphTexture, GlyphTextureRegistry.getInstance().getGlyphs().get(glyphTexture)), chalkSettings.getSize());
|
||||
|
||||
// TODO: Play a sound when a glyph is added
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int sideHit, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
if (entityPlayer.getCurrentEquippedItem() != null && entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemChalk)
|
||||
{
|
||||
NBTTagCompound customEntityData = EntityHelper.getCustomEntityData(entityPlayer);
|
||||
ChalkSettings chalkSettings = new ChalkSettings();
|
||||
chalkSettings.readFromNBT(customEntityData);
|
||||
|
||||
ResourceLocation glyphTexture = GlyphTextureRegistry.getInstance().getResourceLocation(chalkSettings.getIndex());
|
||||
|
||||
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(new Glyph(glyphTexture, GlyphTextureRegistry.getInstance().getGlyphs().get(glyphTexture)), chalkSettings.getSize());
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
world.getTileEntity(x, y, z).markDirty();
|
||||
|
||||
// TODO: Play a sound when a glyph is added to an array
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
|
||||
{
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package com.pahimar.ee3.client.util;
|
||||
|
||||
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
@ -42,7 +45,6 @@ public class RenderUtils
|
|||
|
||||
public static void drawInWorldTransmutationOverlay(DrawBlockHighlightEvent event, ResourceLocation texture, int size, int rotation)
|
||||
{
|
||||
// TODO: Intelligently render the overlay (whether its new, or part of an existing array)
|
||||
// TODO: Only render glyphs if they can be placed
|
||||
|
||||
double x = event.target.blockX + 0.5F;
|
||||
|
@ -66,6 +68,8 @@ public class RenderUtils
|
|||
|
||||
int chargeLevel = size;
|
||||
ForgeDirection sideHit = ForgeDirection.getOrientation(event.target.sideHit);
|
||||
TileEntity tileEntity = event.player.worldObj.getTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ);
|
||||
LogHelper.info(sideHit);
|
||||
switch (sideHit)
|
||||
{
|
||||
case UP:
|
||||
|
@ -75,6 +79,10 @@ public class RenderUtils
|
|||
xRotate = -1;
|
||||
rotationAngle = (-90 * (rotation + 2)) % 360;
|
||||
facingCorrectionAngle = (-90 * (playerFacing + 2)) % 360;
|
||||
if (tileEntity instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
y -= 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DOWN:
|
||||
|
@ -84,6 +92,10 @@ public class RenderUtils
|
|||
xRotate = 1;
|
||||
rotationAngle = (-90 * (rotation + 2)) % 360;
|
||||
facingCorrectionAngle = (-90 * (playerFacing + 2)) % 360;
|
||||
if (tileEntity instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
y += 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NORTH:
|
||||
|
@ -93,6 +105,10 @@ public class RenderUtils
|
|||
zShift = -0.001f;
|
||||
zRotate = 1;
|
||||
rotationAngle = (-90 * (rotation + 1)) % 360;
|
||||
if (tileEntity instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
z += 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SOUTH:
|
||||
|
@ -101,6 +117,10 @@ public class RenderUtils
|
|||
zShift = 0.001f;
|
||||
zRotate = -1;
|
||||
rotationAngle = (-90 * (rotation + 1)) % 360;
|
||||
if (tileEntity instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
z -= 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EAST:
|
||||
|
@ -109,6 +129,10 @@ public class RenderUtils
|
|||
xShift = 0.001f;
|
||||
yRotate = 1;
|
||||
rotationAngle = (-90 * (rotation + 2)) % 360;
|
||||
if (tileEntity instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
x -= 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WEST:
|
||||
|
@ -117,6 +141,10 @@ public class RenderUtils
|
|||
xShift = -0.001f;
|
||||
yRotate = -1;
|
||||
rotationAngle = (-90 * (rotation + 2)) % 360;
|
||||
if (tileEntity instanceof TileEntityAlchemyArray)
|
||||
{
|
||||
x += 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -13,11 +13,13 @@ import net.minecraft.util.AxisAlignedBB;
|
|||
public class TileEntityAlchemyArray extends TileEntityEE
|
||||
{
|
||||
private AlchemyArray alchemyArray;
|
||||
private int rotation;
|
||||
|
||||
public TileEntityAlchemyArray()
|
||||
{
|
||||
super();
|
||||
alchemyArray = new AlchemyArray();
|
||||
rotation = 0;
|
||||
}
|
||||
|
||||
public AlchemyArray getAlchemyArray()
|
||||
|
@ -25,19 +27,53 @@ public class TileEntityAlchemyArray extends TileEntityEE
|
|||
return alchemyArray;
|
||||
}
|
||||
|
||||
public void addGlyphToAlchemyArray(Glyph glyph)
|
||||
{
|
||||
alchemyArray.addGlyph(glyph);
|
||||
}
|
||||
|
||||
public void addGlyphToAlchemyArray(Glyph glyph, int size)
|
||||
{
|
||||
alchemyArray.addGlyph(new Glyph(glyph, size));
|
||||
}
|
||||
|
||||
public void addGlyphToAlchemyArray(Glyph glyph, int size, int facing)
|
||||
public int getRotation()
|
||||
{
|
||||
alchemyArray.addGlyph(new Glyph(glyph, size, facing));
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(int rotation)
|
||||
{
|
||||
this.rotation = rotation;
|
||||
|
||||
if (this.rotation < 0)
|
||||
{
|
||||
this.rotation = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.rotation = this.rotation % 4;
|
||||
}
|
||||
}
|
||||
|
||||
public void rotate()
|
||||
{
|
||||
rotate(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rotateClockwise true if we should rotate clockwise, false if we rotate counter clockwise
|
||||
*/
|
||||
public void rotate(boolean rotateClockwise)
|
||||
{
|
||||
if (rotateClockwise)
|
||||
{
|
||||
this.rotation = (rotation + 1) % 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.rotation -= 1;
|
||||
|
||||
if (this.rotation < 0)
|
||||
{
|
||||
this.rotation = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,6 +97,8 @@ public class TileEntityAlchemyArray extends TileEntityEE
|
|||
|
||||
NBTTagCompound alchemyArrayTagCompound = nbtTagCompound.getCompoundTag("alchemyArray");
|
||||
alchemyArray = AlchemyArray.readAlchemyArrayFromNBT(alchemyArrayTagCompound);
|
||||
|
||||
rotation = nbtTagCompound.getInteger("rotation");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,6 +109,8 @@ public class TileEntityAlchemyArray extends TileEntityEE
|
|||
NBTTagCompound alchemyArrayTagCompound = new NBTTagCompound();
|
||||
alchemyArray.writeToNBT(alchemyArrayTagCompound);
|
||||
|
||||
nbtTagCompound.setInteger("rotation", rotation);
|
||||
|
||||
nbtTagCompound.setTag("alchemyArray", alchemyArrayTagCompound);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue