More glyph work

This commit is contained in:
Pahimar 2014-10-07 23:11:54 -04:00
parent 6e727a5a7f
commit c141fe39bc
5 changed files with 260 additions and 26 deletions

View file

@ -115,7 +115,7 @@ public class EquivalentExchange3
if (EnergyValueRegistry.getInstance().getShouldRegenNextRestart())
{
File dataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.MOD_ID.toLowerCase());
File energyValueRegistryFile = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
File energyValueRegistryFile = new File(dataDirectory, SerializationHelper.getModListMD5() + "." + Reference.MOD_ID.toLowerCase());
if (energyValueRegistryFile.exists())
{

View file

@ -1,8 +1,11 @@
package com.pahimar.ee3.client.handler;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.item.*;
import com.pahimar.ee3.reference.ToolMode;
import com.pahimar.ee3.util.EntityHelper;
import com.pahimar.ee3.util.IModalTool;
import com.pahimar.ee3.util.LogHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -11,6 +14,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
@ -49,7 +53,7 @@ public class DrawBlockHighlightEventHandler
}
else if (event.currentItem.getItem() instanceof ItemChalk)
{
drawGlyphOverlay(event);
}
}
}
@ -208,4 +212,40 @@ public class DrawBlockHighlightEventHandler
GL11.glDisable(GL11.GL_BLEND);
}
}
private void drawGlyphOverlay(DrawBlockHighlightEvent event)
{
NBTTagCompound customData = EntityHelper.getCustomEntityData(event.player);
int index = 0;
int size = 1;
int rotation = 0;
if (customData.hasKey("chalk_settings"))
{
NBTTagCompound chalkSettings = customData.getCompoundTag("chalk_settings");
if (chalkSettings.hasKey("index"))
{
index = chalkSettings.getInteger("index");
if (index >= GlyphTextureRegistry.getInstance().getGlyphs().size())
{
index = 0;
}
}
if (chalkSettings.hasKey("size"))
{
size = chalkSettings.getInteger("size");
}
if (chalkSettings.hasKey("rotation"))
{
rotation = chalkSettings.getInteger("rotation");
}
}
LogHelper.info(String.format("index: %s, size: %s, rotation: %s", index, size, rotation));
}
}

View file

@ -1,5 +1,6 @@
package com.pahimar.ee3.handler;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.network.message.MessageSyncEnergyValues;
@ -65,27 +66,58 @@ public class PlayerEventHandler
{
if (event.player != null)
{
if (EntityHelper.getCustomEntityData(event.player) == null)
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(event.player);
NBTTagCompound chalkCustomData;
// Glyph Settings
int index = 0;
int size = 1;
int rotation = 0;
if (!playerCustomData.hasNoTags() && playerCustomData.hasKey("chalk_settings") && playerCustomData.getTag("chalk_settings").getId() == (byte) 10)
{
NBTTagCompound playerCustomData = new NBTTagCompound();
chalkCustomData = playerCustomData.getCompoundTag("chalk_settings");
NBTTagCompound glyphCustomData = new NBTTagCompound();
glyphCustomData.setInteger("index", 0);
glyphCustomData.setInteger("size", 1);
glyphCustomData.setInteger("rotation", 0);
playerCustomData.setTag("chalkSettings", glyphCustomData);
if (chalkCustomData.hasKey("index"))
{
index = chalkCustomData.getInteger("index");
EntityHelper.saveCustomEntityData(event.player, playerCustomData);
if (index < 0 || index > GlyphTextureRegistry.getInstance().getGlyphs().size())
{
index = 0;
}
}
if (chalkCustomData.hasKey("size"))
{
size = chalkCustomData.getInteger("size");
if (size < 1 || size > 6)
{
size = 1;
}
}
if (chalkCustomData.hasKey("rotation"))
{
rotation = chalkCustomData.getInteger("rotation");
if (rotation < 0 || rotation > 3)
{
rotation = 0;
}
}
}
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())));
}
chalkCustomData = new NBTTagCompound();
}
chalkCustomData.setInteger("index", index);
chalkCustomData.setInteger("size", size);
chalkCustomData.setInteger("rotation", rotation);
playerCustomData.setTag("chalk_settings", chalkCustomData);
EntityHelper.saveCustomEntityData(event.player, playerCustomData);
}
}
}

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.init.ModBlocks;
import com.pahimar.ee3.reference.GUIs;
import com.pahimar.ee3.reference.Key;
@ -9,6 +10,7 @@ import com.pahimar.ee3.reference.Sounds;
import com.pahimar.ee3.util.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class ItemChalk extends ItemEE implements IKeyBound, IChargeable, IOverlayItem
@ -101,19 +103,36 @@ public class ItemChalk extends ItemEE implements IKeyBound, IChargeable, IOverla
@Override
public void doKeyBindingAction(EntityPlayer entityPlayer, ItemStack itemStack, Key key)
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(entityPlayer);
NBTTagCompound chalkSettings = playerCustomData.getCompoundTag("chalk_settings");
int index = 0;
int size = 1;
int rotation = 0;
if (chalkSettings.hasKey("index"))
{
index = chalkSettings.getInteger("index");
}
if (chalkSettings.hasKey("size"))
{
size = chalkSettings.getInteger("size");
}
if (key == Key.CHARGE)
{
if (!entityPlayer.isSneaking())
{
if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
{
NetworkSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
}
else
{
increaseChargeLevel(itemStack);
NetworkSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
}
// if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
// {
// NetworkSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
// }
// else
// {
// increaseChargeLevel(itemStack);
// NetworkSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
// }
}
else
{
@ -172,4 +191,147 @@ public class ItemChalk extends ItemEE implements IKeyBound, IChargeable, IOverla
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, (short) (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) - 1));
}
}
public class ChalkSettings implements INBTTaggable
{
private int index;
private int size;
private int rotation;
private final int MAX_SIZE = 6;
public ChalkSettings()
{
this(0, 1, 0);
}
public ChalkSettings(int index, int size, int rotation)
{
this.index = index;
this.size = size;
this.rotation = rotation;
}
public int getIndex()
{
return index;
}
public void setIndex(int index)
{
if (index < 0 || index >= GlyphTextureRegistry.getInstance().getGlyphs().size())
{
this.index = 0;
}
else
{
this.index = index;
}
}
public int getSize()
{
return size;
}
public void setSize(int size)
{
if (size < 1)
{
this.size = 1;
}
else if (size > MAX_SIZE)
{
this.size = MAX_SIZE;
}
else
{
this.size = size;
}
}
public int getRotation()
{
return rotation;
}
public void setRotation(int rotation)
{
// TODO: Pick up here in the morning
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
if (nbtTagCompound != null && nbtTagCompound.hasKey("chalk_settings") && nbtTagCompound.getTag("chalk_settings").getId() == (byte) 10)
{
NBTTagCompound chalkSettings = nbtTagCompound.getCompoundTag("chalk_settings");
if (chalkSettings.hasKey("index"))
{
this.index = chalkSettings.getInteger("index");
if (this.index < 0 || this.index >= GlyphTextureRegistry.getInstance().getGlyphs().size())
{
this.index = 0;
}
}
else
{
this.index = 0;
}
if (chalkSettings.hasKey("size"))
{
this.size = chalkSettings.getInteger("size");
if (this.size < 1)
{
this.size = 0;
}
else if (this.size > MAX_SIZE)
{
this.size = MAX_SIZE;
}
}
else
{
this.size = 1;
}
if (chalkSettings.hasKey("rotation"))
{
this.rotation = chalkSettings.getInteger("rotation");
if (this.rotation < 0)
{
this.rotation = 0;
}
else
{
this.rotation = this.rotation % 4;
}
}
else
{
this.rotation = 0;
}
}
else
{
this.index = 0;
this.size = 1;
this.rotation = 0;
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
NBTTagCompound chalkSettings = new NBTTagCompound();
chalkSettings.setInteger("index", index);
chalkSettings.setInteger("size", size);
chalkSettings.setInteger("rotation", rotation);
nbtTagCompound.setTag("chalk_settings", chalkSettings);
}
}
}

View file

@ -13,7 +13,7 @@ public class EntityHelper
return entity.getEntityData().getCompoundTag(Reference.MOD_ID.toLowerCase());
}
return null;
return new NBTTagCompound();
}
public static void saveCustomEntityData(Entity entity, NBTTagCompound nbtTagCompound)