Added Break & Place Commands

This commit is contained in:
Henry Mao 2013-01-30 18:49:35 +08:00
parent 48eba3bed2
commit d18cbe854a
7 changed files with 129 additions and 44 deletions

View file

@ -92,6 +92,24 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
public void onUpdate()
{
Vector3 handPosition = this.getHandPosition();
for (Entity entity : this.grabbedEntities)
{
if (entity != null)
{
entity.setPosition(handPosition.x, handPosition.y, handPosition.z);
entity.motionX = 0;
entity.motionY = 0;
entity.motionZ = 0;
if (entity instanceof EntityItem)
{
((EntityItem) entity).delayBeforeCanPickup = 20;
((EntityItem) entity).age = 0;
}
}
}
if (this.isRunning())
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
@ -175,23 +193,6 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
}
}
for (Entity entity : this.grabbedEntities)
{
if (entity != null)
{
entity.setPosition(handPosition.x, handPosition.y, handPosition.z);
entity.motionX = 0;
entity.motionY = 0;
entity.motionZ = 0;
if (entity instanceof EntityItem)
{
((EntityItem) entity).delayBeforeCanPickup = 20;
((EntityItem) entity).age = 0;
}
}
}
// System.out.println("Ren: " + this.renderYaw + "; Rot: " + this.rotationYaw);
if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f)
{
@ -479,11 +480,16 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.rotationYaw = nbt.getFloat("yaw");
this.rotationPitch = nbt.getFloat("pitch");
if (this.worldObj.isRemote)
this.displayText = nbt.getString("cmdText");
if (this.worldObj != null)
{
if (this.worldObj.isRemote)
{
this.displayText = nbt.getString("cmdText");
}
}
/*
* NBTTagCompound cmdManager = nbt.getCompoundTag("cmdManager"); this.commandManager.readFromNBT(this, cmdManager);
* NBTTagCompound cmdManager = nbt.getCompoundTag("cmdManager");
* this.commandManager.readFromNBT(this, cmdManager);
*/
this.commandManager.setCurrentTask(nbt.getInteger("curTask"));
@ -520,7 +526,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
nbt.setFloat("pitch", this.rotationPitch);
/*
* NBTTagCompound cmdManager = new NBTTagCompound("cmdManager"); this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager);
* NBTTagCompound cmdManager = new NBTTagCompound("cmdManager");
* this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager);
*/
nbt.setString("cmdText", this.displayText);

View file

@ -34,6 +34,7 @@ public abstract class Command
registerCommand("use", CommandUse.class);
registerCommand("fire", CommandFire.class);
registerCommand("break", CommandBreak.class);
registerCommand("place", CommandPlace.class);
}
public static void registerCommand(String command, Class<? extends Command> commandClass)

View file

@ -11,21 +11,13 @@ import universalelectricity.core.vector.Vector3;
*/
public class CommandBreak extends Command
{
public static final float radius = 0.5f;
public CommandBreak()
{
super();
}
private CommandRotateTo rotateToCommand;
@Override
protected boolean doTask()
{
super.doTask();
if (this.tileEntity.grabbedEntities.size() > 0)
return false;
Vector3 serachPosition = this.tileEntity.getHandPosition();
Block block = Block.blocksList[serachPosition.getBlockID(this.world)];
@ -34,6 +26,7 @@ public class CommandBreak extends Command
{
block.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata(this.world), 0);
serachPosition.setBlockWithNotify(this.world, 0);
return false;
}
return true;

View file

@ -13,24 +13,30 @@ public class CommandDrop extends Command
if (this.tileEntity.grabbedEntities.size() == 0)
return false;
// TODO: Animate Armbot to move down and drop all items.
for (Entity entity : this.tileEntity.grabbedEntities)
{
if (entity != null)
{
entity.isDead = false;
entity.worldObj = this.tileEntity.worldObj;
if (entity instanceof EntityItem)
{
if (!world.isRemote)
world.spawnEntityInWorld(entity); // items don't move right, so we render
// them manually
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
{
// TODO: This causes crash.
// world.spawnEntityInWorld(entity);
}
}
}
}
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
this.tileEntity.grabbedEntities.clear();
return false;
}
@Override
public String toString()
{

View file

@ -48,15 +48,16 @@ public class CommandGrab extends Command
if (found.get(i) != null && !(found.get(i) instanceof EntityPlayer) && !(found.get(i) instanceof EntityArrow) && found.get(i).ridingEntity == null)
{
this.tileEntity.grabbedEntities.add(found.get(i));
if (found.get(i) instanceof EntityItem)
{
// items don't move right, so we render them manually
this.tileEntity.worldObj.removeEntity(found.get(i));
}
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
found.get(i).isDead = false;
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
return false;
}
}

View file

@ -0,0 +1,74 @@
package assemblyline.common.machine.command;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IPlantable;
import universalelectricity.core.vector.Vector3;
/**
* Used by arms to break a specific block in a position.
*
* @author Calclavia
*/
public class CommandPlace extends Command
{
@Override
protected boolean doTask()
{
super.doTask();
Vector3 serachPosition = this.tileEntity.getHandPosition();
Block block = Block.blocksList[serachPosition.getBlockID(this.world)];
if (block == null)
{
for (Entity entity : this.tileEntity.grabbedEntities)
{
if (entity instanceof EntityItem)
{
ItemStack itemStack = ((EntityItem) entity).getEntityItem();
if (itemStack != null)
{
if (itemStack.getItem() instanceof ItemBlock)
{
((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage());
this.tileEntity.grabbedEntities.remove(entity);
return false;
}
else if (itemStack.getItem() instanceof IPlantable)
{
IPlantable plantable = ((IPlantable) itemStack.getItem());
int blockID = plantable.getPlantID(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
int blockMetadata = plantable.getPlantMetadata(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
if (!world.setBlockAndMetadataWithNotify(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockID, blockMetadata)) { return false; }
if (world.getBlockId(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()) == blockID)
{
Block.blocksList[blockID].onBlockPlacedBy(world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), null);
Block.blocksList[blockID].onPostBlockPlaced(world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockMetadata);
}
this.tileEntity.grabbedEntities.remove(entity);
return false;
}
}
}
}
}
return false;
}
@Override
public String toString()
{
return "PLACE";
}
}

View file

@ -9,9 +9,9 @@ import net.minecraft.nbt.NBTTagCompound;
*/
public class CommandRotateTo extends Command
{
float targetRotationYaw = 0;
float targetRotationPitch = 0;
int totalTicks = 0;
float targetRotationYaw = 0;
float targetRotationPitch = 0;
int totalTicks = 0;
@Override
public void onTaskStart()
@ -43,7 +43,7 @@ public class CommandRotateTo extends Command
this.targetRotationYaw += 360;
while (this.targetRotationYaw > 360)
this.targetRotationYaw -= 360;
while (this.targetRotationPitch < 0)
while (this.targetRotationPitch < -60)
this.targetRotationPitch += 60;
while (this.targetRotationPitch > 60)
this.targetRotationPitch -= 60;
@ -60,7 +60,10 @@ public class CommandRotateTo extends Command
/*
* float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation);
*
* if (rotationalDifference < ROTATION_SPEED) { this.tileEntity.rotationYaw = this.targetRotation; } else { if (this.tileEntity.rotationYaw > this.targetRotation) { this.tileEntity.rotationYaw -= ROTATION_SPEED; } else { this.tileEntity.rotationYaw += ROTATION_SPEED; } this.ticks = 0; }
* if (rotationalDifference < ROTATION_SPEED) { this.tileEntity.rotationYaw =
* this.targetRotation; } else { if (this.tileEntity.rotationYaw > this.targetRotation) {
* this.tileEntity.rotationYaw -= ROTATION_SPEED; } else { this.tileEntity.rotationYaw +=
* ROTATION_SPEED; } this.ticks = 0; }
*/
// set the rotation to the target immediately and let the client handle animating it