Updated UE API

Added RotateTo command
Added .fire(velocity) to CC peripheral
Added .rotateTo(yaw, pitch) to CC peripheral
Changed .rotate(yaw) to .rotateBy(yaw, pitch) in CC API
Fixed RETURN command (and other ROTATE commands) not waiting properly
This commit is contained in:
Brian Ricketts 2013-01-25 22:07:21 -06:00
parent 179c92c3bb
commit f443184f8b
29 changed files with 1125 additions and 176 deletions

View file

@ -1 +1 @@
61
61

View file

@ -1 +1 @@
0.2.4
0.2.4

View file

@ -1,12 +1,14 @@
package assemblyline.client.render;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import org.lwjgl.opengl.GL11;
@ -14,17 +16,33 @@ import universalelectricity.core.vector.Vector3;
import assemblyline.client.model.ModelArmbot;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.armbot.TileEntityArmbot;
import assemblyline.common.machine.command.Command;
public class RenderArmbot extends TileEntitySpecialRenderer
{
public static final ModelArmbot MODEL = new ModelArmbot();
public static final String TEXTURE = "armbot.png";
public static final ModelArmbot MODEL = new ModelArmbot();
public static final String TEXTURE = "armbot.png";
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{
if (tileEntity instanceof TileEntityArmbot)
{
Command curCommand = ((TileEntityArmbot) tileEntity).getCurrentCommand();
if (curCommand != null)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null)
{
if (objectPosition.blockX == tileEntity.xCoord && (objectPosition.blockY == tileEntity.yCoord || objectPosition.blockY == tileEntity.yCoord + 1) && objectPosition.blockZ == tileEntity.zCoord)
{
RenderHelper.renderFloatingText(curCommand.toString(), (float) x + 0.5f, ((float) y) + 0.25f, (float) z + 0.5f, 0xFFFFFF);
}
}
}
this.bindTextureByName(AssemblyLine.TEXTURE_PATH + TEXTURE);
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
@ -36,7 +54,7 @@ public class RenderArmbot extends TileEntitySpecialRenderer
GL11.glRotatef(180, 0, 0, 1);
for (Entity entity : ((TileEntityArmbot) tileEntity).grabbedEntities)
{
if (entity != null && entity instanceof EntityItem) //items don't move right, so we render them manually
if (entity != null && entity instanceof EntityItem) // items don't move right, so we render them manually
{
EntityItem item = (EntityItem) entity;
item.age = 0;

View file

@ -34,10 +34,12 @@ import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.TileEntityAssemblyNetwork;
import assemblyline.common.machine.command.Command;
import assemblyline.common.machine.command.CommandDrop;
import assemblyline.common.machine.command.CommandFire;
import assemblyline.common.machine.command.CommandGrab;
import assemblyline.common.machine.command.CommandManager;
import assemblyline.common.machine.command.CommandReturn;
import assemblyline.common.machine.command.CommandRotate;
import assemblyline.common.machine.command.CommandRotateBy;
import assemblyline.common.machine.command.CommandRotateTo;
import assemblyline.common.machine.command.CommandUse;
import assemblyline.common.machine.encoder.ItemDisk;
@ -272,6 +274,13 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 50);
}
}
public Command getCurrentCommand()
{
if (this.commandManager.hasTasks() && this.commandManager.getCurrentTask() >= 0 && this.commandManager.getCurrentTask() < this.commandManager.getCommands().size())
return this.commandManager.getCommands().get(this.commandManager.getCurrentTask());
return null;
}
/**
* @return The current hand position of the armbot.
@ -616,7 +625,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
@Override
public String[] getMethodNames()
{
return new String[] { "rotate", "grab", "drop", "reset", "isWorking", "touchingEntity", "use" };
return new String[] { "rotateBy", "rotateTo", "grab", "drop", "reset", "isWorking", "touchingEntity", "use", "fire" };
}
@Override
@ -631,8 +640,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
try
// try to cast to Float
{
double angle = (Double) arguments[0];
this.commandManager.addCommand(this, CommandRotate.class, new String[] { Double.toString(angle) });
double yaw = (Double) arguments[0];
double pitch = (Double) arguments[1];
this.commandManager.addCommand(this, CommandRotateBy.class, new String[] { Double.toString(yaw), Double.toString(pitch) });
}
catch (Exception ex)
{
@ -646,27 +656,50 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
}
break;
}
case 1: // grab: grabs an item
case 1: // rotateTo: rotates to a specific rotation
{
if (arguments.length > 0)
{
try
// try to cast to Float
{
double yaw = (Double) arguments[0];
double pitch = (Double) arguments[1];
this.commandManager.addCommand(this, CommandRotateTo.class, new String[] { Double.toString(yaw), Double.toString(pitch) });
}
catch (Exception ex)
{
ex.printStackTrace();
throw new IllegalArgumentException("expected number");
}
}
else
{
throw new IllegalArgumentException("expected number");
}
break;
}
case 2: // grab: grabs an item
{
this.commandManager.addCommand(this, CommandGrab.class);
break;
}
case 2: // drop: drops an item
case 3: // drop: drops an item
{
this.commandManager.addCommand(this, CommandDrop.class);
break;
}
case 3: // reset: clears the queue and calls the RETURN command
case 4: // reset: clears the queue and calls the RETURN command
{
this.commandManager.clear();
this.commandManager.addCommand(this, CommandReturn.class);
break;
}
case 4: // isWorking: returns whether or not the ArmBot is executing commands
case 5: // isWorking: returns whether or not the ArmBot is executing commands
{
return new Object[] { this.commandManager.hasTasks() };
}
case 5: // touchingEntity: returns whether or not the ArmBot is touching an entity it is able to pick up
case 6: // touchingEntity: returns whether or not the ArmBot is touching an entity it is able to pick up
{
Vector3 serachPosition = this.getHandPosition();
List<Entity> found = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(serachPosition.x - 0.5f, serachPosition.y - 0.5f, serachPosition.z - 0.5f, serachPosition.x + 0.5f, serachPosition.y + 0.5f, serachPosition.z + 0.5f));
@ -682,7 +715,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
return new Object[] { false };
}
case 6:
case 7:
{
if (arguments.length > 0)
{
@ -704,6 +737,28 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
}
break;
}
case 8: // fire: think "flying pig"
{
if (arguments.length > 0)
{
try
// try to cast to Float
{
float strength = (float) ((double) ((Double) arguments[0]));
this.commandManager.addCommand(this, CommandFire.class, new String[] { Float.toString(strength) });
}
catch (Exception ex)
{
ex.printStackTrace();
throw new IllegalArgumentException("expected number");
}
}
else
{
this.commandManager.addCommand(this, CommandFire.class);
}
break;
}
}
return null;
}

View file

@ -29,7 +29,8 @@ public abstract class Command
registerCommand("idle", CommandIdle.class);
registerCommand("grab", CommandGrab.class);
registerCommand("drop", CommandDrop.class);
registerCommand("rotate", CommandRotate.class);
registerCommand("rotate", CommandRotateBy.class);
registerCommand("rotateto", CommandRotateTo.class);
registerCommand("return", CommandReturn.class);
registerCommand("repeat", CommandRepeat.class);
registerCommand("use", CommandUse.class);
@ -179,4 +180,10 @@ public abstract class Command
}
taskCompound.setTag("parameters", parList);
}
@Override
public String toString()
{
return "COMMAND";
}
}

View file

@ -30,4 +30,10 @@ public class CommandDrop extends Command
this.tileEntity.grabbedEntities.clear();
return false;
}
@Override
public String toString()
{
return "DROP";
}
}

View file

@ -1,117 +1,123 @@
package assemblyline.common.machine.command;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import universalelectricity.core.vector.Vector3;
public class CommandFire extends Command
{
private static final float MIN_ACTUAL_PITCH = -80;
private static final float MAX_ACTUAL_PITCH = 80;
private float actualYaw;
private float actualPitch;
private float velocity;
private Vector3 finalVelocity;
@Override
public void onTaskStart()
{
super.onTaskStart();
velocity = this.getFloatArg(0);
if (velocity > 2.5f)
velocity = 2.5f;
if (velocity < 0.125f)
velocity = 1f;
this.actualYaw = this.tileEntity.rotationYaw;
this.actualPitch = ((MAX_ACTUAL_PITCH - MIN_ACTUAL_PITCH) * (this.tileEntity.rotationPitch / 60f)) + MIN_ACTUAL_PITCH;
double x, y, z;
double yaw, pitch;
yaw = Math.toRadians(actualYaw);
pitch = Math.toRadians(actualPitch);
// yaw = actualYaw;
// pitch = actualPitch;
x = -Math.sin(yaw) * Math.cos(pitch);
y = Math.sin(pitch);
z = Math.cos(yaw) * Math.cos(pitch);
this.finalVelocity = new Vector3(x, y, z);
Random random = new Random(System.currentTimeMillis());
this.finalVelocity.x *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.y *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.z *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.multiply(velocity);
}
@Override
protected boolean doTask()
{
if (this.finalVelocity == null) // something went wrong
{
this.finalVelocity = new Vector3(0, 0, 0);
}
if (this.tileEntity.grabbedEntities.size() > 0)
{
Entity held = this.tileEntity.grabbedEntities.get(0);
if (held != null)
{
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.bow", velocity, 2f - (velocity / 4f), true);
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;
ItemStack stack = item.func_92014_d();
ItemStack thrown = stack.copy();
thrown.stackSize = 1;
if (item.func_92014_d().stackSize > 0)
{
stack.stackSize--;
item.func_92013_a(stack);
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask();
if (!this.world.isRemote)
this.world.removeEntity(held);
}
if (item.func_92014_d().itemID == Item.arrow.itemID)
{
EntityArrow arrow = new EntityArrow(world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z);
arrow.motionX = this.finalVelocity.x;
arrow.motionY = this.finalVelocity.y;
arrow.motionZ = this.finalVelocity.z;
if (!this.world.isRemote)
this.world.spawnEntityInWorld(arrow);
}
else
{
EntityItem item2 = new EntityItem(world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z, thrown);
item2.motionX = this.finalVelocity.x;
item2.motionY = this.finalVelocity.y;
item2.motionZ = this.finalVelocity.z;
if (!this.world.isRemote)
this.world.spawnEntityInWorld(item2);
}
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask();
held.motionX = this.finalVelocity.x;
held.motionY = this.finalVelocity.y;
held.motionZ = this.finalVelocity.z;
}
}
}
return false;
}
}
package assemblyline.common.machine.command;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import universalelectricity.core.vector.Vector3;
public class CommandFire extends Command
{
private static final float MIN_ACTUAL_PITCH = -80;
private static final float MAX_ACTUAL_PITCH = 80;
private float actualYaw;
private float actualPitch;
private float velocity;
private Vector3 finalVelocity;
@Override
public void onTaskStart()
{
super.onTaskStart();
this.velocity = this.getFloatArg(0);
if (this.velocity > 2.5f)
this.velocity = 2.5f;
if (this.velocity < 0.125f)
this.velocity = 1f;
this.actualYaw = this.tileEntity.rotationYaw;
this.actualPitch = ((MAX_ACTUAL_PITCH - MIN_ACTUAL_PITCH) * (this.tileEntity.rotationPitch / 60f)) + MIN_ACTUAL_PITCH;
double x, y, z;
double yaw, pitch;
yaw = Math.toRadians(actualYaw);
pitch = Math.toRadians(actualPitch);
// yaw = actualYaw;
// pitch = actualPitch;
x = -Math.sin(yaw) * Math.cos(pitch);
y = Math.sin(pitch);
z = Math.cos(yaw) * Math.cos(pitch);
this.finalVelocity = new Vector3(x, y, z);
Random random = new Random(System.currentTimeMillis());
this.finalVelocity.x *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.y *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.z *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.multiply(velocity);
}
@Override
protected boolean doTask()
{
if (this.finalVelocity == null) // something went wrong
{
this.finalVelocity = new Vector3(0, 0, 0);
}
if (this.tileEntity.grabbedEntities.size() > 0)
{
Entity held = this.tileEntity.grabbedEntities.get(0);
if (held != null)
{
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.bow", velocity, 2f - (velocity / 4f), true);
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;
ItemStack stack = item.func_92014_d();
ItemStack thrown = stack.copy();
thrown.stackSize = 1;
if (item.func_92014_d().stackSize > 0)
{
stack.stackSize--;
item.func_92013_a(stack);
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask();
if (!this.world.isRemote)
this.world.removeEntity(held);
}
if (item.func_92014_d().itemID == Item.arrow.itemID)
{
EntityArrow arrow = new EntityArrow(world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z);
arrow.motionX = this.finalVelocity.x;
arrow.motionY = this.finalVelocity.y;
arrow.motionZ = this.finalVelocity.z;
if (!this.world.isRemote)
this.world.spawnEntityInWorld(arrow);
}
else
{
EntityItem item2 = new EntityItem(world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z, thrown);
item2.motionX = this.finalVelocity.x;
item2.motionY = this.finalVelocity.y;
item2.motionZ = this.finalVelocity.z;
if (!this.world.isRemote)
this.world.spawnEntityInWorld(item2);
}
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask();
held.motionX = this.finalVelocity.x;
held.motionY = this.finalVelocity.y;
held.motionZ = this.finalVelocity.z;
}
}
}
return false;
}
@Override
public String toString()
{
return "FIRE " + Float.toString(this.velocity);
}
}

View file

@ -62,4 +62,10 @@ public class CommandGrab extends Command
return true;
}
@Override
public String toString()
{
return "GRAB";
}
}

View file

@ -7,6 +7,7 @@ public class CommandIdle extends Command
* The amount of time in which the machine will idle.
*/
public int idleTime = 80;
private int totalIdleTime = 80;
public void onTaskStart()
{
@ -15,6 +16,7 @@ public class CommandIdle extends Command
if (this.getIntArg(0) > 0)
{
this.idleTime = this.getIntArg(0);
this.totalIdleTime = this.idleTime;
}
}
@ -33,5 +35,11 @@ public class CommandIdle extends Command
return false;
}
@Override
public String toString()
{
return "IDLE " + Integer.toString(this.totalIdleTime);
}
}

View file

@ -1,5 +1,7 @@
package assemblyline.common.machine.command;
import assemblyline.common.machine.armbot.TileEntityArmbot;
/**
* This task resets all previous tasks and does them again in a loop.
*
@ -42,10 +44,25 @@ public class CommandRepeat extends Command
}
else
{
this.commandManager.setCurrentTask(-1);
this.commandManager.setCurrentTask(-2);
return;
}
}
this.initialized = false;
}
@Override
public String toString()
{
int cmdToTest = 0;
if (this.tasksToRepeat > 0)
{
cmdToTest = this.commandManager.getCurrentTask() - this.tasksToRepeat;
}
if (this.commandManager.hasTasks() && this.commandManager.getCurrentTask() >= 0 && this.commandManager.getCurrentTask() < this.commandManager.getCommands().size())
{
return this.commandManager.getCommands().get(cmdToTest).toString();
}
return "REPEAT " + Integer.toString(this.tasksToRepeat) + " " + ((this.numReps > 0) ? Integer.toString(this.numReps) : "");
}
}

View file

@ -1,46 +1,45 @@
package assemblyline.common.machine.command;
public class CommandReturn extends CommandRotate
public class CommandReturn extends Command
{
public static final float IDLE_ROTATION_PITCH = 0;
public static final float IDLE_ROTATION_YAW = 0;
public static final float IDLE_ROTATION_PITCH = 0;
public static final float IDLE_ROTATION_YAW = 0;
private CommandRotateTo rotateToCommand;
@Override
public void onTaskStart()
{
this.targetRotationYaw = IDLE_ROTATION_YAW;
this.targetRotationPitch = IDLE_ROTATION_PITCH;
float totalTicksYaw = Math.abs(this.targetRotationYaw - this.tileEntity.rotationYaw) / this.tileEntity.ROTATION_SPEED;
float totalTicksPitch = Math.abs(this.targetRotationPitch - this.tileEntity.rotationPitch) / this.tileEntity.ROTATION_SPEED;
this.totalTicks = Math.max(totalTicksYaw, totalTicksPitch);
this.rotateToCommand = (CommandRotateTo) this.commandManager.getNewCommand(this.tileEntity, CommandRotateTo.class, new String[] { "0", "0" });
this.rotateToCommand.onTaskStart();
}
/*@Override
@Override
protected boolean doTask()
{
/**
* Move the arm rotation to idle position if the machine is not idling
*
if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) > 0.01 || Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) > 0.01)
{
if (Math.abs(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) > 0.125)
this.tileEntity.rotationPitch += (IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * 0.05;
else
this.tileEntity.rotationPitch += Math.signum(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * (0.125 * 0.05);
if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) < 0.0125)
this.tileEntity.rotationPitch = IDLE_ROTATION_PITCH;
return this.rotateToCommand.doTask();
}
@Override
public void onTaskEnd()
{
this.rotateToCommand.onTaskEnd();
}
if (Math.abs(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) > 0.125)
this.tileEntity.rotationYaw += (IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * 0.05;
else
this.tileEntity.rotationYaw += Math.signum(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * (0.125 * 0.05);
if (Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) < 0.0125)
this.tileEntity.rotationYaw = IDLE_ROTATION_YAW;
return true;
}
return false;
}*/
/*
* @Override protected boolean doTask() { /** Move the arm rotation to idle position if the machine is not idling
*
* if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) > 0.01 || Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) > 0.01) { if (Math.abs(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) > 0.125) this.tileEntity.rotationPitch += (IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * 0.05; else this.tileEntity.rotationPitch += Math.signum(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * (0.125 * 0.05); if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) < 0.0125) this.tileEntity.rotationPitch = IDLE_ROTATION_PITCH;
*
* if (Math.abs(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) > 0.125) this.tileEntity.rotationYaw += (IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * 0.05; else this.tileEntity.rotationYaw += Math.signum(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * (0.125 * 0.05); if (Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) < 0.0125) this.tileEntity.rotationYaw = IDLE_ROTATION_YAW; return true; }
*
* return false; }
*/
@Override
public String toString()
{
return "RETURN";
}
}

View file

@ -6,10 +6,11 @@ package assemblyline.common.machine.command;
*
* @author Calclavia
*/
public class CommandRotate extends Command
public class CommandRotateBy extends Command
{
float targetRotationYaw = 0;
float targetRotationPitch = 0;
float deltaPitch = 0, deltaYaw = 90;
float totalTicks = 0f;
@Override
@ -22,6 +23,7 @@ public class CommandRotate extends Command
if (this.getArg(0) != null)
{
this.targetRotationYaw = this.tileEntity.rotationYaw + this.getFloatArg(0);
this.deltaYaw = this.getFloatArg(0);
}
else
{
@ -31,6 +33,7 @@ public class CommandRotate extends Command
if (this.getArg(1) != null)
{
this.targetRotationPitch = this.tileEntity.rotationPitch + this.getFloatArg(1);
this.deltaYaw = this.getFloatArg(1);
}
else
{
@ -98,4 +101,10 @@ public class CommandRotate extends Command
return false;
}
@Override
public String toString()
{
return "ROTATE " + Float.toString(this.deltaYaw) + " " + Float.toString(this.deltaPitch);
}
}

View file

@ -0,0 +1,108 @@
package assemblyline.common.machine.command;
/**
* Rotates the armbot to a specific direction. If not specified, it will turn right.
*
* @author Calclavia
*/
public class CommandRotateTo extends Command
{
float targetRotationYaw = 0;
float targetRotationPitch = 0;
int totalTicks = 0;
@Override
public void onTaskStart()
{
super.onTaskStart();
this.ticks = 0;
this.totalTicks = 0;
if (this.getArg(0) != null)
{
this.targetRotationYaw = this.getFloatArg(0);
}
else
{
this.targetRotationYaw = 0;
}
if (this.getArg(1) != null)
{
this.targetRotationPitch = this.getFloatArg(1);
}
else
{
this.targetRotationPitch = 0;
}
while (this.targetRotationYaw >= 360)
{
this.targetRotationYaw -= 360;
}
while (this.targetRotationYaw <= -360)
{
this.targetRotationYaw += 360;
}
if (this.targetRotationPitch > 60)
{
this.targetRotationPitch = 60;
}
if (this.targetRotationPitch < 0)
{
this.targetRotationPitch = 0;
}
int totalTicksYaw = (int) (Math.abs(this.targetRotationYaw - this.tileEntity.renderYaw) / this.tileEntity.ROTATION_SPEED);
int totalTicksPitch = (int) (Math.abs(this.targetRotationPitch - this.tileEntity.renderPitch) / this.tileEntity.ROTATION_SPEED);
this.totalTicks = (int) Math.max(totalTicksYaw, totalTicksPitch);
}
@Override
protected boolean doTask()
{
super.doTask();
/*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;
}*/
//set the rotation to the target immediately and let the client handle animating it
//wait for the client to catch up
if (Math.abs(this.tileEntity.rotationYaw - this.targetRotationYaw) > 0.001f)
this.tileEntity.rotationYaw = this.targetRotationYaw;
if (Math.abs(this.tileEntity.rotationPitch - this.targetRotationPitch) > 0.001f)
this.tileEntity.rotationPitch = this.targetRotationPitch;
if (this.ticks < this.totalTicks)
{
return true;
}
return false;
}
@Override
public String toString()
{
return "ROTATETO " + Float.toString(this.targetRotationYaw) + " " + Float.toString(this.targetRotationPitch);
}
}

View file

@ -46,4 +46,10 @@ public class CommandUse extends Command
return true;
}
@Override
public String toString()
{
return "USE " + Integer.toString(this.times);
}
}

View file

@ -31,7 +31,7 @@ public class UniversalElectricity
*/
public static final int MAJOR_VERSION = 1;
public static final int MINOR_VERSION = 2;
public static final int REVISION_VERSION = 3;
public static final int REVISION_VERSION = 4;
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
/**
@ -43,12 +43,16 @@ public class UniversalElectricity
* Conversion ratios between Buildcraft and Industrialcraft energy.
*/
// The amount of UE Joules equivalent to IC2 EU
public static double IC2_RATIO = 50;
public static double IC2_RATIO = 40;
// The amount of UE Joules equivalent to BC Minecraft Joules
public static double BC3_RATIO = 500;
public static double BC3_RATIO = 400;
public static double TO_IC2_RATIO = 1 / IC2_RATIO;
public static double TO_BC_RATIO = 1 / BC3_RATIO;
/**
* Is Universal Electricity currently being voltage sensitive? If so, all machines should
* explode under high voltage and react to different amounts of voltage differently.
*/
public static boolean isVoltageSensitive = false;
/**
@ -56,6 +60,9 @@ public class UniversalElectricity
*/
public static final Material machine = new Material(MapColor.ironColor);
/**
* A list of all mods Universal Electricity has loaded.
*/
public static final List<Object> mods = new ArrayList<Object>();
/**

View file

@ -424,7 +424,8 @@ public class ElectricityNetwork
}
/**
* Consumes electricity from all specified sides. Use this as a simple helper function.
* Requests and attempts to consume electricity from all specified sides. Use this as a simple
* helper function.
*
* @param tileEntity- The TileEntity consuming the electricity.
* @param approachDirection - The sides in which you can connect.

View file

@ -28,6 +28,7 @@ public abstract class BlockConductor extends BlockContainer
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refreshConnectedBlocks();
world.markBlockForUpdate(x, y, z);
}
}
}
@ -46,6 +47,7 @@ public abstract class BlockConductor extends BlockContainer
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refreshConnectedBlocks();
world.markBlockForUpdate(x, y, z);
}
}
}

View file

@ -0,0 +1,22 @@
package universalelectricity.prefab.modifier;
import net.minecraft.item.ItemStack;
/**
* This must be applied to an item that acts as a modifier or an upgrade.
*
* @author Calclavia
*
*/
public interface IModifier
{
/**
* @return - The name of the modifier.
*/
public String getName(ItemStack itemstack);
/**
* @return - How much effect does this modifier have?
*/
public int getEffectiveness(ItemStack itemstack);
}

View file

@ -0,0 +1,29 @@
package universalelectricity.prefab.modifier;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* This slot should be used by any container that contains an item that is a modifier. An example of
* this would be upgrade slots.
*
* @author Calclavia
*
*/
public class SlotModifier extends Slot
{
public SlotModifier(IInventory par2IInventory, int par3, int par4, int par5)
{
super(par2IInventory, par3, par4, par5);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return par1ItemStack.getItem() instanceof IModifier;
}
}

View file

@ -221,7 +221,6 @@ public class PacketManager implements IPacketHandler, IPacketReceiver
}
return data;
}
catch (IOException e)
{

View file

@ -0,0 +1,99 @@
package universalelectricity.prefab.ore;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.FMLLog;
/**
* This class is used for storing ore generation data. If you are too lazy to generate your own
* ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores
* to generate.
*
* @author Calclavia
*
*/
public abstract class OreGenBase
{
public String name;
public String oreDictionaryName;
public boolean shouldGenerate = false;
public int blockIndexTexture;
public ItemStack oreStack;
public int oreID;
public int oreMeta;
/**
* What harvest level does this machine need to be acquired?
*/
public int harvestLevel;
/**
* The predefined tool classes are "pickaxe", "shovel", "axe". You can add others for custom
* tools.
*/
public String harvestTool;
/**
* @param name - The name of the ore for display
* @param textureFile - The 16x16 png texture of your ore to override
* @param minGenerateLevel - The highest generation level of your ore
* @param maxGenerateLevel - The lowest generation level of your ore
* @param amountPerChunk - The amount of ores to generate per chunk
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with
* a lot of other coal next to it. How much do you want?
*/
public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel)
{
if (stack != null)
{
this.name = name;
this.harvestTool = harvestTool;
this.harvestLevel = harvestLevel;
this.oreDictionaryName = oreDiectionaryName;
this.oreStack = stack;
this.oreID = stack.itemID;
this.oreMeta = stack.getItemDamage();
OreDictionary.registerOre(oreDictionaryName, stack);
MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel);
}
else
{
FMLLog.severe("ItemStack is null while registering ore generation!");
}
}
public OreGenBase enable(Configuration config)
{
this.shouldGenerate = shouldGenerateOre(config, this.name);
return this;
}
/**
* Checks the config file and see if Universal Electricity should generate this ore
*/
private static boolean shouldGenerateOre(Configuration configuration, String oreName)
{
configuration.load();
boolean shouldGenerate = configuration.get("Ore Generation", "Generate " + oreName, true).getBoolean(true);
configuration.save();
return shouldGenerate;
}
public abstract void generate(World world, Random random, int varX, int varZ);
public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator);
}

View file

@ -0,0 +1,140 @@
package universalelectricity.prefab.ore;
import java.util.Random;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderEnd;
import net.minecraft.world.gen.ChunkProviderGenerate;
import net.minecraft.world.gen.ChunkProviderHell;
/**
* This class is used for storing ore generation data. If you are too lazy to generate your own
* ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores
* to generate.
*
* @author Calclavia
*
*/
public class OreGenReplace extends OreGenBase
{
public int minGenerateLevel;
public int maxGenerateLevel;
public int amountPerChunk;
public int amountPerBranch;
public int replaceID;
/**
* Dimensions to ignore ore generation
*/
public boolean ignoreSurface = false;
public boolean ignoreNether = true;
public boolean ignoreEnd = true;
/**
* @param name - The name of the ore for display
* @param textureFile - The 16x16 png texture of your ore to override
* @param minGenerateLevel - The highest generation level of your ore
* @param maxGenerateLevel - The lowest generation level of your ore
* @param amountPerChunk - The amount of ores to generate per chunk
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with
* a lot of other coal next to it. How much do you want?
*/
public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
{
super(name, oreDiectionaryName, stack, harvestTool, harvestLevel);
this.minGenerateLevel = minGenerateLevel;
this.maxGenerateLevel = maxGenerateLevel;
this.amountPerChunk = amountPerChunk;
this.amountPerBranch = amountPerBranch;
this.replaceID = replaceID;
}
public void generate(World world, Random random, int varX, int varZ)
{
try
{
for (int i = 0; i < this.amountPerChunk; i++)
{
int x = varX + random.nextInt(16);
int z = varZ + random.nextInt(16);
int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel;
this.generateReplace(world, random, x, y, z);
}
}
catch (Exception e)
{
System.out.println("Error generating ore: " + this.name);
e.printStackTrace();
}
}
public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5)
{
float var6 = par2Random.nextFloat() * (float) Math.PI;
double var7 = (double) ((float) (par3 + 8) + MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F);
double var9 = (double) ((float) (par3 + 8) - MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F);
double var11 = (double) ((float) (par5 + 8) + MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F);
double var13 = (double) ((float) (par5 + 8) - MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F);
double var15 = (double) (par4 + par2Random.nextInt(3) - 2);
double var17 = (double) (par4 + par2Random.nextInt(3) - 2);
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
{
double var20 = var7 + (var9 - var7) * (double) var19 / (double) this.amountPerBranch;
double var22 = var15 + (var17 - var15) * (double) var19 / (double) this.amountPerBranch;
double var24 = var11 + (var13 - var11) * (double) var19 / (double) this.amountPerBranch;
double var26 = par2Random.nextDouble() * (double) this.amountPerBranch / 16.0D;
double var28 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D;
double var30 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D;
int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);
for (int var38 = var32; var38 <= var35; ++var38)
{
double var39 = ((double) var38 + 0.5D - var20) / (var28 / 2.0D);
if (var39 * var39 < 1.0D)
{
for (int var41 = var33; var41 <= var36; ++var41)
{
double var42 = ((double) var41 + 0.5D - var22) / (var30 / 2.0D);
if (var39 * var39 + var42 * var42 < 1.0D)
{
for (int var44 = var34; var44 <= var37; ++var44)
{
double var45 = ((double) var44 + 0.5D - var24) / (var28 / 2.0D);
int block = par1World.getBlockId(var38, var41, var44);
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID))
{
par1World.setBlockAndMetadata(var38, var41, var44, this.oreID, this.oreMeta);
}
}
}
}
}
}
}
return true;
}
@Override
public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator)
{
if (!this.shouldGenerate) { return false; }
if (this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate) { return false; }
if (this.ignoreNether && chunkGenerator instanceof ChunkProviderHell) { return false; }
if (this.ignoreEnd && chunkGenerator instanceof ChunkProviderEnd) { return false; }
return true;
}
}

View file

@ -0,0 +1,17 @@
package universalelectricity.prefab.ore;
import net.minecraft.item.ItemStack;
public class OreGenReplaceStone extends OreGenReplace
{
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
{
super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel);
}
// A simplified version of the constructor
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch)
{
this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1);
}
}

View file

@ -0,0 +1,75 @@
package universalelectricity.prefab.ore;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.registry.GameRegistry;
public class OreGenerator implements IWorldGenerator
{
public static boolean isInitiated = false;
/**
* Add your ore data to this list of ores for it to automatically generate! No hassle indeed!
*/
private static final List<OreGenBase> ORES_TO_GENERATE = new ArrayList<OreGenBase>();
/**
* Adds an ore to the ore generate list. Do this in pre-init.
*/
public static void addOre(OreGenBase data)
{
if (!isInitiated)
{
GameRegistry.registerWorldGenerator(new OreGenerator());
}
ORES_TO_GENERATE.add(data);
}
/**
* Checks to see if this ore
*
* @param oreName
* @return
*/
public static boolean oreExists(String oreName)
{
for (OreGenBase ore : ORES_TO_GENERATE)
{
if (ore.oreDictionaryName == oreName) { return true; }
}
return false;
}
/**
* Removes an ore to the ore generate list. Do this in init.
*/
public static void removeOre(OreGenBase data)
{
ORES_TO_GENERATE.remove(data);
}
@Override
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
chunkX = chunkX << 4;
chunkZ = chunkZ << 4;
// Checks to make sure this is the normal
// world
for (OreGenBase oreData : ORES_TO_GENERATE)
{
if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator))
{
oreData.generate(world, rand, chunkX, chunkZ);
}
}
}
}

View file

@ -0,0 +1,37 @@
package universalelectricity.prefab.potion;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.registry.LanguageRegistry;
public abstract class CustomPotion extends Potion
{
/**
* Creates a new type of potion
*
* @param id - The ID of this potion. Make it greater than 20.
* @param isBadEffect - Is this potion a good potion or a bad one?
* @param color - The color of this potion.
* @param name - The name of this potion.
*/
public CustomPotion(int id, boolean isBadEffect, int color, String name)
{
super(id, isBadEffect, color);
this.setPotionName("potion." + name);
LanguageRegistry.instance().addStringLocalization(this.getName(), name);
}
@Override
public Potion setIconIndex(int par1, int par2)
{
super.setIconIndex(par1, par2);
return this;
}
/**
* You must register all your potion effects during mod initialization!
*/
public void register()
{
Potion.potionTypes[this.getId()] = this;
}
}

View file

@ -0,0 +1,40 @@
package universalelectricity.prefab.potion;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
public class CustomPotionEffect extends PotionEffect
{
public CustomPotionEffect(int potionID, int duration, int amplifier)
{
super(potionID, duration, amplifier);
}
public CustomPotionEffect(Potion potion, int duration, int amplifier)
{
this(potion.getId(), duration, amplifier);
}
/**
* Creates a potion effect with custom curable items.
*
* @param curativeItems - ItemStacks that can cure this potion effect
*/
public CustomPotionEffect(int potionID, int duration, int amplifier, List<ItemStack> curativeItems)
{
super(potionID, duration, amplifier);
if (curativeItems == null)
{
this.setCurativeItems(new ArrayList<ItemStack>());
}
else
{
this.setCurativeItems(curativeItems);
}
}
}

View file

@ -8,6 +8,9 @@ import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import org.bouncycastle.util.Arrays;
import universalelectricity.core.electricity.Electricity;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.electricity.ElectricityNetwork;
@ -147,6 +150,17 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
this.refreshConnectedBlocks();
}
@Override
public void updateEntity()
{
super.updateEntity();
if (this.ticks % 300 == 0)
{
this.refreshConnectedBlocks();
}
}
@Override
public void reset()
{
@ -165,12 +179,20 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
{
if (!this.worldObj.isRemote)
{
boolean[] previousConnections = this.visuallyConnected.clone();
for (byte i = 0; i < 6; i++)
{
this.updateConnection(Vector3.getConnectorFromSide(this.worldObj, new Vector3(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i));
}
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
/**
* Only send packet updates if visuallyConnected changed.
*/
if (!Arrays.areEqual(previousConnections, this.visuallyConnected))
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
}

View file

@ -0,0 +1,100 @@
package universalelectricity.prefab.tile;
import java.util.EnumSet;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.electricity.ElectricityNetwork;
import universalelectricity.core.electricity.ElectricityPack;
/**
* This class should be extended by TileEntities that run on electricity but do not store them.
* Things such as electric furnaces should extend this. Take this class mainly as an example.
*
* @author Calclavia
*
*/
public abstract class TileEntityElectricityRunnable extends TileEntityElectricityReceiver
{
/**
* The amount of watts received this tick. This variable should be deducted when used.
*/
public double prevWatts, wattsReceived = 0;
@Override
public void updateEntity()
{
super.updateEntity();
this.prevWatts = this.wattsReceived;
/**
* ElectricityManager works on server side.
*/
if (!this.worldObj.isRemote)
{
/**
* If the machine is disabled, stop requesting electricity.
*/
if (!this.isDisabled())
{
ElectricityPack electricityPack = ElectricityNetwork.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest());
this.onReceive(electricityPack);
}
else
{
ElectricityNetwork.consumeFromMultipleSides(this, new ElectricityPack());
}
}
}
/**
* Returns the amount of energy being requested this tick. Return an empty ElectricityPack if no
* electricity is desired.
*/
public ElectricityPack getRequest()
{
return new ElectricityPack();
}
/**
* The sides in which this machine can consume electricity from.
*/
protected EnumSet<ForgeDirection> getConsumingSides()
{
return ElectricityConnections.getDirections(this);
}
/**
* Called right after electricity is transmitted to the TileEntity. Override this if you wish to
* have another effect for a voltage overcharge.
*
* @param electricityPack
*/
public void onReceive(ElectricityPack electricityPack)
{
/**
* Creates an explosion if the voltage is too high.
*/
if (UniversalElectricity.isVoltageSensitive)
{
if (electricityPack.voltage > this.getVoltage())
{
this.worldObj.createExplosion(null, this.xCoord, this.yCoord, this.zCoord, 1.5f, true);
return;
}
}
this.wattsReceived = Math.min(this.wattsReceived + electricityPack.getWatts(), this.getWattBuffer());
}
/**
* @return The amount of internal buffer that may be stored within this machine. This will make
* the machine run smoother as electricity might not always be consistent.
*/
public double getWattBuffer()
{
return this.getRequest().getWatts() * 2;
}
}

View file

@ -0,0 +1,114 @@
package universalelectricity.prefab.tile;
import java.util.EnumSet;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.electricity.ElectricityNetwork;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.implement.IJouleStorage;
public abstract class TileEntityElectricityStorage extends TileEntityElectricityReceiver implements IJouleStorage
{
/**
* The amount of joules stored within this machine. Use get and set functions instead of
* referencing to this variable.
*/
private double joules = 0;
public double prevJoules = 0;
@Override
public void updateEntity()
{
super.updateEntity();
this.prevJoules = joules;
if (!this.worldObj.isRemote)
{
if (!this.isDisabled())
{
ElectricityPack electricityPack = ElectricityNetwork.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest());
this.onReceive(electricityPack);
}
else
{
ElectricityNetwork.consumeFromMultipleSides(this, new ElectricityPack());
}
}
}
/**
* The sides in which this machine can consume electricity from.
*/
protected EnumSet<ForgeDirection> getConsumingSides()
{
return ElectricityConnections.getDirections(this);
}
/**
* Returns the amount of energy being requested this tick. Return an empty ElectricityPack if no
* electricity is desired.
*/
public ElectricityPack getRequest()
{
return new ElectricityPack((this.getMaxJoules() - this.getJoules()) / this.getVoltage(), this.getVoltage());
}
/**
* Called right after electricity is transmitted to the TileEntity. Override this if you wish to
* have another effect for a voltage overcharge.
*
* @param electricityPack
*/
public void onReceive(ElectricityPack electricityPack)
{
/**
* Creates an explosion if the voltage is too high.
*/
if (UniversalElectricity.isVoltageSensitive)
{
if (electricityPack.voltage > this.getVoltage())
{
this.worldObj.createExplosion(null, this.xCoord, this.yCoord, this.zCoord, 1.5f, true);
return;
}
}
this.setJoules(this.getJoules() + electricityPack.getWatts());
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.joules = par1NBTTagCompound.getDouble("joules");
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setDouble("joules", this.joules);
}
@Override
public double getJoules(Object... data)
{
return this.joules;
}
@Override
public void setJoules(double joules, Object... data)
{
this.joules = Math.max(Math.min(joules, this.getMaxJoules()), 0);
}
}