Got rotateto and rotateby commands working
This commit is contained in:
parent
698b79ca94
commit
2235c2b743
6 changed files with 64 additions and 94 deletions
|
@ -41,18 +41,22 @@ public class ProgramHelper
|
|||
ProcessReturn re = ProcessReturn.DONE;
|
||||
if (program != null)
|
||||
{
|
||||
System.out.println("[ProgramHelper]UpdateTickDebug");
|
||||
if (this.currentTask == null || this.nextTask)
|
||||
{
|
||||
this.nextTask();
|
||||
}
|
||||
if (this.currentTask != null)
|
||||
{
|
||||
System.out.println("[ProgramHelper]Updating task:"+this.currentTask.toString());
|
||||
if (!this.hasTaskBeenCalled)
|
||||
{
|
||||
System.out.println("[ProgramHelper]First task update");
|
||||
this.hasTaskBeenCalled = true;
|
||||
if (this.currentTask instanceof IProcessTask)
|
||||
{
|
||||
re = ((IProcessTask) this.currentTask).onMethodCalled();
|
||||
System.out.println("[ProgramHelper]OnCall:" + re.toString());
|
||||
if (re == ProcessReturn.DONE)
|
||||
{
|
||||
this.nextTask = true;
|
||||
|
@ -75,6 +79,7 @@ public class ProgramHelper
|
|||
{
|
||||
re = ProcessReturn.CONTINUE;
|
||||
}
|
||||
System.out.println("[ProgramHelper]OnUpdate:" + re.toString());
|
||||
return re;
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +88,7 @@ public class ProgramHelper
|
|||
|
||||
public void nextTask()
|
||||
{
|
||||
System.out.println("[ProgramHelper]Getting next task");
|
||||
this.hasTaskBeenCalled = false;
|
||||
this.nextTask = false;
|
||||
//Tell old task to clear itself
|
||||
|
|
|
@ -26,7 +26,6 @@ public abstract class TaskBaseProcess extends TaskBase implements IProcessTask
|
|||
{
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
return ProcessReturn.GENERAL_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.builtbroken.assemblyline.ALRecipeLoader;
|
|||
import com.builtbroken.assemblyline.api.IArmbot;
|
||||
import com.builtbroken.assemblyline.api.coding.IProgram;
|
||||
import com.builtbroken.assemblyline.api.coding.ProgramHelper;
|
||||
import com.builtbroken.assemblyline.armbot.command.TaskGOTO;
|
||||
import com.builtbroken.assemblyline.armbot.command.TaskReturn;
|
||||
import com.builtbroken.assemblyline.armbot.command.TaskRotateBy;
|
||||
import com.builtbroken.assemblyline.machine.TileEntityAssembly;
|
||||
|
@ -49,20 +50,17 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
protected float rotationPitch = 0, rotationYaw = 0;
|
||||
protected float actualPitch = 0, actualYaw = 0;
|
||||
|
||||
protected boolean hasTask = false;
|
||||
protected boolean spawnEntity = false;
|
||||
|
||||
protected String displayText = "";
|
||||
|
||||
/** An entity that the Armbot is grabbed onto. Entity Items are held separately. */
|
||||
protected Object grabbedObject = null;
|
||||
|
||||
protected List<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
|
||||
|
||||
/** Helper class that does all the logic for the armbot's program */
|
||||
protected ProgramHelper programHelper;
|
||||
|
||||
/** Cached location of the armbot to feed to program tasks */
|
||||
protected Pair<World, Vector3> location;
|
||||
|
||||
/** Var used by the armbot renderer */
|
||||
public EntityItem renderEntityItem;
|
||||
|
||||
public TileEntityArmbot()
|
||||
|
@ -72,13 +70,15 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
Program program = new Program();
|
||||
program.setTaskAt(0, 0, new TaskRotateBy(90, 0));
|
||||
program.setTaskAt(0, 1, new TaskReturn());
|
||||
program.setTaskAt(0, 1, new TaskGOTO(0, 0));
|
||||
programHelper.setProgram(program);
|
||||
}
|
||||
|
||||
/************************************ Armbot logic update methods *************************************/
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
System.out.println("Armbot update");
|
||||
super.updateEntity();
|
||||
Vector3 handPosition = this.getHandPos();
|
||||
if (this.location == null || !this.location.left().equals(this.worldObj) || this.xCoord != this.location.right().intX() || this.yCoord != this.location.right().intY() || this.zCoord != this.location.right().intZ())
|
||||
|
@ -106,12 +106,10 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
|
||||
if (this.isFunctioning())
|
||||
{
|
||||
System.out.println("Is functioning");
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
this.updateLogic();
|
||||
this.programHelper.onUpdate(this.worldObj, new Vector3(this));
|
||||
float preYaw = this.rotationYaw, prePitch = this.rotationPitch;
|
||||
this.updateLogic();
|
||||
if (this.rotationYaw != preYaw || this.rotationPitch != prePitch)
|
||||
{
|
||||
this.sendRotationPacket();
|
||||
|
@ -121,16 +119,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
}
|
||||
}
|
||||
|
||||
public void updateLogic()
|
||||
{
|
||||
System.out.println("Armbot updating logic");
|
||||
if (this.programHelper == null)
|
||||
{
|
||||
this.programHelper = new ProgramHelper(this);
|
||||
}
|
||||
this.programHelper.onUpdate(this.worldObj, new Vector3(this));
|
||||
}
|
||||
|
||||
public void updateRotation()
|
||||
{
|
||||
if (Math.abs(this.actualYaw - this.rotationYaw) > 0.001f)
|
||||
|
@ -227,6 +215,41 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
return this.displayText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivated(EntityPlayer player)
|
||||
{
|
||||
ItemStack containingStack = this.getStackInSlot(0);
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
{
|
||||
EntityItem dropStack = new EntityItem(this.worldObj, player.posX, player.posY, player.posZ, containingStack);
|
||||
dropStack.delayBeforeCanPickup = 0;
|
||||
this.worldObj.spawnEntityInWorld(dropStack);
|
||||
}
|
||||
|
||||
this.setInventorySlotContents(0, null);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.getCurrentEquippedItem() != null)
|
||||
{
|
||||
if (player.getCurrentEquippedItem().getItem() instanceof ItemDisk)
|
||||
{
|
||||
this.setInventorySlotContents(0, player.getCurrentEquippedItem());
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/************************************ Save and load code *************************************/
|
||||
|
||||
/** NBT Data */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
|
@ -280,6 +303,8 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
|
||||
}
|
||||
|
||||
/************************************ Network Packet code *************************************/
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
|
@ -320,38 +345,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivated(EntityPlayer player)
|
||||
{
|
||||
ItemStack containingStack = this.getStackInSlot(0);
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
{
|
||||
EntityItem dropStack = new EntityItem(this.worldObj, player.posX, player.posY, player.posZ, containingStack);
|
||||
dropStack.delayBeforeCanPickup = 0;
|
||||
this.worldObj.spawnEntityInWorld(dropStack);
|
||||
}
|
||||
|
||||
this.setInventorySlotContents(0, null);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.getCurrentEquippedItem() != null)
|
||||
{
|
||||
if (player.getCurrentEquippedItem().getItem() instanceof ItemDisk)
|
||||
{
|
||||
this.setInventorySlotContents(0, player.getCurrentEquippedItem());
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/************************************ Multi Block code *************************************/
|
||||
|
||||
@Override
|
||||
public void onCreate(Vector3 placedPosition)
|
||||
|
@ -366,6 +360,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
this.worldObj.setBlock(this.xCoord, this.yCoord + 1, this.zCoord, 0, 0, 3);
|
||||
}
|
||||
|
||||
/************************************ Armbot API methods *************************************/
|
||||
@Override
|
||||
public Object getGrabbedObject()
|
||||
{
|
||||
|
@ -416,28 +411,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return direction == ForgeDirection.DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvNameLocalized()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWattLoad()
|
||||
{
|
||||
if (this.hasTask)
|
||||
{
|
||||
return 40;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
|
|
|
@ -22,19 +22,17 @@ public class TaskRotateBy extends TaskBaseArmbot
|
|||
|
||||
private TaskRotateTo rotateToCommand;
|
||||
|
||||
public TaskRotateBy()
|
||||
public TaskRotateBy(int yaw, int pitch)
|
||||
{
|
||||
super("RotateBy");
|
||||
this.args.add(new ArgumentIntData("yaw", 0, 360, 0));
|
||||
this.args.add(new ArgumentIntData("pitch", 0, 360, 0));
|
||||
this.args.add(new ArgumentIntData("yaw", yaw, 360, 0));
|
||||
this.args.add(new ArgumentIntData("pitch", pitch, 360, 0));
|
||||
this.UV = new Vector2(80, 80);
|
||||
}
|
||||
|
||||
public TaskRotateBy(float yaw, float pitch)
|
||||
public TaskRotateBy()
|
||||
{
|
||||
this();
|
||||
this.setArg("yaw", yaw);
|
||||
this.setArg("pitch", pitch);
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,10 +40,8 @@ public class TaskRotateBy extends TaskBaseArmbot
|
|||
{
|
||||
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
|
||||
{
|
||||
|
||||
this.targetRotationYaw = (int) MathHelper.clampAngleTo360((float) (((IArmbot) this.program.getMachine()).getRotation().x + UnitHelper.tryToParseInt(this.getArg("yaw"))));
|
||||
this.targetRotationYaw = (int) MathHelper.clampAngleTo360((float) (((IArmbot) this.program.getMachine()).getRotation().x + UnitHelper.tryToParseInt(this.getArg("pitch"))));
|
||||
|
||||
this.targetRotationPitch = (int) MathHelper.clampAngleTo360((float) (((IArmbot) this.program.getMachine()).getRotation().x + UnitHelper.tryToParseInt(this.getArg("pitch"))));
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
return ProcessReturn.GENERAL_ERROR;
|
||||
|
@ -57,6 +53,7 @@ public class TaskRotateBy extends TaskBaseArmbot
|
|||
if (this.rotateToCommand == null)
|
||||
{
|
||||
this.rotateToCommand = new TaskRotateTo(this.targetRotationYaw, this.targetRotationPitch);
|
||||
this.rotateToCommand.setProgram(this.program);
|
||||
this.rotateToCommand.onMethodCalled();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,8 @@ public class TaskRotateTo extends TaskBaseArmbot
|
|||
{
|
||||
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
|
||||
{
|
||||
|
||||
this.targetRotationYaw = (int) MathHelper.clampAngleTo360(UnitHelper.tryToParseInt(this.getArg("yaw")));
|
||||
this.targetRotationPitch = (int) MathHelper.clampAngleTo360(UnitHelper.tryToParseInt(this.getArg("pitch")));
|
||||
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
return ProcessReturn.GENERAL_ERROR;
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.builtbroken.minecraft.tilenetwork.prefab.NetworkTileEntities;
|
|||
|
||||
/** A class to be inherited by all machines on the assembly line. This class acts as a single peace
|
||||
* in a network of similar tiles allowing all to share power from one or more sources
|
||||
*
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public abstract class TileEntityAssembly extends TileEntityEnergyMachine implements INetworkEnergyPart
|
||||
{
|
||||
|
@ -47,11 +47,7 @@ public abstract class TileEntityAssembly extends TileEntityEnergyMachine impleme
|
|||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
NetworkTileEntities.invalidate(this);
|
||||
if (this.getTileNetwork() != null)
|
||||
{
|
||||
this.getTileNetwork().splitNetwork(this);
|
||||
}
|
||||
this.getTileNetwork().splitNetwork(this);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
|
@ -103,7 +99,7 @@ public abstract class TileEntityAssembly extends TileEntityEnergyMachine impleme
|
|||
@Override
|
||||
public NetworkAssembly getTileNetwork()
|
||||
{
|
||||
if (this.assemblyNetwork == null)
|
||||
if (!(this.assemblyNetwork instanceof NetworkAssembly))
|
||||
{
|
||||
this.assemblyNetwork = new NetworkAssembly(this);
|
||||
}
|
||||
|
@ -141,6 +137,7 @@ public abstract class TileEntityAssembly extends TileEntityEnergyMachine impleme
|
|||
return 1;//1J/t or 20J/t
|
||||
}
|
||||
|
||||
/** Conditional load that may not be consumed per tick */
|
||||
public int getExtraLoad()
|
||||
{
|
||||
return 1;//1J/t or 20J/t
|
||||
|
|
Loading…
Add table
Reference in a new issue