Some work on ArmBot (trying to smooth things up a bit)

This commit is contained in:
Brian Ricketts 2013-01-11 22:11:18 -06:00
parent 67a59a6af7
commit 09d4febe13
6 changed files with 129 additions and 30 deletions

View file

@ -1,10 +1,16 @@
package assemblyline.client.render; package assemblyline.client.render;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderEngine;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.registry.RenderingRegistry;
import assemblyline.client.model.ModelArmbot; import assemblyline.client.model.ModelArmbot;
import assemblyline.common.AssemblyLine; import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.armbot.TileEntityArmbot; import assemblyline.common.machine.armbot.TileEntityArmbot;

View file

@ -25,6 +25,7 @@ import assemblyline.common.machine.encoder.BlockEncoder;
import assemblyline.common.machine.encoder.ItemDisk; import assemblyline.common.machine.encoder.ItemDisk;
import assemblyline.common.machine.imprinter.BlockImprinter; import assemblyline.common.machine.imprinter.BlockImprinter;
import assemblyline.common.machine.imprinter.ItemImprinter; import assemblyline.common.machine.imprinter.ItemImprinter;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Init;
@ -36,6 +37,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents") @Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents")
@NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class) @NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
@ -154,4 +156,10 @@ public class AssemblyLine
UETab.setItemStack(new ItemStack(blockConveyorBelt)); UETab.setItemStack(new ItemStack(blockConveyorBelt));
} }
public static void printSidedData(String data)
{
System.out.print(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT ? "[C]" : "[S]");
System.out.println(" " + data);
}
} }

View file

@ -6,6 +6,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Random;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -15,6 +16,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -61,6 +63,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
public float rotationPitch = 0; public float rotationPitch = 0;
public float rotationYaw = 0; public float rotationYaw = 0;
private int ticksSincePower = 0;
/** /**
* An entity that the armbot is grabbed onto. * An entity that the armbot is grabbed onto.
*/ */
@ -72,23 +76,15 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
ElectricityConnections.registerConnector(this, EnumSet.range(ForgeDirection.DOWN, ForgeDirection.EAST)); ElectricityConnections.registerConnector(this, EnumSet.range(ForgeDirection.DOWN, ForgeDirection.EAST));
} }
@Override private void updateCommands(boolean reset, int currentTask)
public void onUpdate()
{ {
if (this.disk != null) if (this.disk != null)
{ {
try if (reset)
{ {
if (this.commandManager.hasTasks()) try
{
if (this.commandManager.getCommands().get(0) instanceof CommandReturn)
{
this.commandManager.clearTasks();
}
}
if (!this.commandManager.hasTasks())
{ {
this.commandManager.clearTasks();
List<String> commands = ItemDisk.getCommands(this.disk); List<String> commands = ItemDisk.getCommands(this.disk);
for (String commandString : commands) for (String commandString : commands)
@ -116,11 +112,63 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.commandManager.addTask(this, newCommand, commandParameters.toArray(new String[0])); this.commandManager.addTask(this, newCommand, commandParameters.toArray(new String[0]));
} }
} }
this.commandManager.setCurrentTask(currentTask);
}
catch (Exception e)
{
e.printStackTrace();
} }
} }
catch (Exception e) else
{ {
e.printStackTrace(); if (this.commandManager.hasTasks())
{
if (this.commandManager.getCommands().get(0) instanceof CommandReturn)
{
this.commandManager.clearTasks();
}
}
if (!this.commandManager.hasTasks())
{
try
{
List<String> commands = ItemDisk.getCommands(this.disk);
for (String commandString : commands)
{
String commandName = commandString.split(" ")[0];
Class<? extends Command> command = Command.getCommand(commandName);
if (command != null)
{
Command newCommand = command.newInstance();
newCommand.world = this.worldObj;
newCommand.tileEntity = this;
List<String> commandParameters = new ArrayList<String>();
for (String param : commandString.split(" "))
{
if (!param.equals(commandName))
{
commandParameters.add(param);
}
}
this.commandManager.addTask(this, newCommand, commandParameters.toArray(new String[0]));
}
}
this.commandManager.setCurrentTask(0);
}
catch (Exception e)
{
e.printStackTrace();
}
}
} }
} }
else else
@ -135,10 +183,15 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{ {
this.commandManager.addTask(this, new CommandReturn()); this.commandManager.addTask(this, new CommandReturn());
} }
this.commandManager.setCurrentTask(0); this.commandManager.setCurrentTask(0);
} }
}
@Override
public void onUpdate()
{
updateCommands(false, -1);
if (this.isRunning()) if (this.isRunning())
{ {
Vector3 handPosition = this.getHandPosition(); Vector3 handPosition = this.getHandPosition();
@ -153,6 +206,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
if (entity instanceof EntityItem) if (entity instanceof EntityItem)
{ {
((EntityItem) entity).delayBeforeCanPickup = 20; ((EntityItem) entity).delayBeforeCanPickup = 20;
((EntityItem) entity).age = 0;
} }
} }
@ -168,11 +222,18 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
if (this.rotationYaw >= 360) if (this.rotationYaw >= 360)
this.rotationYaw -= 360; this.rotationYaw -= 360;
this.ticksSincePower = 0;
}
else
{
this.ticksSincePower++;
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && ticksSincePower <= 20)
this.commandManager.onUpdate();
} }
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 5 == 0) if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 20 == 0)
{ {
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 20); PacketManager.sendPacketToClients(this.getDescriptionPacket());// , this.worldObj, new Vector3(this), 20);
} }
} }
@ -226,16 +287,17 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{ {
ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
DataInputStream dis = new DataInputStream(bis); DataInputStream dis = new DataInputStream(bis);
final int id, x, y, z; int id, x, y, z;
id = dis.readInt(); id = dis.readInt();
x = dis.readInt(); x = dis.readInt();
y = dis.readInt(); y = dis.readInt();
z = dis.readInt(); z = dis.readInt();
this.commandManager.setCurrentTask(dis.readInt()); int curTask = dis.readInt();
NBTTagCompound tag = Packet.readNBTTagCompound(dis); NBTTagCompound tag = Packet.readNBTTagCompound(dis);
readFromNBT(tag); readFromNBT(tag);
updateCommands(true, curTask);
} }
catch (IOException e) catch (IOException e)
{ {

View file

@ -2,6 +2,7 @@ package assemblyline.common.machine.command;
import java.util.HashMap; import java.util.HashMap;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
import assemblyline.common.machine.armbot.TileEntityArmbot; import assemblyline.common.machine.armbot.TileEntityArmbot;
@ -19,6 +20,7 @@ public abstract class Command
* String - Command name. Command - The actual command class. * String - Command name. Command - The actual command class.
*/ */
private static final HashMap<String, Class> COMMANDS = new HashMap<String, Class>(); private static final HashMap<String, Class> COMMANDS = new HashMap<String, Class>();
private static final HashMap<Class, String> REVERSE_LOOKUP = new HashMap<Class, String>();
static static
{ {
@ -33,12 +35,18 @@ public abstract class Command
public static void registerCommand(String command, Class<? extends Command> commandClass) public static void registerCommand(String command, Class<? extends Command> commandClass)
{ {
COMMANDS.put(command, commandClass); COMMANDS.put(command, commandClass);
REVERSE_LOOKUP.put(commandClass, command);
} }
public static Class<? extends Command> getCommand(String command) public static Class<? extends Command> getCommand(String command)
{ {
return COMMANDS.get(command.toLowerCase()); return COMMANDS.get(command.toLowerCase());
} }
public static String getCommandName(Class<? extends Command> command)
{
return REVERSE_LOOKUP.get(command);
}
/** /**
* The amount of ticks this command has been running for. * The amount of ticks this command has been running for.
@ -114,4 +122,9 @@ public abstract class Command
return 0; return 0;
} }
public void writeToNBT(NBTTagCompound taskCompound)
{
}
} }

View file

@ -1,12 +1,11 @@
package assemblyline.common.machine.command; package assemblyline.common.machine.command;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import assemblyline.common.machine.armbot.TileEntityArmbot; import assemblyline.common.machine.armbot.TileEntityArmbot;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
public class CommandManager public class CommandManager
@ -62,8 +61,7 @@ public class CommandManager
} }
/** /**
* Used to register Tasks for a TileEntity, executes onTaskStart for the Task after registering * Used to register Tasks for a TileEntity, executes onTaskStart for the Task after registering it
* it
* *
* @param tileEntity TE instance to register the task for * @param tileEntity TE instance to register the task for
* @param task Task instance to register * @param task Task instance to register
@ -110,4 +108,15 @@ public class CommandManager
{ {
return this.currentTask; return this.currentTask;
} }
public void writeToNBT(NBTTagCompound nbt)
{
NBTTagList taskList = new NBTTagList();
for (int i = 0; i < this.tasks.size(); i++)
{
NBTTagCompound taskCompound = new NBTTagCompound();
this.tasks.get(i).writeToNBT(taskCompound);
taskList.appendTag(taskCompound);
}
}
} }

View file

@ -1,5 +1,6 @@
package assemblyline.common.machine.command; package assemblyline.common.machine.command;
import assemblyline.common.AssemblyLine;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -15,7 +16,9 @@ public class CommandRotate extends Command
@Override @Override
public void onTaskStart() public void onTaskStart()
{ {
super.onTaskStart();
this.ticks = 0;
if (this.getArg(0) == null) if (this.getArg(0) == null)
{ {
this.targetRotation = this.tileEntity.rotationYaw + 90; this.targetRotation = this.tileEntity.rotationYaw + 90;
@ -25,11 +28,11 @@ public class CommandRotate extends Command
this.targetRotation = this.tileEntity.rotationYaw + this.getIntArg(0); this.targetRotation = this.tileEntity.rotationYaw + this.getIntArg(0);
} }
while (this.targetRotation > 360) while (this.targetRotation >= 360)
{ {
this.targetRotation -= 360; this.targetRotation -= 360;
} }
while (this.targetRotation < -360) while (this.targetRotation <= -360)
{ {
this.targetRotation += 360; this.targetRotation += 360;
} }
@ -55,8 +58,6 @@ public class CommandRotate extends Command
{ {
this.tileEntity.rotationYaw += ROTATION_SPEED; this.tileEntity.rotationYaw += ROTATION_SPEED;
} }
return true;
} }
if (this.ticks < 80) { return true; } if (this.ticks < 80) { return true; }