Holy moley more glyph work

This commit is contained in:
Pahimar 2014-10-09 16:13:06 -04:00
parent c141fe39bc
commit 528e79ac1c
15 changed files with 507 additions and 309 deletions

View file

@ -1,8 +1,10 @@
package com.pahimar.ee3.api;
import com.google.common.collect.ImmutableSortedSet;
import net.minecraft.entity.EntityLiving;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import java.util.Collection;
import java.util.Set;
@ -64,6 +66,20 @@ public class AlchemyArray implements Comparable<AlchemyArray>
return largestGlyphSize;
}
/**
* TODO: Document this method
*
* @param entityLiving
* @param world
* @param x
* @param y
* @param z
*/
public void activateArray(EntityLiving entityLiving, World world, int x, int y, int z)
{
}
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
if (nbtTagCompound != null && nbtTagCompound.hasKey("glyphs"))
@ -145,6 +161,7 @@ public class AlchemyArray implements Comparable<AlchemyArray>
@Override
public int compareTo(AlchemyArray alchemyArray)
{
// TODO: Modify this to check that all glyphs have the same rotation
if (this.glyphs.size() == alchemyArray.glyphs.size())
{
for (Glyph glyph : this.glyphs)

View file

@ -14,7 +14,9 @@ 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.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
{
@ -72,6 +74,19 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
}
}
@Override
public boolean canPlaceBlockAt(World world, int x, int y, int z)
{
return false;
// 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 int onBlockPlaced(World world, int x, int y, int z, int sideHit, float hitX, float hitY, float hitZ, int metaData)
{

View file

@ -1,11 +1,12 @@
package com.pahimar.ee3.client.handler;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.client.util.RenderUtils;
import com.pahimar.ee3.item.*;
import com.pahimar.ee3.reference.ToolMode;
import com.pahimar.ee3.util.EntityHelper;
import com.pahimar.ee3.settings.ChalkSettings;
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;
@ -14,9 +15,9 @@ 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.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@ -215,37 +216,8 @@ public class DrawBlockHighlightEventHandler
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));
ChalkSettings chalkSettings = EquivalentExchange3.proxy.getClientProxy().chalkSettings;
ResourceLocation[] textures = GlyphTextureRegistry.getInstance().getGlyphs().keySet().toArray(new ResourceLocation[]{});
RenderUtils.drawInWorldTransmutationOverlay(event, textures[chalkSettings.getIndex()], chalkSettings.getSize(), chalkSettings.getRotation());
}
}

View file

@ -6,7 +6,12 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class RenderUtils
{
@ -34,4 +39,120 @@ public class RenderUtils
tessellator.addVertexWithUV(x, y, zLevel, icon.getMinU(), icon.getMinV());
tessellator.draw();
}
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;
double y = event.target.blockY + 0.5F;
double z = event.target.blockZ + 0.5F;
double iPX = event.player.prevPosX + (event.player.posX - event.player.prevPosX) * event.partialTicks;
double iPY = event.player.prevPosY + (event.player.posY - event.player.prevPosY) * event.partialTicks;
double iPZ = event.player.prevPosZ + (event.player.posZ - event.player.prevPosZ) * event.partialTicks;
float xScale, yScale, zScale;
float xShift, yShift, zShift;
float xRotate, yRotate, zRotate;
int zCorrection = 1;
int rotationAngle = 0;
int playerFacing = MathHelper.floor_double(event.player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
int facingCorrectionAngle = 0;
xScale = yScale = zScale = 1;
xShift = yShift = zShift = 0;
xRotate = yRotate = zRotate = 0;
int chargeLevel = size;
ForgeDirection sideHit = ForgeDirection.getOrientation(event.target.sideHit);
switch (sideHit)
{
case UP:
{
xScale = zScale = chargeLevel;
yShift = 0.001f;
xRotate = -1;
rotationAngle = (-90 * (rotation + 2)) % 360;
facingCorrectionAngle = (-90 * (playerFacing + 2)) % 360;
break;
}
case DOWN:
{
xScale = zScale = chargeLevel;
yShift = -0.001f;
xRotate = 1;
rotationAngle = (-90 * (rotation + 2)) % 360;
facingCorrectionAngle = (-90 * (playerFacing + 2)) % 360;
break;
}
case NORTH:
{
xScale = yScale = chargeLevel;
zCorrection = -1;
zShift = -0.001f;
zRotate = 1;
rotationAngle = (-90 * (rotation + 1)) % 360;
break;
}
case SOUTH:
{
xScale = yScale = chargeLevel;
zShift = 0.001f;
zRotate = -1;
rotationAngle = (-90 * (rotation + 1)) % 360;
break;
}
case EAST:
{
yScale = zScale = chargeLevel;
xShift = 0.001f;
yRotate = 1;
rotationAngle = (-90 * (rotation + 2)) % 360;
break;
}
case WEST:
{
yScale = zScale = chargeLevel;
xShift = -0.001f;
yRotate = -1;
rotationAngle = (-90 * (rotation + 2)) % 360;
break;
}
default:
break;
}
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glPushMatrix();
GL11.glTranslated(-iPX + x + xShift, -iPY + y + yShift, -iPZ + z + zShift);
GL11.glScalef(1F * xScale, 1F * yScale, 1F * zScale);
GL11.glRotatef(rotationAngle, sideHit.offsetX, sideHit.offsetY, sideHit.offsetZ);
GL11.glRotatef(facingCorrectionAngle, sideHit.offsetX, sideHit.offsetY, sideHit.offsetZ);
GL11.glRotatef(90, xRotate, yRotate, zRotate);
GL11.glTranslated(0, 0, 0.5f * zCorrection);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
renderQuad(texture);
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDepthMask(true);
}
public static void renderQuad(ResourceLocation texture)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(texture);
Tessellator tessellator = Tessellator.instance;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1, 1, 1, 1);
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(-0.5D, 0.5D, 0F, 0, 1);
tessellator.addVertexWithUV(0.5D, 0.5D, 0F, 1, 1);
tessellator.addVertexWithUV(0.5D, -0.5D, 0F, 1, 0);
tessellator.addVertexWithUV(-0.5D, -0.5D, 0F, 0, 0);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
}

View file

@ -1,10 +1,11 @@
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.MessageChalkSettings;
import com.pahimar.ee3.network.message.MessageSyncEnergyValues;
import com.pahimar.ee3.reference.Reference;
import com.pahimar.ee3.settings.ChalkSettings;
import com.pahimar.ee3.util.EntityHelper;
import com.pahimar.ee3.util.LogHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -61,62 +62,28 @@ public class PlayerEventHandler
PacketHandler.INSTANCE.sendTo(new MessageSyncEnergyValues(EnergyValueRegistry.getInstance()), (EntityPlayerMP) event.player);
}
@SubscribeEvent
public void syncChalkSettingsOnLogin(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(event.player);
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(playerCustomData);
PacketHandler.INSTANCE.sendTo(new MessageChalkSettings(chalkSettings), (EntityPlayerMP) event.player);
}
@SubscribeEvent
public void initPlayerCustomData(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
{
if (event.player != null)
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(event.player);
NBTTagCompound chalkCustomData;
// Glyph Settings
int index = 0;
int size = 1;
int rotation = 0;
// Chalk Settings
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(playerCustomData);
chalkSettings.writeToNBT(playerCustomData);
if (!playerCustomData.hasNoTags() && playerCustomData.hasKey("chalk_settings") && playerCustomData.getTag("chalk_settings").getId() == (byte) 10)
{
chalkCustomData = playerCustomData.getCompoundTag("chalk_settings");
if (chalkCustomData.hasKey("index"))
{
index = chalkCustomData.getInteger("index");
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
{
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

@ -14,7 +14,6 @@ public class Glyphs
public static final Glyph LINE = new Glyph(Textures.Glyph.LINE, Names.Glyphs.LINE);
public static final Glyph CIRCLE = new Glyph(Textures.Glyph.CIRCLE, Names.Glyphs.CIRCLE);
public static final Glyph TRIANGLE = new Glyph(Textures.Glyph.TRIANGLE, Names.Glyphs.TRIANGLE);
public static final Glyph INVERTED_TRIANGLE = new Glyph(Textures.Glyph.INVERTED_TRIANGLE, Names.Glyphs.INVERTED_TRIANGLE);
public static final Glyph SQUARE = new Glyph(Textures.Glyph.SQUARE, Names.Glyphs.SQUARE);
public static final Glyph DIAMOND = new Glyph(Textures.Glyph.DIAMOND, Names.Glyphs.DIAMOND);
public static final Glyph PENTAGON = new Glyph(Textures.Glyph.PENTAGON, Names.Glyphs.PENTAGON);
@ -29,7 +28,6 @@ public class Glyphs
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);

View file

@ -1,19 +1,20 @@
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.network.PacketHandler;
import com.pahimar.ee3.network.message.MessageChalkSettings;
import com.pahimar.ee3.reference.Key;
import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.reference.Sounds;
import com.pahimar.ee3.util.*;
import com.pahimar.ee3.settings.ChalkSettings;
import com.pahimar.ee3.util.EntityHelper;
import com.pahimar.ee3.util.IKeyBound;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class ItemChalk extends ItemEE implements IKeyBound, IChargeable, IOverlayItem
public class ItemChalk extends ItemEE implements IKeyBound
{
public ItemChalk()
{
@ -76,12 +77,9 @@ public class ItemChalk extends ItemEE implements IKeyBound, IChargeable, IOverla
/**
* Called to actually place the block, after the location is determined and all permission checks have been made.
*
* @param stack
* The item stack that was used to place the block. This can be changed inside the method.
* @param player
* The player who is placing the block. Can be null if the block is not being placed by a player.
* @param side
* The side the player (or machine) right-clicked on.
* @param stack The item stack that was used to place the block. This can be changed inside the method.
* @param player The player who is placing the block. Can be null if the block is not being placed by a player.
* @param side The side the player (or machine) right-clicked on.
*/
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
@ -103,235 +101,50 @@ 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"))
if (key != Key.UNKNOWN)
{
index = chalkSettings.getInteger("index");
}
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(entityPlayer);
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(playerCustomData);
if (chalkSettings.hasKey("size"))
{
size = chalkSettings.getInteger("size");
}
if (key == Key.CHARGE)
{
if (!entityPlayer.isSneaking())
if (key == Key.CHARGE)
{
// 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
{
if (getChargeLevel(itemStack) == 0)
if (!entityPlayer.isSneaking())
{
NetworkSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
chalkSettings.incrementSize();
}
else
{
decreaseChargeLevel(itemStack);
NetworkSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
chalkSettings.decrementSize();
}
}
}
else if (key == Key.TOGGLE)
{
entityPlayer.openGui(EquivalentExchange3.instance, GUIs.SYMBOL_SELECTION.ordinal(), entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
}
}
@Override
public short getMaxChargeLevel()
{
return 6;
}
@Override
public short getChargeLevel(ItemStack itemStack)
{
return NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL);
}
@Override
public void setChargeLevel(ItemStack itemStack, short chargeLevel)
{
if (chargeLevel <= this.getMaxChargeLevel())
{
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, chargeLevel);
}
}
@Override
public void increaseChargeLevel(ItemStack itemStack)
{
if (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) < this.getMaxChargeLevel())
{
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, (short) (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) + 1));
}
}
@Override
public void decreaseChargeLevel(ItemStack itemStack)
{
if (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) > 0)
{
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())
else if (key == Key.TOGGLE)
{
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"))
if (!entityPlayer.isSneaking())
{
this.index = chalkSettings.getInteger("index");
if (this.index < 0 || this.index >= GlyphTextureRegistry.getInstance().getGlyphs().size())
{
this.index = 0;
}
chalkSettings.incrementIndex();
}
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;
chalkSettings.decrementIndex();
}
}
else
else if (key == Key.RELEASE)
{
this.index = 0;
this.size = 1;
this.rotation = 0;
if (!entityPlayer.isSneaking())
{
chalkSettings.rotateClockwise();
}
else
{
chalkSettings.rotateCounterClockwise();
}
}
}
@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);
chalkSettings.writeToNBT(playerCustomData);
EntityHelper.saveCustomEntityData(entityPlayer, playerCustomData);
PacketHandler.INSTANCE.sendTo(new MessageChalkSettings(chalkSettings), (EntityPlayerMP) entityPlayer);
}
}
}

View file

@ -21,5 +21,6 @@ public class PacketHandler
INSTANCE.registerMessage(MessageSyncEnergyValues.class, MessageSyncEnergyValues.class, 6, Side.CLIENT);
INSTANCE.registerMessage(MessageSetEnergyValue.class, MessageSetEnergyValue.class, 7, Side.CLIENT);
INSTANCE.registerMessage(MessageTileEntityAlchemyArray.class, MessageTileEntityAlchemyArray.class, 8, Side.CLIENT);
INSTANCE.registerMessage(MessageChalkSettings.class, MessageChalkSettings.class, 9, Side.CLIENT);
}
}

View file

@ -0,0 +1,70 @@
package com.pahimar.ee3.network.message;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.settings.ChalkSettings;
import com.pahimar.ee3.util.LogHelper;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class MessageChalkSettings implements IMessage, IMessageHandler<MessageChalkSettings, IMessage>
{
private int index, size, rotation;
public MessageChalkSettings()
{
}
public MessageChalkSettings(ChalkSettings chalkSettings)
{
this.index = chalkSettings.getIndex();
this.size = chalkSettings.getSize();
this.rotation = chalkSettings.getRotation();
}
/**
* Convert from the supplied buffer into your specific message type
*
* @param buf
*/
@Override
public void fromBytes(ByteBuf buf)
{
this.index = buf.readInt();
this.size = buf.readInt();
this.rotation = buf.readInt();
}
/**
* Deconstruct your message into the supplied byte buffer
*
* @param buf
*/
@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(this.index);
buf.writeInt(this.size);
buf.writeInt(this.rotation);
}
/**
* Called when a message is received of the appropriate type. You can optionally return a reply message, or null if no reply
* is needed.
*
* @param message The message
* @param ctx
* @return an optional return message
*/
@Override
public IMessage onMessage(MessageChalkSettings message, MessageContext ctx)
{
EquivalentExchange3.proxy.getClientProxy().chalkSettings = new ChalkSettings(message.index, message.size, message.rotation);
LogHelper.info(String.format("index: %s, size: %s, rotation: %s", EquivalentExchange3.proxy.getClientProxy().chalkSettings.getIndex(), EquivalentExchange3.proxy.getClientProxy().chalkSettings.getSize(), EquivalentExchange3.proxy.getClientProxy().chalkSettings.getRotation()));
return null;
}
}

View file

@ -10,6 +10,7 @@ import com.pahimar.ee3.client.settings.Keybindings;
import com.pahimar.ee3.client.util.ClientSoundHelper;
import com.pahimar.ee3.init.ModBlocks;
import com.pahimar.ee3.reference.RenderIds;
import com.pahimar.ee3.settings.ChalkSettings;
import com.pahimar.ee3.tileentity.*;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
@ -20,6 +21,8 @@ import net.minecraftforge.common.MinecraftForge;
public class ClientProxy extends CommonProxy
{
public ChalkSettings chalkSettings = new ChalkSettings();
@Override
public void registerEventHandlers()
{
@ -45,6 +48,12 @@ public class ClientProxy extends CommonProxy
ClientSoundHelper.playSound(soundName, xCoord, yCoord, zCoord, volume, pitch);
}
@Override
public ClientProxy getClientProxy()
{
return this;
}
@Override
public void initRenderingAndTextures()
{

View file

@ -2,6 +2,8 @@ package com.pahimar.ee3.proxy;
public interface IProxy
{
public abstract ClientProxy getClientProxy();
public abstract void registerTileEntities();
public abstract void initRenderingAndTextures();

View file

@ -2,6 +2,12 @@ package com.pahimar.ee3.proxy;
public class ServerProxy extends CommonProxy
{
@Override
public ClientProxy getClientProxy()
{
return null;
}
@Override
public void initRenderingAndTextures()
{

View file

@ -61,7 +61,6 @@ public final class Textures
public static final ResourceLocation LINE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transLine.png");
public static final ResourceLocation CIRCLE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transCircle.png");
public static final ResourceLocation TRIANGLE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transTriangle.png");
public static final ResourceLocation INVERTED_TRIANGLE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transInvertedTriangle.png");
public static final ResourceLocation SQUARE = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transSquare.png");
public static final ResourceLocation DIAMOND = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transDiamond.png");
public static final ResourceLocation PENTAGON = ResourceLocationHelper.getResourceLocation(SYMBOL_TEXTURE_LOCATION + "transPentagon.png");

View file

@ -0,0 +1,208 @@
package com.pahimar.ee3.settings;
import com.pahimar.ee3.array.GlyphTextureRegistry;
import com.pahimar.ee3.util.INBTTaggable;
import net.minecraft.nbt.NBTTagCompound;
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)
{
this.index = index;
if (this.index < 0)
{
this.index = 0;
}
else if (this.index >= GlyphTextureRegistry.getInstance().getGlyphs().size())
{
this.index = GlyphTextureRegistry.getInstance().getGlyphs().size() - 1;
}
}
public void incrementIndex()
{
index += 1;
if (index >= GlyphTextureRegistry.getInstance().getGlyphs().size())
{
index = 0;
}
}
public void decrementIndex()
{
index -= 1;
if (index < 0)
{
this.index = GlyphTextureRegistry.getInstance().getGlyphs().size() - 1;
}
}
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 void incrementSize()
{
if (size < MAX_SIZE)
{
size += 1;
}
}
public void decrementSize()
{
if (size > 1)
{
size -= 1;
}
}
public int getRotation()
{
return rotation;
}
public void setRotation(int rotation)
{
if (rotation < 0)
{
this.rotation = 0;
}
else
{
this.rotation = rotation % 4;
}
}
public void rotateClockwise()
{
this.rotation = (rotation + 1) % 4;
}
public void rotateCounterClockwise()
{
this.rotation -= 1;
if (this.rotation < 0)
{
this.rotation = 3;
}
}
@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 = 1;
}
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);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB