Atomic's Once-over
See issues for comments
This commit is contained in:
parent
8a611891fb
commit
5d41e8644d
17 changed files with 768 additions and 36 deletions
|
@ -33,7 +33,7 @@ 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.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
|
||||||
@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents")
|
@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "required-after:BasicComponents")
|
||||||
@NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
|
@NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
|
||||||
public class AssemblyLine
|
public class AssemblyLine
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package assemblyline.ai;
|
package assemblyline.ai;
|
||||||
|
|
||||||
import assemblyline.machines.crafter.TileEntityCraftingArm;
|
import assemblyline.machine.crafter.TileEntityCraftingArm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An AI Task that is used by TileEntities with AI.
|
* An AI Task that is used by TileEntities with AI.
|
||||||
|
@ -19,11 +19,11 @@ public abstract class Task
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a task is being done.
|
* Called by the TaskManager to propagate tick updates
|
||||||
*
|
*
|
||||||
* @param ticks
|
* @param ticks
|
||||||
* The amount of ticks this task has been elapsed for.
|
* The amount of ticks this task has been running
|
||||||
* @return Return true if the task is not finished and false if it is.
|
* @return false if the task is finished and can be removed, true otherwise
|
||||||
*/
|
*/
|
||||||
protected boolean doTask()
|
protected boolean doTask()
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,6 @@ public abstract class Task
|
||||||
|
|
||||||
public void onTaskStart()
|
public void onTaskStart()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTaskEnd()
|
public void onTaskEnd()
|
||||||
|
@ -41,10 +40,10 @@ public abstract class Task
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The tick interval of this task. Return 0 for no ticks.
|
* @return The tick interval of this task. 0 means it will receive no update ticks.
|
||||||
*/
|
*/
|
||||||
public int getTickInterval()
|
public int getTickInterval()
|
||||||
{
|
{
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package assemblyline.ai;
|
package assemblyline.ai;
|
||||||
|
|
||||||
import assemblyline.machines.crafter.TileEntityCraftingArm;
|
import assemblyline.machine.crafter.TileEntityCraftingArm;
|
||||||
|
|
||||||
public class TaskIdle extends Task
|
public class TaskIdle extends Task
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package assemblyline.ai;
|
package assemblyline.ai;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.src.TileEntity;
|
import net.minecraft.src.TileEntity;
|
||||||
|
@ -22,8 +23,11 @@ public class TaskManager
|
||||||
*/
|
*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (Task task : this.tasks)
|
Task task;
|
||||||
|
Iterator<Task> iter = tasks.iterator();
|
||||||
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
|
task = iter.next();
|
||||||
if (task.getTickInterval() > 0)
|
if (task.getTickInterval() > 0)
|
||||||
{
|
{
|
||||||
if (this.ticks % task.getTickInterval() == 0)
|
if (this.ticks % task.getTickInterval() == 0)
|
||||||
|
@ -31,7 +35,7 @@ public class TaskManager
|
||||||
if (!task.doTask())
|
if (!task.doTask())
|
||||||
{
|
{
|
||||||
task.onTaskEnd();
|
task.onTaskEnd();
|
||||||
tasks.remove(task);
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,14 +50,24 @@ public class TaskManager
|
||||||
this.ticks++;
|
this.ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to register Tasks for a TileEntity, executes onTaskStart
|
||||||
|
* for the Task after registering it
|
||||||
|
*
|
||||||
|
* @param tileEntity TE instance to register the task for
|
||||||
|
* @param task Task instance to register
|
||||||
|
*/
|
||||||
public void addTask(TileEntity tileEntity, Task task)
|
public void addTask(TileEntity tileEntity, Task task)
|
||||||
{
|
{
|
||||||
task.onTaskStart();
|
|
||||||
tasks.add(task);
|
tasks.add(task);
|
||||||
|
task.onTaskStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasTask()
|
/**
|
||||||
|
* @return true when there are tasks registered, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean hasTasks()
|
||||||
{
|
{
|
||||||
return this.tasks.size() > 0;
|
return !tasks.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ public interface IBelt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Causes the belt to ignore the entity for a few updates help in cases where another machine
|
* Causes the belt to ignore the entity for a few updates help in cases where another machine
|
||||||
* need to effect this entity without the belt doing so as well.
|
* needs to affect this particular entity without the belt interfering
|
||||||
*
|
*
|
||||||
* @param entity
|
* @param entity
|
||||||
* - entity being ignored
|
* - entity being ignored
|
||||||
|
@ -25,9 +25,9 @@ public interface IBelt
|
||||||
public void ignoreEntity(Entity entity);
|
public void ignoreEntity(Entity entity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get a list of entities above this belt
|
* Used to get a list of entities the belt exerts an effect upon.
|
||||||
*
|
*
|
||||||
* @return list of entities
|
* @return list of entities in the belts are of effect
|
||||||
*/
|
*/
|
||||||
public List<Entity> getEntityAbove();
|
public List<Entity> getAffectedEntities();
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Entity> entityOnTop = this.getEntityAbove();
|
List<Entity> entityOnTop = this.getAffectedEntities();
|
||||||
|
|
||||||
for (Entity entity : entityOnTop)
|
for (Entity entity : entityOnTop)
|
||||||
{
|
{
|
||||||
|
@ -263,7 +263,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean middleBelt()
|
public boolean getIsMiddleBelt()
|
||||||
{
|
{
|
||||||
|
|
||||||
ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection());
|
ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection());
|
||||||
|
@ -280,7 +280,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean FrontCap()
|
public boolean getIsFrontCap()
|
||||||
{
|
{
|
||||||
|
|
||||||
ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection());
|
ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection());
|
||||||
|
@ -296,7 +296,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean BackCap()
|
public boolean getIsBackCap()
|
||||||
{
|
{
|
||||||
|
|
||||||
ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection());
|
ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection());
|
||||||
|
@ -345,7 +345,8 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
||||||
return ForgeDirection.getOrientation(this.getBeltDirection());
|
return ForgeDirection.getOrientation(this.getBeltDirection());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Entity> getEntityAbove()
|
@Override
|
||||||
|
public List<Entity> getAffectedEntities()
|
||||||
{
|
{
|
||||||
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
|
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
|
||||||
return worldObj.getEntitiesWithinAABB(Entity.class, bounds);
|
return worldObj.getEntitiesWithinAABB(Entity.class, bounds);
|
||||||
|
|
129
src/common/assemblyline/machine/crafter/BlockCrafter.java
Normal file
129
src/common/assemblyline/machine/crafter/BlockCrafter.java
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
import net.minecraft.src.TileEntity;
|
||||||
|
import net.minecraft.src.World;
|
||||||
|
import universalelectricity.core.UniversalElectricity;
|
||||||
|
import universalelectricity.prefab.BlockMachine;
|
||||||
|
import universalelectricity.prefab.UETab;
|
||||||
|
import assemblyline.AssemblyLine;
|
||||||
|
|
||||||
|
public class BlockCrafter extends BlockMachine
|
||||||
|
{
|
||||||
|
protected BlockCrafter(int id)
|
||||||
|
{
|
||||||
|
super("AutoCrafter", id, UniversalElectricity.machine);
|
||||||
|
this.setResistance(5.0f);
|
||||||
|
this.setHardness(5.0f);
|
||||||
|
this.setCreativeTab(UETab.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum CrafterType
|
||||||
|
{
|
||||||
|
CRAFTER("Crafter", 0, -1, TileEntityAutoCrafter.class);
|
||||||
|
|
||||||
|
public String name;
|
||||||
|
public int metadata;
|
||||||
|
public int guiID;
|
||||||
|
public Class<? extends TileEntity> tileEntity;
|
||||||
|
|
||||||
|
CrafterType(String name, int metadata, int guiID, Class<? extends TileEntity> tileEntity)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.guiID = guiID;
|
||||||
|
this.tileEntity = tileEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CrafterType get(int metadata)
|
||||||
|
{
|
||||||
|
for (CrafterType value : CrafterType.values())
|
||||||
|
{
|
||||||
|
if (metadata >= value.metadata && metadata < value.metadata + 4) { return value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the direction based on the metadata
|
||||||
|
*
|
||||||
|
* @return A direction value from 0 to 4.
|
||||||
|
*/
|
||||||
|
public static int getDirection(int metadata)
|
||||||
|
{
|
||||||
|
return metadata - CrafterType.get(metadata).metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param currentDirection - An integer from 0 to 4.
|
||||||
|
* @return The metadata this block should change into.
|
||||||
|
*/
|
||||||
|
public int getNextDirectionMeta(int currentDirection)
|
||||||
|
{
|
||||||
|
currentDirection++;
|
||||||
|
|
||||||
|
if (currentDirection >= 4)
|
||||||
|
{
|
||||||
|
currentDirection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentDirection + this.metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TIleEntity.
|
||||||
|
*/
|
||||||
|
public TileEntity instantiateTileEntity()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this.tileEntity.newInstance();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createNewTileEntity(World var1)
|
||||||
|
{
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createNewTileEntity(World var1, int metadata)
|
||||||
|
{
|
||||||
|
return CrafterType.get(metadata).instantiateTileEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||||
|
{
|
||||||
|
if (!par1World.isRemote)
|
||||||
|
{
|
||||||
|
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||||
|
int guiID = CrafterType.get(metadata).metadata;
|
||||||
|
if (guiID == -1)
|
||||||
|
return false;
|
||||||
|
par5EntityPlayer.openGui(AssemblyLine.instance, guiID, par1World, x, y, z);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRenderType()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import net.minecraft.src.Container;
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
import net.minecraft.src.InventoryPlayer;
|
||||||
|
import net.minecraft.src.Item;
|
||||||
|
import net.minecraft.src.ItemStack;
|
||||||
|
import net.minecraft.src.Slot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* I am planning to make the crafter not use a GUI.
|
||||||
|
*
|
||||||
|
* @author Calclavia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public class ContainerCrafter extends Container
|
||||||
|
{
|
||||||
|
private TileEntityAutoCrafter tileEntity;
|
||||||
|
|
||||||
|
public ContainerCrafter(InventoryPlayer par1InventoryPlayer, TileEntityAutoCrafter tileEntity)
|
||||||
|
{
|
||||||
|
this.tileEntity = tileEntity;
|
||||||
|
for (int r = 0; r < 3; r++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
// this.addSlotToContainer(new
|
||||||
|
// Slot(tileEntity, i + r * 3, 33
|
||||||
|
// + i * 18, 34 + r * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int var3;
|
||||||
|
|
||||||
|
for (var3 = 0; var3 < 3; ++var3)
|
||||||
|
{
|
||||||
|
for (int var4 = 0; var4 < 9; ++var4)
|
||||||
|
{
|
||||||
|
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var3 = 0; var3 < 9; ++var3)
|
||||||
|
{
|
||||||
|
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1)
|
||||||
|
{
|
||||||
|
ItemStack itemStack3 = null;
|
||||||
|
Slot itemStack = (Slot) this.inventorySlots.get(par1);
|
||||||
|
|
||||||
|
if (itemStack != null && itemStack.getHasStack())
|
||||||
|
{
|
||||||
|
ItemStack itemStack2 = itemStack.getStack();
|
||||||
|
itemStack3 = itemStack2.copy();
|
||||||
|
|
||||||
|
if (par1 != 0)
|
||||||
|
{
|
||||||
|
if (itemStack2.itemID == Item.coal.shiftedIndex)
|
||||||
|
{
|
||||||
|
if (!this.mergeItemStack(itemStack2, 0, 1, false)) { return null; }
|
||||||
|
}
|
||||||
|
else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false)) { return null; }
|
||||||
|
}
|
||||||
|
else if (!this.mergeItemStack(itemStack2, 3, 37, false)) { return null; }
|
||||||
|
|
||||||
|
if (itemStack2.stackSize == 0)
|
||||||
|
{
|
||||||
|
itemStack.putStack((ItemStack) null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemStack.onSlotChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemStack2.stackSize == itemStack3.stackSize) { return null; }
|
||||||
|
|
||||||
|
itemStack.onPickupFromSlot(par1EntityPlayer, itemStack2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemStack3;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import net.minecraft.src.Entity;
|
||||||
|
import net.minecraft.src.EntityItem;
|
||||||
|
import net.minecraft.src.ItemStack;
|
||||||
|
import net.minecraft.src.NBTTagCompound;
|
||||||
|
import net.minecraft.src.World;
|
||||||
|
import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
|
public class EntityCraftingArm extends Entity
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Used to ID the type of arm
|
||||||
|
*/
|
||||||
|
static enum armType
|
||||||
|
{
|
||||||
|
ARM, SOLDER, DRILL, BREAKER
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* type of arm this robotic arm currently is
|
||||||
|
*/
|
||||||
|
public armType arm = armType.ARM;
|
||||||
|
/**
|
||||||
|
* stack this arm is holding if any
|
||||||
|
*/
|
||||||
|
public ItemStack stack = null;
|
||||||
|
/**
|
||||||
|
* TileEntity this arm is working with
|
||||||
|
*/
|
||||||
|
public TileEntityCraftingArm blockArm = null;
|
||||||
|
/**
|
||||||
|
* position that the arms claw should be at
|
||||||
|
*/
|
||||||
|
public Vector3 clawPos = new Vector3();
|
||||||
|
|
||||||
|
public boolean isWorking = false;
|
||||||
|
|
||||||
|
public EntityCraftingArm(World par1World)
|
||||||
|
{
|
||||||
|
super(par1World);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void entityInit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readEntityFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
this.arm = armType.values()[nbt.getInteger("type")];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeEntityToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
nbt.setInteger("type", arm.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean grabItem(EntityItem item)
|
||||||
|
{
|
||||||
|
if (this.stack == null)
|
||||||
|
{
|
||||||
|
// TODO set current stack to item as
|
||||||
|
// soon as it reaches coords
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
14
src/common/assemblyline/machine/crafter/ItemCrafterArm.java
Normal file
14
src/common/assemblyline/machine/crafter/ItemCrafterArm.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import net.minecraft.src.Item;
|
||||||
|
|
||||||
|
public class ItemCrafterArm extends Item
|
||||||
|
{
|
||||||
|
|
||||||
|
protected ItemCrafterArm(int par1)
|
||||||
|
{
|
||||||
|
super(par1);
|
||||||
|
this.setHasSubtypes(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
38
src/common/assemblyline/machine/crafter/TaskArmCollect.java
Normal file
38
src/common/assemblyline/machine/crafter/TaskArmCollect.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityItem;
|
||||||
|
import assemblyline.ai.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by arms to collect items in a specific region.
|
||||||
|
*
|
||||||
|
* @author Calclavia
|
||||||
|
*/
|
||||||
|
public class TaskArmCollect extends Task
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item to be collected.
|
||||||
|
*/
|
||||||
|
private EntityItem entityItem;
|
||||||
|
|
||||||
|
public TaskArmCollect(TileEntityCraftingArm arm, EntityItem entityItem)
|
||||||
|
{
|
||||||
|
super(arm);
|
||||||
|
this.entityItem = entityItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean doTask()
|
||||||
|
{
|
||||||
|
super.doTask();
|
||||||
|
|
||||||
|
if (entityItem == null) { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slowly stretch down the arm's model and grab the item
|
||||||
|
*/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
61
src/common/assemblyline/machine/crafter/TaskArmSearch.java
Normal file
61
src/common/assemblyline/machine/crafter/TaskArmSearch.java
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.src.AxisAlignedBB;
|
||||||
|
import net.minecraft.src.Entity;
|
||||||
|
import assemblyline.ai.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by arms to search for entities in a region
|
||||||
|
*
|
||||||
|
* @author Calclavia
|
||||||
|
*/
|
||||||
|
public class TaskArmSearch extends Task
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item to be collected.
|
||||||
|
*/
|
||||||
|
private Class<? extends Entity> entityToInclude;
|
||||||
|
|
||||||
|
private float searchSpeed;
|
||||||
|
|
||||||
|
private double radius;
|
||||||
|
|
||||||
|
private Entity foundEntity;
|
||||||
|
|
||||||
|
public TaskArmSearch(TileEntityCraftingArm arm, Class<? extends Entity> entityToInclude, double radius, float searchSpeed)
|
||||||
|
{
|
||||||
|
super(arm);
|
||||||
|
this.entityToInclude = entityToInclude;
|
||||||
|
this.radius = radius;
|
||||||
|
this.searchSpeed = searchSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTaskStart()
|
||||||
|
{
|
||||||
|
List found = tileEntity.worldObj.getEntitiesWithinAABB(entityToInclude,
|
||||||
|
AxisAlignedBB.getBoundingBox(tileEntity.xCoord - radius, tileEntity.yCoord - radius, tileEntity.zCoord - radius,
|
||||||
|
tileEntity.xCoord + radius, tileEntity.yCoord + radius, tileEntity.zCoord + radius));
|
||||||
|
if (found != null && !found.isEmpty())
|
||||||
|
{
|
||||||
|
foundEntity = (Entity) found.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean doTask()
|
||||||
|
{
|
||||||
|
super.doTask();
|
||||||
|
|
||||||
|
if (this.entityToInclude == null || this.foundEntity == null) { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the robotic arm around and emulate an item search. Then initiate a collect task.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
import net.minecraft.src.INetworkManager;
|
||||||
|
import net.minecraft.src.Packet250CustomPayload;
|
||||||
|
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
public class TileEntityAutoCrafter extends TileEntityAdvanced
|
||||||
|
{
|
||||||
|
public String getInvName()
|
||||||
|
{
|
||||||
|
return "Auto Crafter";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,282 @@
|
||||||
|
package assemblyline.machine.crafter;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
import net.minecraft.src.IInventory;
|
||||||
|
import net.minecraft.src.INetworkManager;
|
||||||
|
import net.minecraft.src.ItemStack;
|
||||||
|
import net.minecraft.src.NBTTagCompound;
|
||||||
|
import net.minecraft.src.NBTTagList;
|
||||||
|
import net.minecraft.src.Packet250CustomPayload;
|
||||||
|
import net.minecraft.src.TileEntity;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
import universalelectricity.core.electricity.ElectricityConnections;
|
||||||
|
import universalelectricity.core.implement.IConductor;
|
||||||
|
import universalelectricity.core.implement.IJouleStorage;
|
||||||
|
import universalelectricity.core.vector.Vector3;
|
||||||
|
import universalelectricity.prefab.network.IPacketReceiver;
|
||||||
|
import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
|
||||||
|
import assemblyline.ai.TaskManager;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
public class TileEntityCraftingArm extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver, IJouleStorage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The items this container contains.
|
||||||
|
*/
|
||||||
|
protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()];
|
||||||
|
|
||||||
|
private TaskManager taskManager = new TaskManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity robotic arm to be used with this tileEntity
|
||||||
|
*/
|
||||||
|
public EntityCraftingArm EntityArm = null;
|
||||||
|
|
||||||
|
public final double WATT_REQUEST = 20;
|
||||||
|
|
||||||
|
public double wattsReceived = 0;
|
||||||
|
|
||||||
|
private int playerUsing = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initiate()
|
||||||
|
{
|
||||||
|
ElectricityConnections.registerConnector(this, EnumSet.of(ForgeDirection.DOWN, ForgeDirection.SOUTH, ForgeDirection.NORTH, ForgeDirection.EAST, ForgeDirection.WEST));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEntity()
|
||||||
|
{
|
||||||
|
super.updateEntity();
|
||||||
|
|
||||||
|
if (!this.worldObj.isRemote)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
ForgeDirection inputDirection = ForgeDirection.getOrientation(i);
|
||||||
|
|
||||||
|
if (inputDirection != ForgeDirection.UP)
|
||||||
|
{
|
||||||
|
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection);
|
||||||
|
|
||||||
|
if (inputTile != null)
|
||||||
|
{
|
||||||
|
if (inputTile instanceof IConductor)
|
||||||
|
{
|
||||||
|
if (this.getJoules() >= this.getMaxJoules())
|
||||||
|
{
|
||||||
|
((IConductor) inputTile).getNetwork().stopRequesting(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage());
|
||||||
|
this.setJoules(this.getJoules() + ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taskManager.onUpdate();
|
||||||
|
|
||||||
|
if (this.ticks % 5 == 0 && !this.isDisabled() && this.taskManager.hasTasks() && EntityArm != null)
|
||||||
|
{
|
||||||
|
this.wattsReceived -= this.WATT_REQUEST;
|
||||||
|
this.doWork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* controls the robotic arm into doing a set task
|
||||||
|
*/
|
||||||
|
public void doWork()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getVoltage()
|
||||||
|
{
|
||||||
|
return 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inventory
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInvName()
|
||||||
|
{
|
||||||
|
return "RoboticArm";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inventory functions.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlot(int par1)
|
||||||
|
{
|
||||||
|
return this.containingItems[par1];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack decrStackSize(int par1, int par2)
|
||||||
|
{
|
||||||
|
if (this.containingItems[par1] != null)
|
||||||
|
{
|
||||||
|
ItemStack var3;
|
||||||
|
|
||||||
|
if (this.containingItems[par1].stackSize <= par2)
|
||||||
|
{
|
||||||
|
var3 = this.containingItems[par1];
|
||||||
|
this.containingItems[par1] = null;
|
||||||
|
return var3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var3 = this.containingItems[par1].splitStack(par2);
|
||||||
|
|
||||||
|
if (this.containingItems[par1].stackSize == 0)
|
||||||
|
{
|
||||||
|
this.containingItems[par1] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return var3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlotOnClosing(int par1)
|
||||||
|
{
|
||||||
|
if (this.containingItems[par1] != null)
|
||||||
|
{
|
||||||
|
ItemStack var2 = this.containingItems[par1];
|
||||||
|
this.containingItems[par1] = null;
|
||||||
|
return var2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
|
||||||
|
{
|
||||||
|
this.containingItems[par1] = par2ItemStack;
|
||||||
|
|
||||||
|
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
|
||||||
|
{
|
||||||
|
par2ItemStack.stackSize = this.getInventoryStackLimit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInventoryStackLimit()
|
||||||
|
{
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
|
||||||
|
{
|
||||||
|
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openChest()
|
||||||
|
{
|
||||||
|
this.playerUsing++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeChest()
|
||||||
|
{
|
||||||
|
this.playerUsing--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NBT Data
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
|
NBTTagList var2 = nbt.getTagList("Items");
|
||||||
|
this.containingItems = new ItemStack[this.getSizeInventory()];
|
||||||
|
|
||||||
|
for (int var3 = 0; var3 < var2.tagCount(); ++var3)
|
||||||
|
{
|
||||||
|
NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3);
|
||||||
|
byte var5 = var4.getByte("Slot");
|
||||||
|
|
||||||
|
if (var5 >= 0 && var5 < this.containingItems.length)
|
||||||
|
{
|
||||||
|
this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a tile entity to NBT.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
super.writeToNBT(nbt);
|
||||||
|
NBTTagList var2 = new NBTTagList();
|
||||||
|
for (int var3 = 0; var3 < this.containingItems.length; ++var3)
|
||||||
|
{
|
||||||
|
if (this.containingItems[var3] != null)
|
||||||
|
{
|
||||||
|
NBTTagCompound var4 = new NBTTagCompound();
|
||||||
|
var4.setByte("Slot", (byte) var3);
|
||||||
|
this.containingItems[var3].writeToNBT(var4);
|
||||||
|
var2.appendTag(var4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nbt.setTag("Items", var2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getJoules(Object... data)
|
||||||
|
{
|
||||||
|
return this.wattsReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setJoules(double joules, Object... data)
|
||||||
|
{
|
||||||
|
this.wattsReceived = joules;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMaxJoules(Object... data)
|
||||||
|
{
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,11 +13,11 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer
|
||||||
{
|
{
|
||||||
private ModelConveyorBelt model = new ModelConveyorBelt();
|
private ModelConveyorBelt model = new ModelConveyorBelt();
|
||||||
|
|
||||||
public void renderAModelAt(TileEntityConveyorBelt tileEntity, double x, double y, double z, float f)
|
private void renderAModelAt(TileEntityConveyorBelt tileEntity, double x, double y, double z, float f)
|
||||||
{
|
{
|
||||||
String flip = "";// if(tileEntity.flip){flip
|
String flip = "";// if(tileEntity.flip){flip
|
||||||
// = "F";}
|
// = "F";}
|
||||||
boolean mid = tileEntity.middleBelt();
|
boolean mid = tileEntity.getIsMiddleBelt();
|
||||||
int face = tileEntity.getBeltDirection();
|
int face = tileEntity.getBeltDirection();
|
||||||
|
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
|
@ -29,20 +29,20 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer
|
||||||
{
|
{
|
||||||
GL11.glRotatef(180f, 0f, 1f, 0f);
|
GL11.glRotatef(180f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 3)
|
else if (face == 3)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(0f, 0f, 1f, 0f);
|
GL11.glRotatef(0f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 4)
|
else if (face == 4)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(90f, 0f, 1f, 0f);
|
GL11.glRotatef(90f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 5)
|
else if (face == 5)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(270f, 0f, 1f, 0f);
|
GL11.glRotatef(270f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||||
model.render(0.0625F, (float) Math.toRadians(tileEntity.wheelRotation), tileEntity.BackCap(), tileEntity.FrontCap(), false);
|
model.render(0.0625F, (float) Math.toRadians(tileEntity.wheelRotation), tileEntity.getIsBackCap(), tileEntity.getIsFrontCap(), false);
|
||||||
|
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RenderManipulator extends TileEntitySpecialRenderer
|
||||||
{
|
{
|
||||||
private ModelManipulator model = new ModelManipulator();
|
private ModelManipulator model = new ModelManipulator();
|
||||||
|
|
||||||
public void renderAModelAt(TileEntityManipulator tileEntity, double x, double y, double z, float f)
|
private void renderAModelAt(TileEntityManipulator tileEntity, double x, double y, double z, float f)
|
||||||
{
|
{
|
||||||
int face = tileEntity.getBeltDirection().ordinal();
|
int face = tileEntity.getBeltDirection().ordinal();
|
||||||
|
|
||||||
|
@ -34,15 +34,15 @@ public class RenderManipulator extends TileEntitySpecialRenderer
|
||||||
{
|
{
|
||||||
GL11.glRotatef(0f, 0f, 1f, 0f);
|
GL11.glRotatef(0f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 3)
|
else if (face == 3)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(180f, 0f, 1f, 0f);
|
GL11.glRotatef(180f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 4)
|
else if (face == 4)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(270f, 0f, 1f, 0f);
|
GL11.glRotatef(270f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 5)
|
else if (face == 5)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(90f, 0f, 1f, 0f);
|
GL11.glRotatef(90f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RenderSorter extends TileEntitySpecialRenderer
|
||||||
{
|
{
|
||||||
private ModelSorter model = new ModelSorter();
|
private ModelSorter model = new ModelSorter();
|
||||||
|
|
||||||
public void renderAModelAt(TileEntityRejector tileEntity, double x, double y, double z, float f)
|
private void renderAModelAt(TileEntityRejector tileEntity, double x, double y, double z, float f)
|
||||||
{
|
{
|
||||||
boolean fire = tileEntity.firePiston;
|
boolean fire = tileEntity.firePiston;
|
||||||
int face = tileEntity.getDirection(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
int face = tileEntity.getDirection(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
||||||
|
@ -34,11 +34,11 @@ public class RenderSorter extends TileEntitySpecialRenderer
|
||||||
{
|
{
|
||||||
GL11.glRotatef(0f, 0f, 1f, 0f);
|
GL11.glRotatef(0f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 4)
|
else if (face == 4)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(90f, 0f, 1f, 0f);
|
GL11.glRotatef(90f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
if (face == 5)
|
else if (face == 5)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(270f, 0f, 1f, 0f);
|
GL11.glRotatef(270f, 0f, 1f, 0f);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue