More work on Armbot
This commit is contained in:
parent
f2a0867399
commit
67a59a6af7
9 changed files with 99 additions and 79 deletions
|
@ -1 +1 @@
|
|||
50
|
||||
51
|
||||
|
|
1
info.txt
1
info.txt
|
@ -44,3 +44,4 @@ Minecraft 1.4.5
|
|||
@. AssemblyLine_v0.2.3.48.jar AssemblyLine_v0.2.3.48_api.zip
|
||||
@ AssemblyLine_v0.2.3.49.jar AssemblyLine_v0.2.3.49_api.zip
|
||||
@ AssemblyLine_v0.2.3.50.jar AssemblyLine_v0.2.3.50_api.zip
|
||||
@ AssemblyLine_v0.2.3.51.jar AssemblyLine_v0.2.3.51_api.zip
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package assemblyline.common.machine.armbot;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
@ -12,7 +15,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet132TileEntityData;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -22,6 +24,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
import universalelectricity.prefab.TranslationHelper;
|
||||
import universalelectricity.prefab.multiblock.IMultiBlock;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.machine.TileEntityAssemblyNetwork;
|
||||
import assemblyline.common.machine.command.Command;
|
||||
|
@ -33,6 +36,7 @@ import assemblyline.common.machine.encoder.ItemDisk;
|
|||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IJouleStorage
|
||||
|
@ -82,6 +86,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
this.commandManager.clearTasks();
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.commandManager.hasTasks())
|
||||
{
|
||||
List<String> commands = ItemDisk.getCommands(this.disk);
|
||||
|
@ -130,6 +135,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
{
|
||||
this.commandManager.addTask(this, new CommandReturn());
|
||||
}
|
||||
|
||||
this.commandManager.setCurrentTask(0);
|
||||
}
|
||||
|
||||
if (this.isRunning())
|
||||
|
@ -142,14 +149,16 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
entity.motionX = 0;
|
||||
entity.motionY = 0;
|
||||
entity.motionZ = 0;
|
||||
|
||||
if (entity instanceof EntityItem)
|
||||
{
|
||||
((EntityItem) entity).delayBeforeCanPickup = 20;
|
||||
}
|
||||
}
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
{
|
||||
this.commandManager.onUpdate();
|
||||
}
|
||||
this.commandManager.onUpdate();
|
||||
|
||||
// keep it within [0, 360) so ROTATE commands work properly
|
||||
// keep it within 0 - 360 degrees so ROTATE commands work properly
|
||||
if (this.rotationPitch <= -360)
|
||||
this.rotationPitch += 360;
|
||||
if (this.rotationPitch >= 360)
|
||||
|
@ -161,10 +170,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
|
||||
}
|
||||
|
||||
// Simulates smoothness on client side
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 5 == 0)
|
||||
{
|
||||
this.commandManager.onUpdate();
|
||||
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,8 +194,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
delta.x = Math.sin(Math.toRadians(-this.rotationYaw)) * dH;
|
||||
delta.z = Math.cos(Math.toRadians(-this.rotationYaw)) * dH;
|
||||
position.add(delta);
|
||||
|
||||
this.worldObj.spawnParticle("smoke", position.x, position.y, position.z, 0, 0, 0);
|
||||
// TODO: Use Smoke Spawning to Determine Hand Calculation Position. Delete when done
|
||||
// developing this part.
|
||||
// this.worldObj.spawnParticle("smoke", position.x, position.y, position.z, 0, 0, 0);
|
||||
return position;
|
||||
}
|
||||
|
||||
|
@ -202,20 +211,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
writeToNBT(nbt);
|
||||
Packet132TileEntityData data = new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 0, nbt);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(INetworkManager netManager, Packet132TileEntityData packet)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
{
|
||||
this.xCoord = packet.xPosition;
|
||||
this.yCoord = packet.yPosition;
|
||||
this.zCoord = packet.zPosition;
|
||||
readFromNBT(packet.customParam1);
|
||||
}
|
||||
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.commandManager.getCurrentTask(), nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,12 +220,29 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
/*
|
||||
* if (packetType == PACKET_COMMANDS) { String commandString = dataStream.readUTF();
|
||||
* String[] commands = commandString.split("|");
|
||||
*
|
||||
* }
|
||||
*/
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
try
|
||||
{
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
|
||||
DataInputStream dis = new DataInputStream(bis);
|
||||
final int id, x, y, z;
|
||||
|
||||
id = dis.readInt();
|
||||
x = dis.readInt();
|
||||
y = dis.readInt();
|
||||
z = dis.readInt();
|
||||
this.commandManager.setCurrentTask(dis.readInt());
|
||||
|
||||
NBTTagCompound tag = Packet.readNBTTagCompound(dis);
|
||||
readFromNBT(tag);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
FMLLog.severe("Failed to receive packet for Armbot");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -351,9 +364,14 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
{
|
||||
this.disk = ItemStack.loadItemStackFromNBT(diskNBT);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.disk = null;
|
||||
}
|
||||
|
||||
this.rotationYaw = nbt.getFloat("yaw");
|
||||
this.rotationPitch = nbt.getFloat("pitch");
|
||||
this.commandManager.setCurrentTask(nbt.getInteger("currentTask"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -374,6 +392,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
nbt.setTag("disk", diskNBT);
|
||||
nbt.setFloat("yaw", this.rotationYaw);
|
||||
nbt.setFloat("pitch", this.rotationPitch);
|
||||
nbt.setInteger("currentTask", this.commandManager.getCurrentTask());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -432,6 +451,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
@Override
|
||||
public void onInventoryChanged()
|
||||
{
|
||||
this.commandManager.setCurrentTask(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,7 +59,7 @@ public abstract class Command
|
|||
* Called by the TaskManager to propagate tick updates
|
||||
*
|
||||
* @param ticks The amount of ticks this task has been running
|
||||
* @return false if the task is finished and can be removed, true otherwise
|
||||
* @return false if the task is finished and can be continued, true otherwise
|
||||
*/
|
||||
protected boolean doTask()
|
||||
{
|
||||
|
|
|
@ -14,7 +14,6 @@ public class CommandDrop extends Command
|
|||
|
||||
// TODO: Animate Armbot to move down and drop all items.
|
||||
this.tileEntity.grabbedEntities.clear();
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.List;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import assemblyline.common.machine.armbot.TileEntityArmbot;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* Used by arms to search for entities in a region
|
||||
|
@ -14,7 +14,7 @@ import assemblyline.common.machine.armbot.TileEntityArmbot;
|
|||
public class CommandGrab extends Command
|
||||
{
|
||||
|
||||
public static final int radius = 1;
|
||||
public static final float radius = 0.5f;
|
||||
|
||||
/**
|
||||
* The item to be collected.
|
||||
|
@ -32,7 +32,8 @@ public class CommandGrab extends Command
|
|||
{
|
||||
super.doTask();
|
||||
|
||||
List<Entity> found = this.tileEntity.worldObj.getEntitiesWithinAABB(entityToInclude, AxisAlignedBB.getBoundingBox(tileEntity.xCoord - radius, tileEntity.yCoord - radius, tileEntity.zCoord - radius, tileEntity.xCoord + radius, tileEntity.yCoord + radius, tileEntity.zCoord + radius));
|
||||
Vector3 serachPosition = this.tileEntity.getHandPosition();
|
||||
List<Entity> found = this.world.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(serachPosition.x - radius, serachPosition.y - radius, serachPosition.z - radius, serachPosition.x + radius, serachPosition.y + radius, serachPosition.z + radius));
|
||||
|
||||
if (found != null && found.size() > 0)
|
||||
{
|
||||
|
|
|
@ -27,35 +27,28 @@ public class CommandManager
|
|||
*/
|
||||
try
|
||||
{
|
||||
/*
|
||||
* Iterator<Command> iter = tasks.iterator();
|
||||
*
|
||||
* while (iter.hasNext()) { task = iter.next();
|
||||
*
|
||||
* if (task.getTickInterval() > 0) { if (this.ticks % task.getTickInterval() == 0) { if
|
||||
* (!task.doTask()) { task.onTaskEnd(); iter.remove(); }
|
||||
*
|
||||
* break; } } }
|
||||
*/
|
||||
if (this.tasks != null && this.tasks.size() > 0)
|
||||
if (this.tasks.size() > 0)
|
||||
{
|
||||
if (this.currentTask >= this.tasks.size())
|
||||
this.currentTask = 0;
|
||||
if (this.currentTask < 0)
|
||||
this.currentTask = 0;
|
||||
|
||||
Command task = this.tasks.get(this.currentTask);
|
||||
|
||||
if (this.currentTask != this.lastTask)
|
||||
if (this.currentTask < this.tasks.size())
|
||||
{
|
||||
this.lastTask = this.currentTask;
|
||||
task.onTaskStart();
|
||||
}
|
||||
if (this.currentTask < 0)
|
||||
{
|
||||
this.currentTask = 0;
|
||||
}
|
||||
|
||||
if (!task.doTask())
|
||||
{
|
||||
task.onTaskEnd();
|
||||
this.currentTask++;
|
||||
Command task = this.tasks.get(this.currentTask);
|
||||
|
||||
if (this.currentTask != this.lastTask)
|
||||
{
|
||||
this.lastTask = this.currentTask;
|
||||
task.onTaskStart();
|
||||
}
|
||||
|
||||
if (!task.doTask())
|
||||
{
|
||||
task.onTaskEnd();
|
||||
this.currentTask++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +74,7 @@ public class CommandManager
|
|||
task.tileEntity = tileEntity;
|
||||
task.commandManager = this;
|
||||
task.setParameters(parameters);
|
||||
tasks.add(task);
|
||||
this.tasks.add(task);
|
||||
task.onTaskStart();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,21 @@ public class CommandRepeat extends Command
|
|||
|
||||
public void onTaskStart()
|
||||
{
|
||||
this.tasksToRepeat = this.getIntArg(0);
|
||||
this.tasksToRepeat = Math.max(this.getIntArg(0), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doTask()
|
||||
{
|
||||
this.commandManager.setCurrentTask(this.commandManager.getCurrentTask() - this.tasksToRepeat);
|
||||
if (this.tasksToRepeat > 0)
|
||||
{
|
||||
this.commandManager.setCurrentTask(this.commandManager.getCurrentTask() - this.tasksToRepeat);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.commandManager.setCurrentTask(0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@ import cpw.mods.fml.relauncher.Side;
|
|||
*/
|
||||
public class CommandRotate extends Command
|
||||
{
|
||||
public static final float ROTATION_SPEED = 1f;
|
||||
public static final float ROTATION_SPEED = 1.3f;
|
||||
float targetRotation = 0;
|
||||
|
||||
@Override
|
||||
public void onTaskStart()
|
||||
{
|
||||
{
|
||||
if (this.getArg(0) == null)
|
||||
{
|
||||
this.targetRotation = this.tileEntity.rotationYaw + 90;
|
||||
|
@ -39,8 +39,13 @@ public class CommandRotate extends Command
|
|||
protected boolean doTask()
|
||||
{
|
||||
super.doTask();
|
||||
float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation);
|
||||
|
||||
if (Math.abs(this.targetRotation - this.tileEntity.rotationYaw) > 0.125)
|
||||
if (rotationalDifference < 0.8)
|
||||
{
|
||||
this.tileEntity.rotationYaw = this.targetRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.tileEntity.rotationYaw > this.targetRotation)
|
||||
{
|
||||
|
@ -51,17 +56,10 @@ public class CommandRotate extends Command
|
|||
this.tileEntity.rotationYaw += ROTATION_SPEED;
|
||||
}
|
||||
|
||||
// System.out.println("[" + ((FMLCommonHandler.instance().getEffectiveSide() ==
|
||||
// Side.SERVER) ? "S" : "C") + "]" + "Target: " + this.targetRotation + "; current: " +
|
||||
// this.tileEntity.rotationYaw);
|
||||
|
||||
if (Math.abs(this.tileEntity.rotationYaw - this.targetRotation) < 0.5)
|
||||
this.tileEntity.rotationYaw = this.targetRotation;
|
||||
|
||||
return true;
|
||||
}
|
||||
if (ticks < 80) // wait for a few ticks after rotating
|
||||
return true;
|
||||
|
||||
if (this.ticks < 80) { return true; }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue