updated to UE 3.0
This commit is contained in:
parent
181d2f885f
commit
738ffa7b2a
131 changed files with 604 additions and 9765 deletions
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class BuildCraftAPI
|
||||
{
|
||||
|
||||
public static final int LAST_ORIGINAL_BLOCK = 122;
|
||||
public static final int LAST_ORIGINAL_ITEM = 126;
|
||||
|
||||
public static final boolean[] softBlocks = new boolean[Block.blocksList.length];
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
/**
|
||||
* To be implemented by TileEntities able to provide a square area on the world, typically
|
||||
* BuildCraft markers.
|
||||
*/
|
||||
public interface IAreaProvider
|
||||
{
|
||||
|
||||
public int xMin();
|
||||
|
||||
public int yMin();
|
||||
|
||||
public int zMin();
|
||||
|
||||
public int xMax();
|
||||
|
||||
public int yMax();
|
||||
|
||||
public int zMax();
|
||||
|
||||
/**
|
||||
* Remove from the world all objects used to define the area.
|
||||
*/
|
||||
public void removeFromWorld();
|
||||
|
||||
}
|
31
dependencies/buildcraft/api/core/IBox.java
vendored
31
dependencies/buildcraft/api/core/IBox.java
vendored
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IBox
|
||||
{
|
||||
|
||||
public void expand(int amount);
|
||||
|
||||
public void contract(int amount);
|
||||
|
||||
public boolean contains(int x, int y, int z);
|
||||
|
||||
public Position pMin();
|
||||
|
||||
public Position pMax();
|
||||
|
||||
public void createLasers(World world, LaserKind kind);
|
||||
|
||||
public void deleteLasers();
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.util.Icon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IIconProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @param iconIndex
|
||||
* @return
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getIcon(int iconIndex);
|
||||
|
||||
/**
|
||||
* A call for the provider to register its Icons. This may be called multiple times but should
|
||||
* only be executed once per provider
|
||||
*
|
||||
* @param iconRegister
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IconRegister iconRegister);
|
||||
|
||||
}
|
15
dependencies/buildcraft/api/core/LaserKind.java
vendored
15
dependencies/buildcraft/api/core/LaserKind.java
vendored
|
@ -1,15 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
public enum LaserKind
|
||||
{
|
||||
Red, Blue, Stripes
|
||||
}
|
161
dependencies/buildcraft/api/core/Position.java
vendored
161
dependencies/buildcraft/api/core/Position.java
vendored
|
@ -1,161 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class Position
|
||||
{
|
||||
|
||||
public double x, y, z;
|
||||
public ForgeDirection orientation;
|
||||
|
||||
public Position(double ci, double cj, double ck)
|
||||
{
|
||||
x = ci;
|
||||
y = cj;
|
||||
z = ck;
|
||||
orientation = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public Position(double ci, double cj, double ck, ForgeDirection corientation)
|
||||
{
|
||||
x = ci;
|
||||
y = cj;
|
||||
z = ck;
|
||||
orientation = corientation;
|
||||
}
|
||||
|
||||
public Position(Position p)
|
||||
{
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
orientation = p.orientation;
|
||||
}
|
||||
|
||||
public Position(NBTTagCompound nbttagcompound)
|
||||
{
|
||||
x = nbttagcompound.getDouble("i");
|
||||
y = nbttagcompound.getDouble("j");
|
||||
z = nbttagcompound.getDouble("k");
|
||||
|
||||
orientation = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public Position(TileEntity tile)
|
||||
{
|
||||
x = tile.xCoord;
|
||||
y = tile.yCoord;
|
||||
z = tile.zCoord;
|
||||
}
|
||||
|
||||
public void moveRight(double step)
|
||||
{
|
||||
switch (orientation)
|
||||
{
|
||||
case SOUTH:
|
||||
x = x - step;
|
||||
break;
|
||||
case NORTH:
|
||||
x = x + step;
|
||||
break;
|
||||
case EAST:
|
||||
z = z + step;
|
||||
break;
|
||||
case WEST:
|
||||
z = z - step;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public void moveLeft(double step)
|
||||
{
|
||||
moveRight(-step);
|
||||
}
|
||||
|
||||
public void moveForwards(double step)
|
||||
{
|
||||
switch (orientation)
|
||||
{
|
||||
case UP:
|
||||
y = y + step;
|
||||
break;
|
||||
case DOWN:
|
||||
y = y - step;
|
||||
break;
|
||||
case SOUTH:
|
||||
z = z + step;
|
||||
break;
|
||||
case NORTH:
|
||||
z = z - step;
|
||||
break;
|
||||
case EAST:
|
||||
x = x + step;
|
||||
break;
|
||||
case WEST:
|
||||
x = x - step;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public void moveBackwards(double step)
|
||||
{
|
||||
moveForwards(-step);
|
||||
}
|
||||
|
||||
public void moveUp(double step)
|
||||
{
|
||||
switch (orientation)
|
||||
{
|
||||
case SOUTH:
|
||||
case NORTH:
|
||||
case EAST:
|
||||
case WEST:
|
||||
y = y + step;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void moveDown(double step)
|
||||
{
|
||||
moveUp(-step);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound)
|
||||
{
|
||||
nbttagcompound.setDouble("i", x);
|
||||
nbttagcompound.setDouble("j", y);
|
||||
nbttagcompound.setDouble("k", z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{" + x + ", " + y + ", " + z + "}";
|
||||
}
|
||||
|
||||
public Position min(Position p)
|
||||
{
|
||||
return new Position(p.x > x ? x : p.x, p.y > y ? y : p.y, p.z > z ? z : p.z);
|
||||
}
|
||||
|
||||
public Position max(Position p)
|
||||
{
|
||||
return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SafeTimeTracker
|
||||
{
|
||||
|
||||
private long lastMark = Long.MIN_VALUE;
|
||||
private long duration = -1;
|
||||
|
||||
/**
|
||||
* Return true if a given delay has passed since last time marked was called successfully.
|
||||
*/
|
||||
public boolean markTimeIfDelay(World world, long delay)
|
||||
{
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
long currentTime = world.getTotalWorldTime();
|
||||
|
||||
if (currentTime < lastMark)
|
||||
{
|
||||
lastMark = currentTime;
|
||||
return false;
|
||||
}
|
||||
else if (lastMark + delay <= currentTime)
|
||||
{
|
||||
duration = currentTime - lastMark;
|
||||
lastMark = currentTime;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public long durationOfLastDelay()
|
||||
{
|
||||
return duration > 0 ? duration : 0;
|
||||
}
|
||||
|
||||
public void markTime(World world)
|
||||
{
|
||||
lastMark = world.getTotalWorldTime();
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class StackWrapper
|
||||
{
|
||||
|
||||
public final ItemStack stack;
|
||||
|
||||
public StackWrapper(ItemStack stack)
|
||||
{
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 5;
|
||||
hash = 67 * hash + stack.itemID;
|
||||
hash = 67 * hash + stack.getItemDamage();
|
||||
if (stack.stackTagCompound != null)
|
||||
hash = 67 * hash + stack.stackTagCompound.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final StackWrapper other = (StackWrapper) obj;
|
||||
if (stack.itemID != other.stack.itemID)
|
||||
return false;
|
||||
if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage())
|
||||
return false;
|
||||
if (stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.power;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Essentially only used for Wooden Power Pipe connection rules.
|
||||
*
|
||||
* This Tile Entity interface allows you to indicate that a block can emit power from a specific
|
||||
* side.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public interface IPowerEmitter
|
||||
{
|
||||
|
||||
public boolean canEmitPowerFrom(ForgeDirection side);
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.power;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
|
||||
/**
|
||||
* This interface should be implemented by any Tile Entity that wishes to be able to receive power.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public interface IPowerReceptor
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the PowerReceiver for this side of the block. You can return the same PowerReceiver for
|
||||
* all sides or one for each side.
|
||||
*
|
||||
* You should NOT return null to this method unless you mean to NEVER receive power from that
|
||||
* side. Returning null, after previous returning a PowerReceiver, will most likely cause pipe
|
||||
* connections to derp out and engines to eventually explode.
|
||||
*
|
||||
* @param side
|
||||
* @return
|
||||
*/
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side);
|
||||
|
||||
/**
|
||||
* Call back from the PowerHandler that is called when the stored power exceeds the activation
|
||||
* power.
|
||||
*
|
||||
* It can be triggered by update() calls or power modification calls.
|
||||
*
|
||||
* @param workProvider
|
||||
*/
|
||||
public void doWork(PowerHandler workProvider);
|
||||
|
||||
public World getWorld();
|
||||
}
|
455
dependencies/buildcraft/api/power/PowerHandler.java
vendored
455
dependencies/buildcraft/api/power/PowerHandler.java
vendored
|
@ -1,455 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.power;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
|
||||
public final class PowerHandler
|
||||
{
|
||||
|
||||
public static enum Type
|
||||
{
|
||||
|
||||
ENGINE, GATE, MACHINE, PIPE, STORAGE;
|
||||
|
||||
public boolean canReceiveFromPipes()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case MACHINE:
|
||||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean eatsEngineExcess()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case MACHINE:
|
||||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PerditionCalculator
|
||||
{
|
||||
|
||||
public static final float DEFAULT_POWERLOSS = 1F;
|
||||
public static final float MIN_POWERLOSS = 0.01F;
|
||||
private final float powerLoss;
|
||||
|
||||
public PerditionCalculator()
|
||||
{
|
||||
powerLoss = DEFAULT_POWERLOSS;
|
||||
}
|
||||
|
||||
public PerditionCalculator(float powerLoss)
|
||||
{
|
||||
if (powerLoss < MIN_POWERLOSS)
|
||||
{
|
||||
powerLoss = MIN_POWERLOSS;
|
||||
}
|
||||
this.powerLoss = powerLoss;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the perdition algorithm to the current stored energy. This function can only be
|
||||
* called once per tick, but it might not be called every tick. It is triggered by any
|
||||
* manipulation of the stored energy.
|
||||
*
|
||||
* @param powerHandler the PowerHandler requesting the perdition update
|
||||
* @param current the current stored energy
|
||||
* @param ticksPassed ticks since the last time this function was called
|
||||
* @return
|
||||
*/
|
||||
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed)
|
||||
{
|
||||
current -= powerLoss * ticksPassed;
|
||||
if (current < 0)
|
||||
{
|
||||
current = 0;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
|
||||
private float minEnergyReceived;
|
||||
private float maxEnergyReceived;
|
||||
private float maxEnergyStored;
|
||||
private float activationEnergy;
|
||||
private float energyStored = 0;
|
||||
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
|
||||
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker();
|
||||
private final SafeTimeTracker perditionTracker = new SafeTimeTracker();
|
||||
public final int[] powerSources = new int[6];
|
||||
public final IPowerReceptor receptor;
|
||||
private PerditionCalculator perdition;
|
||||
private final PowerReceiver receiver;
|
||||
private final Type type;
|
||||
|
||||
public PowerHandler(IPowerReceptor receptor, Type type)
|
||||
{
|
||||
this.receptor = receptor;
|
||||
this.type = type;
|
||||
this.receiver = new PowerReceiver();
|
||||
this.perdition = DEFAULT_PERDITION;
|
||||
}
|
||||
|
||||
public PowerReceiver getPowerReceiver()
|
||||
{
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public float getMinEnergyReceived()
|
||||
{
|
||||
return minEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyReceived()
|
||||
{
|
||||
return maxEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyStored()
|
||||
{
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public float getActivationEnergy()
|
||||
{
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public float getEnergyStored()
|
||||
{
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup your PowerHandler's settings.
|
||||
*
|
||||
* @param minEnergyReceived This is the minimum about of power that will be accepted by the
|
||||
* PowerHandler. This should generally be greater than the activationEnergy if you plan to use
|
||||
* the doWork() callback. Anything greater than 1 will prevent Redstone Engines from powering
|
||||
* this Provider.
|
||||
* @param maxEnergyReceived The maximum amount of power accepted by the PowerHandler. This
|
||||
* should generally be less than 500. Too low and larger engines will overheat while trying to
|
||||
* power the machine. Too high, and the engines will never warm up. Greater values also place
|
||||
* greater strain on the power net.
|
||||
* @param activationEnergy If the stored energy is greater than this value, the doWork()
|
||||
* callback is called (once per tick).
|
||||
* @param maxStoredEnergy The maximum amount of power this PowerHandler can store. Values tend
|
||||
* to range between 100 and 5000. With 1000 and 1500 being common.
|
||||
*/
|
||||
public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy)
|
||||
{
|
||||
if (minEnergyReceived > maxEnergyReceived)
|
||||
{
|
||||
maxEnergyReceived = minEnergyReceived;
|
||||
}
|
||||
this.minEnergyReceived = minEnergyReceived;
|
||||
this.maxEnergyReceived = maxEnergyReceived;
|
||||
this.maxEnergyStored = maxStoredEnergy;
|
||||
this.activationEnergy = activationEnergy;
|
||||
}
|
||||
|
||||
public void configurePowerPerdition(int powerLoss, int powerLossRegularity)
|
||||
{
|
||||
if (powerLoss == 0 || powerLossRegularity == 0)
|
||||
{
|
||||
perdition = new PerditionCalculator(0);
|
||||
return;
|
||||
}
|
||||
perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to define a new PerditionCalculator class to handler perdition calculations.
|
||||
*
|
||||
* For example if you want exponentially increasing loss based on amount stored.
|
||||
*
|
||||
* @param perdition
|
||||
*/
|
||||
public void setPerdition(PerditionCalculator perdition)
|
||||
{
|
||||
if (perdition == null)
|
||||
perdition = DEFAULT_PERDITION;
|
||||
this.perdition = perdition;
|
||||
}
|
||||
|
||||
public PerditionCalculator getPerdition()
|
||||
{
|
||||
if (perdition == null)
|
||||
return DEFAULT_PERDITION;
|
||||
return perdition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticks the power handler. You should call this if you can, but its not required.
|
||||
*
|
||||
* If you don't call it, the possibility exists for some weirdness with the perdition algorithm
|
||||
* and work callback as its possible they will not be called on every tick they otherwise would
|
||||
* be. You should be able to design around this though if you are aware of the limitations.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
applyPerdition();
|
||||
applyWork();
|
||||
validateEnergy();
|
||||
}
|
||||
|
||||
private void applyPerdition()
|
||||
{
|
||||
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0)
|
||||
{
|
||||
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (newEnergy == 0 || newEnergy < energyStored)
|
||||
energyStored = newEnergy;
|
||||
else
|
||||
energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
validateEnergy();
|
||||
}
|
||||
}
|
||||
|
||||
private void applyWork()
|
||||
{
|
||||
if (energyStored >= activationEnergy)
|
||||
{
|
||||
if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1))
|
||||
{
|
||||
receptor.doWork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSources(ForgeDirection source)
|
||||
{
|
||||
if (sourcesTracker.markTimeIfDelay(receptor.getWorld(), 1))
|
||||
{
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
powerSources[i] -= sourcesTracker.durationOfLastDelay();
|
||||
if (powerSources[i] < 0)
|
||||
{
|
||||
powerSources[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null)
|
||||
powerSources[source.ordinal()] = 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract energy from the PowerHandler. You must call this even if doWork() triggers.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @param doUse
|
||||
* @return amount used
|
||||
*/
|
||||
public float useEnergy(float min, float max, boolean doUse)
|
||||
{
|
||||
applyPerdition();
|
||||
|
||||
float result = 0;
|
||||
|
||||
if (energyStored >= min)
|
||||
{
|
||||
if (energyStored <= max)
|
||||
{
|
||||
result = energyStored;
|
||||
if (doUse)
|
||||
{
|
||||
energyStored = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = max;
|
||||
if (doUse)
|
||||
{
|
||||
energyStored -= max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateEnergy();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
readFromNBT(data, "powerProvider");
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag)
|
||||
{
|
||||
NBTTagCompound nbt = data.getCompoundTag(tag);
|
||||
energyStored = nbt.getFloat("storedEnergy");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
writeToNBT(data, "powerProvider");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag)
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setFloat("storedEnergy", energyStored);
|
||||
data.setCompoundTag(tag, nbt);
|
||||
}
|
||||
|
||||
public final class PowerReceiver
|
||||
{
|
||||
|
||||
private PowerReceiver()
|
||||
{
|
||||
}
|
||||
|
||||
public float getMinEnergyReceived()
|
||||
{
|
||||
return minEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyReceived()
|
||||
{
|
||||
return maxEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyStored()
|
||||
{
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public float getActivationEnergy()
|
||||
{
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public float getEnergyStored()
|
||||
{
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
public Type getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
PowerHandler.this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount of power that this PowerHandler currently needs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public float powerRequest()
|
||||
{
|
||||
update();
|
||||
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add power to the PowerReceiver from an external source.
|
||||
*
|
||||
* @param quantity
|
||||
* @param from
|
||||
* @return the amount of power used
|
||||
*/
|
||||
public float receiveEnergy(Type source, final float quantity, ForgeDirection from)
|
||||
{
|
||||
float used = quantity;
|
||||
if (source == Type.ENGINE)
|
||||
{
|
||||
if (used < minEnergyReceived)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (used > maxEnergyReceived)
|
||||
{
|
||||
used = maxEnergyReceived;
|
||||
}
|
||||
}
|
||||
|
||||
updateSources(from);
|
||||
|
||||
used = addEnergy(used);
|
||||
|
||||
applyWork();
|
||||
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess())
|
||||
{
|
||||
return Math.min(quantity, maxEnergyReceived);
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the amount the power changed by
|
||||
*/
|
||||
public float addEnergy(float quantity)
|
||||
{
|
||||
energyStored += quantity;
|
||||
|
||||
if (energyStored > maxEnergyStored)
|
||||
{
|
||||
quantity -= energyStored - maxEnergyStored;
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
else if (energyStored < 0)
|
||||
{
|
||||
quantity -= energyStored;
|
||||
energyStored = 0;
|
||||
}
|
||||
|
||||
applyPerdition();
|
||||
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setEnergy(float quantity)
|
||||
{
|
||||
this.energyStored = quantity;
|
||||
validateEnergy();
|
||||
}
|
||||
|
||||
public boolean isPowerSource(ForgeDirection from)
|
||||
{
|
||||
return powerSources[from.ordinal()] != 0;
|
||||
}
|
||||
|
||||
private void validateEnergy()
|
||||
{
|
||||
if (energyStored < 0)
|
||||
{
|
||||
energyStored = 0;
|
||||
}
|
||||
if (energyStored > maxEnergyStored)
|
||||
{
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
}
|
||||
}
|
151
dependencies/cofh/api/energy/EnergyStorage.java
vendored
151
dependencies/cofh/api/energy/EnergyStorage.java
vendored
|
@ -1,151 +0,0 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class EnergyStorage implements IEnergyStorage {
|
||||
|
||||
protected int energy;
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public EnergyStorage(int capacity) {
|
||||
|
||||
this(capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxTransfer) {
|
||||
|
||||
this(capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
this.energy = nbt.getInteger("Energy");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
nbt.setInteger("Energy", energy);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
public int getMaxExtract() {
|
||||
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are
|
||||
* guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
|
||||
this.energy = energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
|
||||
this.energy += energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyStorage */
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
*
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyContainerItem {
|
||||
|
||||
/**
|
||||
* Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be charged.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be sent into the item.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received by the item.
|
||||
*/
|
||||
int receiveEnergy(ItemStack container, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally
|
||||
* discharged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be discharged.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted from the item.
|
||||
* @param simulate
|
||||
* If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the item.
|
||||
*/
|
||||
int extractEnergy(ItemStack container, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Get the amount of energy currently stored in the container item.
|
||||
*/
|
||||
int getEnergyStored(ItemStack container);
|
||||
|
||||
/**
|
||||
* Get the max amount of energy that can be stored in the container item.
|
||||
*/
|
||||
int getMaxEnergyStored(ItemStack container);
|
||||
|
||||
}
|
56
dependencies/cofh/api/energy/IEnergyHandler.java
vendored
56
dependencies/cofh/api/energy/IEnergyHandler.java
vendored
|
@ -1,56 +0,0 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
*
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyHandler {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to received.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted to.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to extract.
|
||||
* @param simulate
|
||||
* If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns true if the Handler functions on a given side - if a Tile Entity can receive and/or send energy from a given side, this should return true.
|
||||
*/
|
||||
boolean canInterface(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
45
dependencies/cofh/api/energy/IEnergyStorage.java
vendored
45
dependencies/cofh/api/energy/IEnergyStorage.java
vendored
|
@ -1,45 +0,0 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
/**
|
||||
* An energy storage is the unit of interaction with Energy inventories.
|
||||
*
|
||||
* A reference implementation can be found at {@link EnergyStorage}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyStorage {
|
||||
|
||||
/**
|
||||
* Adds energy to the storage. Returns quantity of energy that was accepted.
|
||||
*
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be inserted.
|
||||
* @param simulate
|
||||
* If TRUE, the insertion will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
|
||||
*/
|
||||
int receiveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Removes energy from the storage. Returns quantity of energy that was removed.
|
||||
*
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
|
||||
*/
|
||||
int extractEnergy(int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored();
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored();
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package ic2.api.energy.event;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
/**
|
||||
* Base class for energy net events, don't use it directly.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileEvent extends WorldEvent {
|
||||
public final IEnergyTile energyTile;
|
||||
|
||||
public EnergyTileEvent(IEnergyTile energyTile) {
|
||||
super(((TileEntity) energyTile).worldObj);
|
||||
|
||||
this.energyTile = energyTile;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package ic2.api.energy.event;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
/**
|
||||
* Event announcing new energy tiles.
|
||||
*
|
||||
* This event notifies subscribers of loaded energy tiles, e.g. after getting
|
||||
* loaded through the chunk they are in or after being placed down by the
|
||||
* player or another deployer mechanism.
|
||||
*
|
||||
* Every energy tile which wants to get connected to the IC2 Energy Network has
|
||||
* to either post this event or alternatively call EnergyNet.addTileEntity().
|
||||
*
|
||||
* You may use this event to build a static representation of energy tiles for
|
||||
* your own energy grid implementation if you need to. It's not required if you
|
||||
* always lookup energy paths on demand.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileLoadEvent extends EnergyTileEvent {
|
||||
public EnergyTileLoadEvent(IEnergyTile energyTile) {
|
||||
super(energyTile);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package ic2.api.energy.event;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
/**
|
||||
* Event announcing terminated energy tiles.
|
||||
*
|
||||
* This event notifies subscribers of unloaded energy tiles, e.g. after getting
|
||||
* unloaded through the chunk they are in or after being destroyed by the
|
||||
* player or another block pick/destruction mechanism.
|
||||
*
|
||||
* Every energy tile which wants to get disconnected from the IC2 Energy
|
||||
* Network has to either post this event or alternatively call
|
||||
* EnergyNet.removeTileEntity().
|
||||
*
|
||||
* You may use this event to build a static representation of energy tiles for
|
||||
* your own energy grid implementation if you need to. It's not required if you
|
||||
* always lookup energy paths on demand.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileUnloadEvent extends EnergyTileEvent {
|
||||
public EnergyTileUnloadEvent(IEnergyTile energyTile) {
|
||||
super(energyTile);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* For internal/multi-block usage only.
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyAcceptor extends IEnergyTile {
|
||||
/**
|
||||
* Determine if this acceptor can accept current from an adjacent emitter in a direction.
|
||||
*
|
||||
* The TileEntity in the emitter parameter is what was originally added to the energy net,
|
||||
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
|
||||
*
|
||||
* @param emitter energy emitter
|
||||
* @param direction direction the energy is being received from
|
||||
*/
|
||||
boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction);
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
/**
|
||||
* Tile entities which conduct energy pulses without buffering (mostly cables) have to implement this
|
||||
* interface.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyConductor extends IEnergyAcceptor, IEnergyEmitter {
|
||||
/**
|
||||
* Energy loss for the conductor in EU per block.
|
||||
*
|
||||
* @return Energy loss
|
||||
*/
|
||||
double getConductionLoss();
|
||||
|
||||
/**
|
||||
* Amount of energy the insulation will handle before shocking nearby players and mobs.
|
||||
*
|
||||
* @return Insulation energy absorption in EU
|
||||
*/
|
||||
int getInsulationEnergyAbsorption();
|
||||
|
||||
/**
|
||||
* Amount of energy the insulation will handle before it is destroyed.
|
||||
* Ensure that this value is greater than the insulation energy absorption + 64.
|
||||
*
|
||||
* @return Insulation-destroying energy in EU
|
||||
*/
|
||||
int getInsulationBreakdownEnergy();
|
||||
|
||||
/**
|
||||
* Amount of energy the conductor will handle before it melts.
|
||||
*
|
||||
* @return Conductor-destroying energy in EU
|
||||
*/
|
||||
int getConductorBreakdownEnergy();
|
||||
|
||||
/**
|
||||
* Remove the conductor's insulation if the insulation breakdown energy was exceeded.
|
||||
*
|
||||
* @see #getInsulationBreakdownEnergy()
|
||||
*/
|
||||
void removeInsulation();
|
||||
|
||||
/**
|
||||
* Remove the conductor if the conductor breakdown energy was exceeded.
|
||||
*
|
||||
* @see #getConductorBreakdownEnergy()
|
||||
*/
|
||||
void removeConductor();
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* For internal/multi-block usage only.
|
||||
*
|
||||
* @see IEnergySource
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyEmitter extends IEnergyTile {
|
||||
/**
|
||||
* Determine if this emitter can emit energy to an adjacent receiver.
|
||||
*
|
||||
* The TileEntity in the receiver parameter is what was originally added to the energy net,
|
||||
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
|
||||
*
|
||||
* @param receiver receiver, may be an IMetaDelegate
|
||||
* @param direction direction the receiver is from the emitter
|
||||
* @return Whether energy should be emitted
|
||||
*/
|
||||
boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction);
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Allows a tile entity (mostly a machine) to receive energy.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergySink extends IEnergyAcceptor {
|
||||
/**
|
||||
* Determine how much energy the sink accepts.
|
||||
*
|
||||
* This value is unrelated to getMaxSafeInput().
|
||||
*
|
||||
* Make sure that injectEnergy() does accepts energy if demandsEnergy() returns anything > 0.
|
||||
*
|
||||
* @return max accepted input in eu
|
||||
*/
|
||||
double demandedEnergyUnits();
|
||||
|
||||
/**
|
||||
* Transfer energy to the sink.
|
||||
*
|
||||
* It's highly recommended to accept all energy by letting the internal buffer overflow to
|
||||
* increase the performance and accuracy of the distribution simulation.
|
||||
*
|
||||
* @param directionFrom direction from which the energy comes from
|
||||
* @param amount energy to be transferred
|
||||
* @return Energy not consumed (leftover)
|
||||
*/
|
||||
double injectEnergyUnits(ForgeDirection directionFrom, double amount);
|
||||
|
||||
/**
|
||||
* Determine the amount of eu which can be safely injected into the specific energy sink without exploding.
|
||||
*
|
||||
* Typical values are 32 for LV, 128 for MV, 512 for HV and 2048 for EV. A value of Integer.MAX_VALUE indicates no
|
||||
* limit.
|
||||
*
|
||||
* This value is unrelated to demandsEnergy().
|
||||
*
|
||||
* @return max safe input in eu
|
||||
*/
|
||||
int getMaxSafeInput();
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
/**
|
||||
* Allows a tile entity (mostly a generator) to emit energy.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergySource extends IEnergyEmitter {
|
||||
/**
|
||||
* Energy output provided by the source this tick.
|
||||
* This is typically Math.min(stored energy, max output/tick).
|
||||
*
|
||||
* @return Energy offered this tick
|
||||
*/
|
||||
double getOfferedEnergy();
|
||||
|
||||
/**
|
||||
* Draw energy from this source's buffer.
|
||||
*
|
||||
* If the source doesn't have a buffer, this is a no-op.
|
||||
*
|
||||
* @param amount amount of EU to draw, may be negative
|
||||
*/
|
||||
void drawEnergy(double amount);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
/**
|
||||
* For internal usage only, base class for all energy tiles.
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergySource
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyTile {
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Interface for grouping multi-block structures to a single energy net delegate.
|
||||
*
|
||||
* The energy net uses TileEntity to refer to a specific xyz+world position. If multiple of those
|
||||
* positions should belong to the same functional structure, i.e. they consume or produce energy
|
||||
* only once for the whole multi-block instead of once per every single block, this interface
|
||||
* allows to do so.
|
||||
*
|
||||
* The tile entity implementing IMetaDelegate has to be added/removed to/from the energy net
|
||||
* instead of every single sub-TileEntity. The energy net interaction will be handled by the
|
||||
* IMetaDelegate TileEntity as well.
|
||||
*
|
||||
* The sub tile array TileEntity[] just provides optional connectivity (IEnergyAcceptor,
|
||||
* IEnergyEmitter) and mandatory position (x, y, z, World) data.
|
||||
* If the connectivity data on the sub tile is missing, the meta delegate is queried instead.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IMetaDelegate extends IEnergyTile {
|
||||
/**
|
||||
* Get the sub-TileEntities belonging to this Meta TileEntity.
|
||||
*
|
||||
* @return sub-TileEntity array
|
||||
*/
|
||||
List<TileEntity> getSubTiles();
|
||||
}
|
108
dependencies/ic2/api/item/ElectricItem.java
vendored
108
dependencies/ic2/api/item/ElectricItem.java
vendored
|
@ -1,108 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Allows for charging, discharging and using electric items (IElectricItem).
|
||||
*
|
||||
* The charge or remaining capacity of an item can be determined by calling charge/discharge with
|
||||
* ignoreTransferLimit and simulate set to true.
|
||||
*/
|
||||
public final class ElectricItem {
|
||||
/**
|
||||
* IElectricItemManager to use for interacting with IElectricItem ItemStacks.
|
||||
*
|
||||
* This manager will act as a gateway and delegate the tasks to the final implementation
|
||||
* (rawManager or a custom one) as necessary.
|
||||
*/
|
||||
public static IElectricItemManager manager;
|
||||
|
||||
/**
|
||||
* Standard IElectricItemManager implementation, only call it directly from another
|
||||
* IElectricItemManager. Use manager instead.
|
||||
*/
|
||||
public static IElectricItemManager rawManager;
|
||||
|
||||
/**
|
||||
* Charge an item with a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the charging device, has to be at least as high as the item to charge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually change the item, just determine the return value
|
||||
* @return Energy transferred into the electric item
|
||||
*
|
||||
* @deprecated use manager.charge() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
return manager.charge(itemStack, amount, tier, ignoreTransferLimit, simulate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharge an item by a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually discharge the item, just determine the return value
|
||||
* @return Energy retrieved from the electric item
|
||||
*
|
||||
* @deprecated use manager.discharge() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
return manager.discharge(itemStack, amount, tier, ignoreTransferLimit, simulate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the specified electric item has at least a specific amount of EU.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* BatPacks are not taken into account.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount minimum amount of energy required
|
||||
* @return true if there's enough energy
|
||||
*
|
||||
* @deprecated use manager.canUse() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean canUse(ItemStack itemStack, int amount) {
|
||||
return manager.canUse(itemStack, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to discharge in EU
|
||||
* @param player player holding the item
|
||||
* @return true if the operation succeeded
|
||||
*
|
||||
* @deprecated use manager.use() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean use(ItemStack itemStack, int amount, EntityPlayer player) {
|
||||
return manager.use(itemStack, amount, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge an item from the BatPack a player is wearing.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* use() already contains this functionality.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param player player holding the item
|
||||
*
|
||||
* @deprecated use manager.chargeFromArmor() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static void chargeFromArmor(ItemStack itemStack, EntityPlayer player) {
|
||||
manager.chargeFromArmor(itemStack, player);
|
||||
}
|
||||
}
|
||||
|
14
dependencies/ic2/api/item/IBoxable.java
vendored
14
dependencies/ic2/api/item/IBoxable.java
vendored
|
@ -1,14 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IBoxable {
|
||||
/**
|
||||
* Determine whether an item can be stored in a toolbox or not.
|
||||
*
|
||||
* @param itemstack item to be stored
|
||||
* @return Whether to store the item in the toolbox or not
|
||||
*/
|
||||
public abstract boolean canBeStoredInToolbox(ItemStack itemstack);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides the ability to store energy on the implementing item.
|
||||
*
|
||||
* This interface is a special version of IElectricItem which delegates the implementation of
|
||||
* charge(), discharge() and canUse() to the implementing Item.
|
||||
*
|
||||
* The default implementation (when not using ICustomElectricItem) does the following:
|
||||
* - store and retrieve the charge
|
||||
* - handle charging, taking amount, tier, transfer limit, canProvideEnergy and simulate into account
|
||||
* - replace item IDs if appropriate (getChargedItemId() and getEmptyItemId())
|
||||
* - update and manage the damage value for the visual charge indicator
|
||||
*
|
||||
* @note ICustomElectricItem must not call the ElectricItem methods charge, discharge or canUse
|
||||
*
|
||||
* @deprecated Use ISpecialElectricItem instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ICustomElectricItem extends IElectricItem {
|
||||
/**
|
||||
* Charge an item with a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the charging device, has to be at least as high as the item to charge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually change the item, just determine the return value
|
||||
* @return Energy transferred into the electric item
|
||||
*/
|
||||
public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate);
|
||||
|
||||
/**
|
||||
* Discharge an item by a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually discharge the item, just determine the return value
|
||||
* @return Energy retrieved from the electric item
|
||||
*/
|
||||
public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate);
|
||||
|
||||
/**
|
||||
* Determine if the specified electric item has at least a specific amount of EU.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* BatPacks are not taken into account.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount minimum amount of energy required
|
||||
* @return true if there's enough energy
|
||||
*/
|
||||
public boolean canUse(ItemStack itemStack, int amount);
|
||||
|
||||
/**
|
||||
* Determine whether to show the charge tool tip with NEI or other means.
|
||||
*
|
||||
* Return false if IC2's handler is incompatible, you want to implement your own or you don't
|
||||
* want to display the charge at all.
|
||||
*
|
||||
* @return true to show the tool tip (x/y EU)
|
||||
*/
|
||||
public boolean canShowChargeToolTip(ItemStack itemStack);
|
||||
}
|
23
dependencies/ic2/api/item/IDebuggable.java
vendored
23
dependencies/ic2/api/item/IDebuggable.java
vendored
|
@ -1,23 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Allows a tile entity to output a debug message when the debugItem is used on it.
|
||||
* Suggestions by Myrathi
|
||||
*/
|
||||
public abstract interface IDebuggable {
|
||||
/**
|
||||
* Checks if the tile entity is in a state that can be debugged.
|
||||
*
|
||||
* @return True if the tile entity can be debugged
|
||||
*/
|
||||
public abstract boolean isDebuggable();
|
||||
|
||||
/**
|
||||
* Gets the debug text for the tile entity.
|
||||
*
|
||||
* @return The text that the debugItem should show
|
||||
*/
|
||||
public abstract String getDebugText();
|
||||
}
|
54
dependencies/ic2/api/item/IElectricItem.java
vendored
54
dependencies/ic2/api/item/IElectricItem.java
vendored
|
@ -1,54 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides the ability to store energy on the implementing item.
|
||||
*
|
||||
* The item should have a maximum damage of 13.
|
||||
*/
|
||||
public interface IElectricItem {
|
||||
/**
|
||||
* Determine if the item can be used in a machine or as an armor part to supply energy.
|
||||
*
|
||||
* @return Whether the item can supply energy
|
||||
*/
|
||||
boolean canProvideEnergy(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item ID to use for a charge energy greater than 0.
|
||||
*
|
||||
* @return Item ID to use
|
||||
*/
|
||||
int getChargedItemId(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item ID to use for a charge energy of 0.
|
||||
*
|
||||
* @return Item ID to use
|
||||
*/
|
||||
int getEmptyItemId(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item's maximum charge energy in EU.
|
||||
*
|
||||
* @return Maximum charge energy
|
||||
*/
|
||||
int getMaxCharge(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item's tier, lower tiers can't send energy to higher ones.
|
||||
* Batteries are Tier 1, Energy Crystals are Tier 2, Lapotron Crystals are Tier 3.
|
||||
*
|
||||
* @return Item's tier
|
||||
*/
|
||||
int getTier(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item's transfer limit in EU per transfer operation.
|
||||
*
|
||||
* @return Transfer limit
|
||||
*/
|
||||
int getTransferLimit(ItemStack itemStack);
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This interface specifies a manager to handle the various tasks for electric items.
|
||||
*
|
||||
* The default implementation does the following:
|
||||
* - store and retrieve the charge
|
||||
* - handle charging, taking amount, tier, transfer limit, canProvideEnergy and simulate into account
|
||||
* - replace item IDs if appropriate (getChargedItemId() and getEmptyItemId())
|
||||
* - update and manage the damage value for the visual charge indicator
|
||||
*
|
||||
* @note If you're implementing your own variant (ISpecialElectricItem), you can delegate to the
|
||||
* default implementations through ElectricItem.rawManager. The default implementation is designed
|
||||
* to minimize its dependency on its own constraints/structure and delegates most work back to the
|
||||
* more atomic features in the gateway manager.
|
||||
*/
|
||||
public interface IElectricItemManager {
|
||||
/**
|
||||
* Charge an item with a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the charging device, has to be at least as high as the item to charge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually change the item, just determine the return value
|
||||
* @return Energy transferred into the electric item
|
||||
*/
|
||||
int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate);
|
||||
|
||||
/**
|
||||
* Discharge an item by a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually discharge the item, just determine the return value
|
||||
* @return Energy retrieved from the electric item
|
||||
*/
|
||||
int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate);
|
||||
|
||||
/**
|
||||
* Determine the charge level for the specified item
|
||||
*
|
||||
* @param itemStack ItemStack containing the electric item
|
||||
* @return charge level in EU
|
||||
*/
|
||||
int getCharge(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Determine if the specified electric item has at least a specific amount of EU.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* BatPacks are not taken into account.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount minimum amount of energy required
|
||||
* @return true if there's enough energy
|
||||
*/
|
||||
boolean canUse(ItemStack itemStack, int amount);
|
||||
|
||||
/**
|
||||
* Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to discharge in EU
|
||||
* @param entity entity holding the item
|
||||
* @return true if the operation succeeded
|
||||
*/
|
||||
boolean use(ItemStack itemStack, int amount, EntityLivingBase entity);
|
||||
|
||||
/**
|
||||
* Charge an item from the BatPack a player is wearing.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* use() already contains this functionality.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param entity entity holding the item
|
||||
*/
|
||||
void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity);
|
||||
|
||||
/**
|
||||
* Get the tool tip to display for electric items.
|
||||
*
|
||||
* @param itemStack ItemStack to determine the tooltip for
|
||||
* @return tool tip string or null for none
|
||||
*/
|
||||
String getToolTip(ItemStack itemStack);
|
||||
}
|
27
dependencies/ic2/api/item/IItemHudInfo.java
vendored
27
dependencies/ic2/api/item/IItemHudInfo.java
vendored
|
@ -1,27 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemHudInfo {
|
||||
|
||||
/*
|
||||
Add Info to Nano- and Quantum-Suit Helm Hud
|
||||
for itemStack
|
||||
|
||||
@Override
|
||||
public List<String> getHudInfo(ItemStack itemStack) {
|
||||
List<String> info = new LinkedList<String>();
|
||||
info.add("i am a Cool Item");
|
||||
info.add("and have Cool info");
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
public List<String> getHudInfo(ItemStack itemStack);
|
||||
|
||||
}
|
20
dependencies/ic2/api/item/IMetalArmor.java
vendored
20
dependencies/ic2/api/item/IMetalArmor.java
vendored
|
@ -1,20 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Armor items implementing this can be considered metal armor.
|
||||
*
|
||||
* Currently used for determining which boots can be used to slide up a magnetic pole.
|
||||
*/
|
||||
public interface IMetalArmor {
|
||||
/**
|
||||
* Determine if the given armor piece is metal armor.
|
||||
*
|
||||
* @param itemstack Armor piece as worn by the player
|
||||
* @param player The player
|
||||
* @return Whether the armor piece is metal armor
|
||||
*/
|
||||
public boolean isMetalArmor(ItemStack itemstack, EntityPlayer player);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface ISpecialElectricItem extends IElectricItem {
|
||||
/**
|
||||
* Supply a custom IElectricItemManager.
|
||||
*
|
||||
* @param itemStack ItemStack to get the manager for
|
||||
* @return IElectricItemManager instance
|
||||
*/
|
||||
IElectricItemManager getManager(ItemStack itemStack);
|
||||
}
|
35
dependencies/ic2/api/item/ITerraformingBP.java
vendored
35
dependencies/ic2/api/item/ITerraformingBP.java
vendored
|
@ -1,35 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Allows an item to act as a terraformer blueprint.
|
||||
*/
|
||||
public interface ITerraformingBP
|
||||
{
|
||||
/**
|
||||
* Get the energy consumption per operation of the blueprint.
|
||||
*
|
||||
* @return Energy consumption in EU
|
||||
*/
|
||||
public abstract int getConsume();
|
||||
|
||||
/**
|
||||
* Get the maximum range of the blueprint.
|
||||
* Should be a divisor of 5.
|
||||
*
|
||||
* @return Maximum range in blocks
|
||||
*/
|
||||
public abstract int getRange();
|
||||
|
||||
/**
|
||||
* Perform the terraforming operation.
|
||||
*
|
||||
* @param world world to terraform
|
||||
* @param x X position to terraform
|
||||
* @param z Z position to terraform
|
||||
* @param yCoord Y position of the terraformer
|
||||
* @return Whether the operation was successful and the terraformer should consume energy.
|
||||
*/
|
||||
public abstract boolean terraform(World world, int x, int z, int yCoord);
|
||||
}
|
50
dependencies/ic2/api/item/ItemWrapper.java
vendored
50
dependencies/ic2/api/item/ItemWrapper.java
vendored
|
@ -1,50 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* Wrapper for inserting interfaces into items you don't own.
|
||||
*
|
||||
* @author Richard
|
||||
*/
|
||||
public class ItemWrapper {
|
||||
private static final Multimap<Item, IBoxable> boxableItems = ArrayListMultimap.create();
|
||||
private static final Multimap<Item, IMetalArmor> metalArmorItems = ArrayListMultimap.create();
|
||||
|
||||
public static void registerBoxable(Item item, IBoxable boxable) {
|
||||
boxableItems.put(item, boxable);
|
||||
}
|
||||
|
||||
public static boolean canBeStoredInToolbox(ItemStack stack) {
|
||||
Item item = stack.getItem();
|
||||
// use customs first to allow for overriding behavior
|
||||
for (IBoxable boxable : boxableItems.get(item)) {
|
||||
if (boxable.canBeStoredInToolbox(stack)) return true;
|
||||
}
|
||||
|
||||
if (item instanceof IBoxable && ((IBoxable) item).canBeStoredInToolbox(stack)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void registerMetalArmor(Item item, IMetalArmor armor) {
|
||||
metalArmorItems.put(item, armor);
|
||||
}
|
||||
|
||||
public static boolean isMetalArmor(ItemStack stack, EntityPlayer player) {
|
||||
Item item = stack.getItem();
|
||||
// use customs first to allow for overriding behavior
|
||||
for (IMetalArmor metalArmor : metalArmorItems.get(item)) {
|
||||
if (metalArmor.isMetalArmor(stack, player)) return true;
|
||||
}
|
||||
|
||||
if (item instanceof IMetalArmor && ((IMetalArmor) item).isMetalArmor(stack, player)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
407
dependencies/ic2/api/item/Items.java
vendored
407
dependencies/ic2/api/item/Items.java
vendored
|
@ -1,407 +0,0 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides access to IC2 blocks and items.
|
||||
*
|
||||
* Some items can be acquired through the ore dictionary which is the recommended way.
|
||||
* The items are initialized while IC2 is being loaded - try to use ModsLoaded() or load your mod after IC2.
|
||||
* Some blocks/items can be disabled by a config setting, so it's recommended to check if they're null first.
|
||||
*
|
||||
* Getting the associated Block/Item for an ItemStack x:
|
||||
* Blocks: Block.blocksList[x.itemID]
|
||||
* Items: x.getItem()
|
||||
*/
|
||||
public final class Items {
|
||||
/**
|
||||
* Get an ItemStack for a specific item name, example: Items.getItem("resin")
|
||||
* See the list below for item names.
|
||||
* Make sure to copy() the ItemStack if you want to modify it.
|
||||
*
|
||||
* @param name item name
|
||||
* @return The item or null if the item does not exist or an error occurred
|
||||
*/
|
||||
public static ItemStack getItem(String name) {
|
||||
try {
|
||||
if (Ic2Items == null) Ic2Items = Class.forName(getPackage() + ".core.Ic2Items");
|
||||
|
||||
Object ret = Ic2Items.getField(name).get(null);
|
||||
|
||||
if (ret instanceof ItemStack) {
|
||||
return (ItemStack) ret;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("IC2 API: Call getItem failed for "+name);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* Possible values:
|
||||
|
||||
----- blocks -----
|
||||
|
||||
ores
|
||||
copperOre Copper Ore block, currently not meta sensitive, meta in ItemStack set to 0, ore dictionary: oreCopper, null with enableWorldGenOreCopper=false
|
||||
tinOre Tin Ore block, currently not meta sensitive, meta in ItemStack set to 0, ore dictionary: oreTin, null with enableWorldGenOreTin=false
|
||||
uraniumOre Tin Ore block, currently not meta sensitive, meta in ItemStack set to 0, ore dictionary: oreUranium, null with enableWorldGenOreUranium=false
|
||||
|
||||
rubber related
|
||||
Rubber wood block, meta reflects the state, meta in ItemStack set to 0, ore dictionary: woodRubber (with meta 0), null with enableWorldGenTreeRubber=false
|
||||
dropped (as an item) -> metadata 0
|
||||
block, no resin spot -> metadata 0 or 1
|
||||
block, wet resin spot -> metadata 2-5 (according to the side)
|
||||
block, dry resin spot -> metadata 8-11 (wet state + 6)
|
||||
|
||||
rubberWood
|
||||
rubberLeaves Rubber Leaves block, currently not meta sensitive, meta in ItemStack set to 0, null with enableWorldGenTreeRubber=false
|
||||
rubberSapling Rubber Sapling block, currently not meta sensitive, meta in ItemStack set to 0, null with enableWorldGenTreeRubber=false
|
||||
resinSheet Resin Sheet block, currently not meta sensitive
|
||||
rubberTrampoline Rubber Trampoline block, meta reflects internal state, meta in ItemStack set to 0
|
||||
|
||||
building/storage
|
||||
ironFence Iron Fence block, currently not meta sensitive
|
||||
|
||||
reinforcedStone Reinforced Stone block, currently not meta sensitive
|
||||
reinforcedGlass Reinforced Glass block, currently not meta sensitive
|
||||
reinforcedDoorBlock Reinforced Door block, meta reflects the state (see vanilla doors), meta in ItemStack set to 0
|
||||
|
||||
constructionFoam Construction Foam block, currently not meta sensitive
|
||||
constructionFoamWall Construction Foam Wall block, meta = color, implements IPaintableBlock
|
||||
scaffold Scaffold block, meta reflects internal physical model data
|
||||
|
||||
bronzeBlock Bronze block, meta sensitive
|
||||
copperBlock Copper block, meta sensitive
|
||||
tinBlock Tin block, meta sensitive
|
||||
uraniumBlock Uranium block, meta sensitive
|
||||
|
||||
cables (when placed as a block, inventory items are different TE implements IEnergyConductor)
|
||||
copperCableBlock Copper Cable block, meta sensitive
|
||||
insulatedCopperCableBlock Insulated Copper Cable block, meta sensitive
|
||||
|
||||
goldCableBlock Gold Cable block, meta sensitive
|
||||
insulatedGoldCableBlock Insulated Gold Cable block, meta sensitive
|
||||
doubleInsulatedGoldCableBlock Double Insulated Gold Cable block, meta sensitive
|
||||
|
||||
ironCableBlock Iron Cable block, meta sensitive
|
||||
insulatedIronCableBlock Insulated Iron Cable block, meta sensitive
|
||||
doubleInsulatedIronCableBlock Double Insulated Iron Cable block, meta sensitive
|
||||
trippleInsulatedIronCableBlock Tripple Insulated Iron Cable block, meta sensitive
|
||||
|
||||
glassFiberCableBlock Glass Fiber Cable block, meta sensitive
|
||||
|
||||
tinCableBlock Tin Cable block, meta sensitive
|
||||
|
||||
detectorCableBlock Detector Cable block, meta sensitive
|
||||
splitterCableBlock Splitter Cable block, meta sensitive
|
||||
|
||||
generators + related (TE implements IEnergySource ex. reactorChamber)
|
||||
generator Generator block, meta sensitive
|
||||
geothermalGenerator Geothermal Generator block, meta sensitive
|
||||
waterMill Water Mill block, meta sensitive
|
||||
solarPanel Solar Panel block, meta sensitive
|
||||
windMill Wind Mill block, meta sensitive
|
||||
nuclearReactor Nuclear Reactor block, meta sensitive
|
||||
reactorChamber Reactor Chamber block, currently not meta sensitive
|
||||
|
||||
energy storages (TE implements IEnergySource and IEnergyConductor)
|
||||
batBox BatBox block, meta sensitive
|
||||
mfeUnit MFE Unit block, meta sensitive
|
||||
mfsUnit MFS Unit block, meta sensitive
|
||||
|
||||
transformers (TE implements IEnergySource and IEnergyConductor)
|
||||
lvTransformer LV Transformer block, meta sensitive
|
||||
mvTransformer MV Transformer block, meta sensitive
|
||||
hvTransformer HV Transformer block, meta sensitive
|
||||
|
||||
machines + related (TE implements IEnergySink ex. machine, miningPipe, miningPipeTip)
|
||||
machine Machine block, meta sensitive
|
||||
advancedMachine Advanced Machine block, meta sensitive
|
||||
|
||||
ironFurnace Iron Furnace block, meta sensitive
|
||||
electroFurnace Electro Furnace block, meta sensitive
|
||||
macerator Macerator block, meta sensitive
|
||||
extractor Extractor block, meta sensitive
|
||||
compressor Compressor block, meta sensitive
|
||||
canner Canner block, meta sensitive
|
||||
miner Miner block, meta sensitive
|
||||
pump Pump block, meta sensitive
|
||||
magnetizer Magnetizer block, meta sensitive
|
||||
electrolyzer Electrolyzer block, meta sensitive
|
||||
recycler Recycler block, meta sensitive
|
||||
inductionFurnace Induction Furnace block, meta sensitive
|
||||
massFabricator Mass Fabricator block, meta sensitive
|
||||
terraformer Terraformer block, meta sensitive
|
||||
teleporter Teleporter block, meta sensitive
|
||||
teslaCoil Tesla Coil block, meta sensitive
|
||||
luminator Passive (dark) Luminator block, meta = facing
|
||||
activeLuminator Active (bright) Luminator block, meta = facing
|
||||
|
||||
miningPipe Mining Pipe block, currently not meta sensitive, meta in ItemStack set to 0
|
||||
miningPipeTip Mining Pipe Tip block, currently not meta sensitive, meta in ItemStack set to 0
|
||||
|
||||
personal blocks
|
||||
personalSafe Personal Safe block, meta sensitive
|
||||
tradeOMat Trade-O-Mat block, meta sensitive
|
||||
energyOMat Energy-O-Mat block, meta sensitive
|
||||
|
||||
explosives
|
||||
industrialTnt Industrial TNT block, currently not meta sensitive
|
||||
nuke Nuke block, currently not meta sensitive
|
||||
dynamiteStick Dynamite Stick block, meta = placement, meta in ItemStack set to 0
|
||||
dynamiteStickWithRemote Dynamite Stick with Remote block, meta = placement, meta in ItemStack set to 0
|
||||
|
||||
Agriculture Stuff
|
||||
crop Crop Block, empty, not meta sensitive
|
||||
|
||||
|
||||
----- items -----
|
||||
|
||||
rubber + related
|
||||
resin Resin item, currently not meta sensitive
|
||||
rubber Rubber item, currently not meta sensitive, ore dictionary: itemRubber
|
||||
|
||||
ore drops
|
||||
uraniumDrop Uranium Drop item, currently not meta sensitive, ore dictionary: itemDropUranium
|
||||
|
||||
dusts
|
||||
bronzeDust Bronze Dust item, currently not meta sensitive
|
||||
clayDust Clay Dust item, currently not meta sensitive
|
||||
coalDust Coal Dust item, currently not meta sensitive
|
||||
copperDust Copper Dust item, currently not meta sensitive
|
||||
goldDust Gold Dust item, currently not meta sensitive
|
||||
ironDust Iron Dust item, currently not meta sensitive
|
||||
silverDust Silver Dust item, currently not meta sensitive
|
||||
smallIronDust Small Iron Dust item, currently not meta sensitive
|
||||
tinDust Tin Dust item, currently not meta sensitive
|
||||
hydratedCoalDust Hydrated Coal Dust item, currently not meta sensitive
|
||||
|
||||
ingots
|
||||
refinedIronIngot Refined Iron Ingot item, currently not meta sensitive, ore dictionary: ingotRefinedIron
|
||||
copperIngot Copper Ingot item, currently not meta sensitive, ore dictionary: ingotCopper
|
||||
tinIngot Tin Ingot item, currently not meta sensitive, ore dictionary: ingotTin
|
||||
bronzeIngot Bronze Ingot item, currently not meta sensitive, ore dictionary: ingotBronze
|
||||
mixedMetalIngot Mixed Metal Ingot item, currently not meta sensitive
|
||||
uraniumIngot Uranium Ingot item, currently not meta sensitive, ore dictionary: ingotUranium
|
||||
|
||||
tools/weapons (without electric tools)
|
||||
treetap Treetap item, meta = damage value
|
||||
wrench Wrench item, meta = damage value
|
||||
cutter Insulation Cutter item, meta = damage value
|
||||
constructionFoamSprayer Construction Foam Sprayer item, meta = charges (as of v1.45)
|
||||
|
||||
bronzePickaxe Bronze Pickaxe item, meta = damage value
|
||||
bronzeAxe Bronze Axe item, meta = damage value
|
||||
bronzeSword Bronze Sword item, meta = damage value
|
||||
bronzeShovel Bronze Shovel item, meta = damage value
|
||||
bronzeHoe Bronze Hoe item, meta = damage value
|
||||
|
||||
el. tools/devices/weapons
|
||||
miningDrill Mining Drill item, meta = visual charge indicator, implements IElectricItem
|
||||
diamondDrill Diamond Tipped Mining Drill item, meta = visual charge indicator, implements IElectricItem
|
||||
chainsaw Chainsaw item, meta = visual charge indicator, implements IElectricItem
|
||||
electricWrench Electric Wrench item, meta = visual charge indicator, implements IElectricItem
|
||||
electricTreetap Electric Treetap item, meta = visual charge indicator, implements IElectricItem
|
||||
miningLaser Mining Laser item, meta = visual charge indicator, implements IElectricItem
|
||||
|
||||
ecMeter EC-Mater item, currently not meta sensitive
|
||||
odScanner Ore Density Scanner item, meta = damage value for charge level, implements IElectricItem
|
||||
ovScanner Ore Value Scanner item, meta = visual charge indicator, implements IElectricItem
|
||||
|
||||
frequencyTransmitter Frequency Transmitter item, currently not meta sensitive
|
||||
|
||||
nanoSaber Idle Nano Saber item, meta = visual charge indicator, implements IElectricItem
|
||||
enabledNanoSaber Enabled Nano Saber item, meta = visual charge indicator, implements IElectricItem
|
||||
|
||||
armor/wearable
|
||||
rubberBoots Rubber Boots item, meta = damage value
|
||||
|
||||
bronzeHelmet Bronze Helmet Armor item, meta = damage value
|
||||
bronzeChestplate Bronze Chestplate Armor item, meta = damage value
|
||||
bronzeLeggings Bronze Leggings Armor item, meta = damage value
|
||||
bronzeBoots Bronze Boots Armor item, meta = damage value
|
||||
|
||||
compositeArmor Composite Armor item, meta = damage value for charge level
|
||||
|
||||
nanoHelmet Nano Helmet Armor item, meta = visual charge indicator, implements IElectricItem
|
||||
nanoBodyarmor Nano Bodyarmor item, meta = visual charge indicator, implements IElectricItem
|
||||
nanoLeggings Nano Leggings Armor item, meta = visual charge indicator, implements IElectricItem
|
||||
nanoBoots Nano Boots Armor item, meta = visual charge indicator, implements IElectricItem
|
||||
|
||||
quantumHelmet Quantum Helmet Armor item, meta = visual charge indicator, implements IElectricItem
|
||||
quantumBodyarmor Quantum Bodyarmor item, meta = visual charge indicator, implements IElectricItem
|
||||
quantumLeggings Quantum Leggings Armor item, meta = visual charge indicator, implements IElectricItem
|
||||
quantumBoots Quantum Boots Armor item, meta = visual charge indicator, implements IElectricItem
|
||||
|
||||
jetpack Jetpack item, meta = damage value for fuel level
|
||||
electricJetpack Electric Jetpack item, meta = visual charge indicator, implements IElectricItem
|
||||
|
||||
batPack BatPack item, meta = visual charge indicator, implements IElectricItem, can provide energy
|
||||
lapPack LapPack item, meta = visual charge indicator, implements IElectricItem, can provide energy
|
||||
|
||||
cfPack CF Pack item, meta = charges (as of v1.45)
|
||||
|
||||
solarHelmet Solar Helmet item, currently not meta sensitive
|
||||
staticBoots Static Boots item, currently not meta sensitive
|
||||
|
||||
batteries
|
||||
reBattery Empty RE Battery item, currently not meta sensitive, implements IElectricItem
|
||||
chargedReBattery RE Battery item, meta = visual charge indicator, implements IElectricItem, can provide energy
|
||||
energyCrystal Energy Crystal item, meta = visual charge indicator, implements IElectricItem, can provide energy
|
||||
lapotronCrystal Lapotron Crystal item, meta = visual charge indicator, implements IElectricItem, can provide energy
|
||||
suBattery SU Battery item, currently not meta sensitive
|
||||
|
||||
cables
|
||||
copperCableItem Copper Cable item, meta sensitive
|
||||
insulatedCopperCableItem Insulated Copper Cable item, meta sensitive
|
||||
|
||||
goldCableItem Gold Cable item, meta sensitive
|
||||
insulatedGoldCableItem Insulated Gold Cable item, meta sensitive
|
||||
doubleInsulatedGoldCableItem Double Insulated Gold Cable item, meta sensitive
|
||||
|
||||
ironCableItem Iron Cable item, meta sensitive
|
||||
insulatedIronCableItem Insulated Iron Cable item, meta sensitive
|
||||
doubleInsulatedIronCableItem Double Insulated Iron Cable item, meta sensitive
|
||||
trippleInsulatedIronCableItem Tripple Insulated Iron Cable item, meta sensitive
|
||||
|
||||
glassFiberCableItem Glass Fiber Cable item, meta sensitive
|
||||
|
||||
tinCableItem Tin Cable item, meta sensitive
|
||||
|
||||
detectorCableItem Detector Cable item, meta sensitive
|
||||
splitterCableItem Splitter Cable item, meta sensitive
|
||||
|
||||
cells/containers (without reactor components)
|
||||
cell Empty Cell item, currently not meta sensitive
|
||||
lavaCell Lava Cell item, currently not meta sensitive
|
||||
hydratedCoalCell Hydrated Coal Cell item, currently not meta sensitive
|
||||
bioCell Bio Cell item, currently not meta sensitive
|
||||
coalfuelCell Coalfuel Cell item, currently not meta sensitive
|
||||
biofuelCell Biofuel Cell item, currently not meta sensitive
|
||||
waterCell Water Cell item, currently not meta sensitive
|
||||
electrolyzedWaterCell Electrolyzed Water Cell item, currently not meta sensitive
|
||||
|
||||
fuelCan Empty Fuel Can item, currently not meta sensitive
|
||||
filledFuelCan Fuel Can item, meta = fuel value (as of v1.45)
|
||||
|
||||
tinCan Empty Tin Can item, currently not meta sensitive
|
||||
filledTinCan Filled Tin Can item, currently not meta sensitive
|
||||
|
||||
reactor components
|
||||
uraniumCell Uranium Cell item, meta = damage value
|
||||
coolingCell Cooling Cell item, meta = damage value
|
||||
|
||||
depletedIsotopeCell Depleted Isotope Cell item, meta = damage value
|
||||
reEnrichedUraniumCell Re-Enriched Uranium Cell item, currently not meta sensitive
|
||||
nearDepletedUraniumCell Near-Depleted Uranium Cell item, currently not meta sensitive
|
||||
|
||||
integratedReactorPlating Integrated Reactor Plating item, meta = damage value
|
||||
integratedHeatDisperser Integrated Heat Disperser item, meta = damage value
|
||||
|
||||
terraformer blueprints
|
||||
terraformerBlueprint Empty Terraformer Blueprint item, currently not meta sensitive
|
||||
cultivationTerraformerBlueprint Cultivation Terraformer Blueprint item, currently not meta sensitive
|
||||
irrigationTerraformerBlueprint Irrigation Terraformer Blueprint item, currently not meta sensitive
|
||||
chillingTerraformerBlueprint Chilling Terraformer Blueprint item, currently not meta sensitive
|
||||
desertificationTerraformerBlueprint Desertification Terraformer Blueprint item, currently not meta sensitive
|
||||
flatificatorTerraformerBlueprint Flatificator Terraformer Blueprint item, currently not meta sensitive
|
||||
mushroomTerraformerBlueprint Mushroom Terraformer Blueprint item, currently not meta sensitive
|
||||
|
||||
diamond chain
|
||||
coalBall Coal Ball item, currently not meta sensitive
|
||||
compressedCoalBall Compressed Coal Ball item, currently not meta sensitive
|
||||
coalChunk Coal Chunk item, currently not meta sensitive
|
||||
industrialDiamond Industrial Diamond item, currently not meta sensitive, DEPRECATED
|
||||
|
||||
recycler chain
|
||||
scrap Scrap item, currently not meta sensitive
|
||||
scrapBox Scrap Box item, currently not meta sensitive
|
||||
|
||||
fuel production chain
|
||||
hydratedCoalClump Hydrated Coal Clump item, currently not meta sensitive
|
||||
plantBall Plant Ball item, currently not meta sensitive
|
||||
compressedPlantBall Compressed Plant Ball item, currently not meta sensitive
|
||||
|
||||
painting
|
||||
painter Painter item, currently not meta sensitive
|
||||
|
||||
blackPainter Black Painter item, meta = damage value
|
||||
redPainter Red Painter item, meta = damage value
|
||||
greenPainter Green Painter item, meta = damage value
|
||||
brownPainter Brown Painter item, meta = damage value
|
||||
bluePainter Blue Painter item, meta = damage value
|
||||
purplePainter Purple Painter item, meta = damage value
|
||||
cyanPainter Cyan Painter item, meta = damage value
|
||||
lightGreyPainter Light Grey Painter item, meta = damage value
|
||||
darkGreyPainter Dark Grey Painter item, meta = damage value
|
||||
pinkPainter Pink Painter item, meta = damage value
|
||||
limePainter Lime Painter item, meta = damage value
|
||||
yellowPainter Yellow Painter item, meta = damage value
|
||||
cloudPainter Cloud Painter item, meta = damage value
|
||||
magentaPainter Magenta Painter item, meta = damage value
|
||||
orangePainter Orange Painter item, meta = damage value
|
||||
whitePainter White Painter item, meta = damage value
|
||||
|
||||
explosives + related
|
||||
dynamite Throwable Dynamite item, currently not meta sensitive
|
||||
stickyDynamite Throwable Sticky Dynamite item, currently not meta sensitive
|
||||
|
||||
remote Dynamite Remote item, currently not meta sensitive
|
||||
|
||||
misc intermediate recipe ingredients
|
||||
electronicCircuit Electronic Circuit item, currently not meta sensitive
|
||||
advancedCircuit Advanced Circuit item, currently not meta sensitive
|
||||
|
||||
advancedAlloy Advanced Alloy item, currently not meta sensitive
|
||||
|
||||
carbonFiber Raw Carbon Fiber item, currently not meta sensitive
|
||||
carbonMesh Raw Carbon Mesh item, currently not meta sensitive
|
||||
carbonPlate Carbon Plate item, currently not meta sensitive
|
||||
|
||||
matter UU-Matter item, currently not meta sensitive
|
||||
iridiumOre Iridium Ore item, currently not meta sensitive
|
||||
iridiumPlate Iridium Plate item, currently not meta sensitive
|
||||
|
||||
upgrade modules
|
||||
overclockerUpgrade overclocker upgrade item, meta sensitive
|
||||
transformerUpgrade transformer upgrade item, meta sensitive
|
||||
energyStorageUpgrade energy storage upgrade item, meta sensitive
|
||||
|
||||
misc
|
||||
coin Coin item, currently not meta sensitive
|
||||
reinforcedDoor Reinforced Door item, currently not meta sensitive
|
||||
constructionFoamPellet Construction Foam Pellet item, currently not meta sensitive
|
||||
cropSeed Crop seeds, stuff stored in NBT, don't use for crafting recipes!
|
||||
cropnalyzer Cropnalyzer handheld device
|
||||
fertilizer Basic IC2Item, used to provide nutrients toCropBlocks
|
||||
hydratingCell Cell used to hydrate Crops, meta = Content, 0 = Full, 9999 = Near empty
|
||||
electricHoe Electric Hoe, meta = charge level
|
||||
solarHelmet Solar Helmet item, currently not meta sensitive
|
||||
terraWart Terra Wart item, cures potion effects
|
||||
weedEx Weed-EX can, meta = uses left
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the base IC2 package name, used internally.
|
||||
*
|
||||
* @return IC2 package name, if unable to be determined defaults to ic2
|
||||
*/
|
||||
private static String getPackage() {
|
||||
Package pkg = Items.class.getPackage();
|
||||
|
||||
if (pkg != null) {
|
||||
String packageName = pkg.getName();
|
||||
|
||||
return packageName.substring(0, packageName.length() - ".api.item".length());
|
||||
}
|
||||
|
||||
return "ic2";
|
||||
}
|
||||
|
||||
private static Class<?> Ic2Items;
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
package universalelectricity.compatibility;
|
||||
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.core.electricity.NetworkLoader;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
/**
|
||||
* The Universal Electricity compatibility module allows your mod to be compatible with most major
|
||||
* power systems in Minecraft.
|
||||
*
|
||||
* @author Calclavia, Micdoodle
|
||||
*/
|
||||
public class Compatibility
|
||||
{
|
||||
/** Version of BuildCraft api compiled with */
|
||||
public static String BCx_VERSION = "@BCxVersion@";
|
||||
/** Version of Industrial Craft api compiled with */
|
||||
public static String ICx_VERSION = "@ICxVersion@";
|
||||
/** Version of Thermal Expansion api compiled with */
|
||||
public static String TEx_VERSION = "@TExVersion@";
|
||||
|
||||
/** Has the initiate method been called */
|
||||
public static boolean INIT = false;
|
||||
|
||||
/** Ratio of Build craft(MJ) power to UE power(Kw). Multiply BC3 power by this to convert to UE */
|
||||
public static float BC3_RATIO = 2.814f;
|
||||
|
||||
/** Ratio of Redstone Flux power to UE power(Kw). Multiply TE power by this to convert to UE */
|
||||
public static float TE_RATIO = BC3_RATIO / 10;
|
||||
|
||||
/**
|
||||
* Ratio of Industrial craft(EU) power to UE power(Kw). Multiply IC2 power by this to convert to
|
||||
* UE
|
||||
*/
|
||||
public static float IC2_RATIO = 0.11256f;
|
||||
|
||||
/**
|
||||
* Ratio of UE power(Kw) to Build craft(MJ) power. Multiply UE power by this to convert it to
|
||||
* BC3 power
|
||||
*/
|
||||
public static float TO_BC_RATIO = 1 / BC3_RATIO;
|
||||
|
||||
/**
|
||||
* Ratio of UE power(Kw) to Redstone Flux power. Multiply UE power by this to convert it to TE
|
||||
* power
|
||||
*/
|
||||
public static float TO_TE_RATIO = 1 / TE_RATIO;
|
||||
|
||||
/**
|
||||
* Ratio of UE power(KW) to Industrial craft(EU) power. Multiply UE power by this to convert it
|
||||
* to IC2 power
|
||||
*/
|
||||
public static float TO_IC2_RATIO = 1 / IC2_RATIO;
|
||||
|
||||
/** You must call this function to enable the Universal Network module. */
|
||||
public static void initiate()
|
||||
{
|
||||
if (!INIT)
|
||||
{
|
||||
/** Outputs basic version information */
|
||||
System.out.println("[UniversalElectricity] Loading compatibility API version " + UniversalElectricity.VERSION);
|
||||
System.out.println("[UniversalElectricity] Compiled with IndustrialCraft API version " + Compatibility.ICx_VERSION);
|
||||
System.out.println("[UniversalElectricity] Compiled with BuildCraft API version " + Compatibility.BCx_VERSION);
|
||||
System.out.println("[UniversalElectricity] Compiled with ThermalExpansion API version " + Compatibility.TEx_VERSION);
|
||||
|
||||
/** Loads the configuration and sets all the values. */
|
||||
UniversalElectricity.CONFIGURATION.load();
|
||||
IC2_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO);
|
||||
TE_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "Thermal Expansion Conversion Ratio", TE_RATIO).getDouble(TE_RATIO);
|
||||
BC3_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO);
|
||||
TO_IC2_RATIO = 1 / IC2_RATIO;
|
||||
TO_BC_RATIO = 1 / BC3_RATIO;
|
||||
UniversalElectricity.CONFIGURATION.save();
|
||||
|
||||
NetworkLoader.setNetworkClass(UniversalNetwork.class);
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks using the FML loader too see if IC2 is loaded */
|
||||
public static boolean isIndustrialCraft2Loaded()
|
||||
{
|
||||
return Loader.isModLoaded("IC2");
|
||||
}
|
||||
|
||||
/** Checks using the FML loader too see if BC3 is loaded */
|
||||
public static boolean isBuildcraftLoaded()
|
||||
{
|
||||
return Loader.isModLoaded("BuildCraft|Energy");
|
||||
}
|
||||
|
||||
public static boolean isThermalExpansionLoaded()
|
||||
{
|
||||
return Loader.isModLoaded("ThermalExpansion");
|
||||
}
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import ic2.api.item.ISpecialElectricItem;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.core.item.ItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
|
||||
public abstract class ItemUniversalElectric extends ItemElectric implements ISpecialElectricItem, IEnergyContainerItem
|
||||
{
|
||||
public static final float CHARGE_RATE = 0.005f;
|
||||
|
||||
public ItemUniversalElectric(int id)
|
||||
{
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* IC2
|
||||
*/
|
||||
@Override
|
||||
public int getChargedItemId(ItemStack itemStack)
|
||||
{
|
||||
return this.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmptyItemId(ItemStack itemStack)
|
||||
{
|
||||
return this.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCharge(ItemStack itemStack)
|
||||
{
|
||||
return (int) (this.getMaxElectricityStored(itemStack) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier(ItemStack itemStack)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransferLimit(ItemStack itemStack)
|
||||
{
|
||||
return (int) ((this.getMaxElectricityStored(itemStack) * CHARGE_RATE) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElectricItemManager getManager(ItemStack itemStack)
|
||||
{
|
||||
return IC2ElectricItemManager.MANAGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(ItemStack itemStack)
|
||||
{
|
||||
return this.recharge(itemStack, 1, false) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thermal Expansion
|
||||
*/
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
|
||||
{
|
||||
return (int) (this.recharge(theItem, energy * Compatibility.BC3_RATIO, doReceive) * Compatibility.TO_BC_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
|
||||
{
|
||||
return (int) (this.discharge(theItem, energy * Compatibility.BC3_RATIO, doTransfer) * Compatibility.TO_BC_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (int) (this.getElectricityStored(theItem) * Compatibility.TO_BC_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (int) (this.getMaxElectricityStored(theItem) * Compatibility.TO_BC_RATIO);
|
||||
}
|
||||
|
||||
public static class IC2ElectricItemManager implements IElectricItemManager
|
||||
{
|
||||
public static final IElectricItemManager MANAGER = new IC2ElectricItemManager();
|
||||
|
||||
private IItemElectric getElectricItem(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
return ((IItemElectric) itemStack.getItem());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate)
|
||||
{
|
||||
float inputElectricity = amount * Compatibility.IC2_RATIO;
|
||||
return (int) (getElectricItem(itemStack).recharge(itemStack, inputElectricity, !simulate) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate)
|
||||
{
|
||||
float outputElectricity = amount * Compatibility.IC2_RATIO;
|
||||
return (int) (getElectricItem(itemStack).discharge(itemStack, outputElectricity, !simulate) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(ItemStack itemStack, int amount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharge(ItemStack itemStack)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean use(ItemStack itemStack, int amount, EntityLivingBase entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTip(ItemStack itemStack)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,267 +0,0 @@
|
|||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import universalelectricity.prefab.tile.TileEntityConductor;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
/**
|
||||
* A universal conductor class.
|
||||
*
|
||||
* Extend this class or use as a reference for your own implementation of compatible conductor
|
||||
* tiles.
|
||||
*
|
||||
* @author Calclavia, micdoodle8
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityUniversalConductor extends TileEntityConductor implements IEnergySink, IPowerReceptor, IEnergyHandler
|
||||
{
|
||||
protected boolean isAddedToEnergyNet;
|
||||
public PowerHandler powerHandler;
|
||||
public float buildcraftBuffer = Compatibility.BC3_RATIO * 50;
|
||||
|
||||
public TileEntityUniversalConductor()
|
||||
{
|
||||
this.powerHandler = new PowerHandler(this, Type.PIPE);
|
||||
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2);
|
||||
this.powerHandler.configurePowerPerdition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity[] getAdjacentConnections()
|
||||
{
|
||||
if (this.adjacentConnections == null)
|
||||
{
|
||||
this.adjacentConnections = new TileEntity[6];
|
||||
|
||||
for (byte i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(i);
|
||||
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), side);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IEnergyTile)
|
||||
{
|
||||
if (tileEntity instanceof IEnergyAcceptor)
|
||||
{
|
||||
if (((IEnergyAcceptor) tileEntity).acceptsEnergyFrom(this, side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (tileEntity instanceof IEnergyEmitter)
|
||||
{
|
||||
if (((IEnergyEmitter) tileEntity).emitsEnergyTo(tileEntity, side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
else if (tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
if (((IPowerReceptor) tileEntity).getPowerReceiver(side.getOpposite()) != null)
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IEnergyHandler)
|
||||
{
|
||||
if (((IEnergyHandler) tileEntity).canInterface(side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.adjacentConnections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate()
|
||||
{
|
||||
super.validate();
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (!this.isAddedToEnergyNet)
|
||||
{
|
||||
this.initIC();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
protected void initIC()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
this.isAddedToEnergyNet = true;
|
||||
}
|
||||
|
||||
protected void unloadTileIC2()
|
||||
{
|
||||
if (this.isAddedToEnergyNet && this.worldObj != null)
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
if (this.getNetwork() == null)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
||||
{
|
||||
TileEntity tile = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), directionFrom);
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 1);
|
||||
return this.getNetwork().produce(pack, this, tile) * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* BuildCraft Functions
|
||||
*/
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
return this.powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
Set<TileEntity> ignoreTiles = new HashSet<TileEntity>();
|
||||
ignoreTiles.add(this);
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
|
||||
ignoreTiles.add(tile);
|
||||
}
|
||||
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 1);
|
||||
this.getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return this.getWorldObj();
|
||||
}
|
||||
|
||||
/**
|
||||
* Thermal Expansion Functions
|
||||
*/
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts(maxReceive * Compatibility.TE_RATIO, 1);
|
||||
float request = this.getMaxEnergyStored(from);
|
||||
|
||||
if (!simulate)
|
||||
{
|
||||
if (request > 0)
|
||||
{
|
||||
float reject = this.getNetwork().produce(pack, new Vector3(this).modifyPositionFromSide(from).getTileEntity(this.worldObj));
|
||||
return (int) (maxReceive - (reject * Compatibility.TO_TE_RATIO));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.min(maxReceive, request * Compatibility.TO_TE_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInterface(ForgeDirection from)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return (int) (this.getNetwork().getRequest(new Vector3(this).modifyPositionFromSide(from).getTileEntity(this.worldObj)).getWatts() * Compatibility.TO_TE_RATIO);
|
||||
}
|
||||
}
|
|
@ -1,385 +0,0 @@
|
|||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import ic2.api.item.ISpecialElectricItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
/**
|
||||
* A universal electricity tile used for tiles that consume or produce electricity.
|
||||
*
|
||||
* Extend this class or use as a reference for your own implementation of compatible electrical
|
||||
* tiles.
|
||||
*
|
||||
* @author micdoodle8, Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityUniversalElectrical extends TileEntityElectrical implements IEnergySink, IEnergySource, IPowerReceptor, IEnergyHandler
|
||||
{
|
||||
protected boolean isAddedToEnergyNet;
|
||||
public PowerHandler bcPowerHandler;
|
||||
public Type bcBlockType = Type.MACHINE;
|
||||
public float maxInputEnergy = 100;
|
||||
|
||||
/**
|
||||
* Recharges electric item.
|
||||
*/
|
||||
@Override
|
||||
public void recharge(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
super.recharge(itemStack);
|
||||
}
|
||||
else if (itemStack.getItem() instanceof ISpecialElectricItem)
|
||||
{
|
||||
ISpecialElectricItem electricItem = (ISpecialElectricItem) itemStack.getItem();
|
||||
IElectricItemManager manager = electricItem.getManager(itemStack);
|
||||
float energy = Math.max(this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.IC2_RATIO, 0);
|
||||
energy = manager.charge(itemStack, (int) (energy * Compatibility.TO_IC2_RATIO), 0, false, false) * Compatibility.IC2_RATIO;
|
||||
this.provideElectricity(energy, true);
|
||||
}
|
||||
else if (itemStack.getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
float forgienEnergyAccepted = ((IEnergyContainerItem) itemStack.getItem()).receiveEnergy(itemStack, (int) (this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.TO_TE_RATIO), false);
|
||||
this.provideElectricity(forgienEnergyAccepted * Compatibility.TE_RATIO, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharges electric item.
|
||||
*/
|
||||
@Override
|
||||
public void discharge(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
super.discharge(itemStack);
|
||||
}
|
||||
else if (itemStack.getItem() instanceof ISpecialElectricItem)
|
||||
{
|
||||
ISpecialElectricItem electricItem = (ISpecialElectricItem) itemStack.getItem();
|
||||
|
||||
if (electricItem.canProvideEnergy(itemStack))
|
||||
{
|
||||
IElectricItemManager manager = electricItem.getManager(itemStack);
|
||||
float energy = Math.max(this.getRequest(ForgeDirection.UNKNOWN) * Compatibility.IC2_RATIO, 0);
|
||||
energy = manager.discharge(itemStack, (int) (energy * Compatibility.TO_IC2_RATIO), 0, false, false);
|
||||
this.receiveElectricity(energy, true);
|
||||
}
|
||||
}
|
||||
else if (itemStack.getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
float forgienEnergy = ((IEnergyContainerItem) itemStack.getItem()).extractEnergy(itemStack, (int) (this.getRequest(ForgeDirection.UNKNOWN) * Compatibility.TO_TE_RATIO), false);
|
||||
this.receiveElectricity(forgienEnergy * Compatibility.TE_RATIO, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
super.initiate();
|
||||
this.initBuildCraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
// Register to the IC2 Network
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (!this.isAddedToEnergyNet)
|
||||
{
|
||||
this.initIC();
|
||||
}
|
||||
|
||||
if (this.bcPowerHandler == null)
|
||||
{
|
||||
this.initBuildCraft();
|
||||
}
|
||||
|
||||
if (Compatibility.isBuildcraftLoaded())
|
||||
{
|
||||
if (this.bcPowerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
/**
|
||||
* Cheat BuildCraft powerHandler and always empty energy inside of it.
|
||||
*/
|
||||
this.receiveElectricity(this.bcPowerHandler.getEnergyStored() * Compatibility.BC3_RATIO, true);
|
||||
this.bcPowerHandler.setEnergy(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void produce()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (ForgeDirection outputDirection : this.getOutputDirections())
|
||||
{
|
||||
if (outputDirection != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
if (!this.produceUE(outputDirection))
|
||||
{
|
||||
if (!this.produceThermalExpansion(outputDirection))
|
||||
{
|
||||
this.produceBuildCraft(outputDirection);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean produceThermalExpansion(ForgeDirection outputDirection)
|
||||
{
|
||||
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
float provide = this.getProvide(outputDirection);
|
||||
|
||||
if (this.getEnergyStored() >= provide && provide > 0)
|
||||
{
|
||||
if (Compatibility.isThermalExpansionLoaded())
|
||||
{
|
||||
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(outputDirection).getTileEntity(this.worldObj);
|
||||
|
||||
if (tileEntity instanceof IEnergyHandler)
|
||||
{
|
||||
IEnergyHandler receiver = (IEnergyHandler) tileEntity;
|
||||
int convertedProvide = (int) (provide * Compatibility.TO_TE_RATIO);
|
||||
|
||||
if (receiver.canInterface(outputDirection.getOpposite()) && receiver.receiveEnergy(outputDirection.getOpposite(), convertedProvide, true) > 0)
|
||||
{
|
||||
int forgienEnergyUsed = receiver.receiveEnergy(outputDirection.getOpposite(), convertedProvide, false);
|
||||
this.provideElectricity(forgienEnergyUsed * Compatibility.TE_RATIO, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean produceBuildCraft(ForgeDirection outputDirection)
|
||||
{
|
||||
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
float provide = this.getProvide(outputDirection);
|
||||
|
||||
if (this.getEnergyStored() >= provide && provide > 0)
|
||||
{
|
||||
if (Compatibility.isBuildcraftLoaded())
|
||||
{
|
||||
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(outputDirection).getTileEntity(this.worldObj);
|
||||
|
||||
if (tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
PowerReceiver receiver = ((IPowerReceptor) tileEntity).getPowerReceiver(outputDirection.getOpposite());
|
||||
|
||||
if (receiver != null)
|
||||
{
|
||||
if (receiver.powerRequest() > 0)
|
||||
{
|
||||
float convertedProvide = provide * Compatibility.TO_BC_RATIO;
|
||||
float forgienEnergyUsed = receiver.receiveEnergy(this.bcBlockType, convertedProvide, outputDirection.getOpposite());
|
||||
this.provideElectricity(forgienEnergyUsed * Compatibility.BC3_RATIO, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TE Methods
|
||||
*/
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
return (int) (this.receiveElectricity(from, ElectricityPack.getFromWatts(maxReceive * Compatibility.TE_RATIO, this.getVoltage()), !simulate) * Compatibility.TO_TE_RATIO);
|
||||
}
|
||||
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
return (int) (this.provideElectricity(from, ElectricityPack.getFromWatts(maxExtract * Compatibility.TE_RATIO, this.getVoltage()), !simulate).getWatts() * Compatibility.TO_TE_RATIO);
|
||||
}
|
||||
|
||||
public boolean canInterface(ForgeDirection from)
|
||||
{
|
||||
return this.canConnect(from);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return (int) (this.getEnergyStored() * Compatibility.TO_TE_RATIO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return (int) (this.getMaxEnergyStored() * Compatibility.TO_TE_RATIO);
|
||||
}
|
||||
|
||||
/**
|
||||
* IC2 Methods
|
||||
*/
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return this.getInputDirections().contains(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
return this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
this.provideElectricity((float) amount * Compatibility.IC2_RATIO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
protected void initIC()
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = true;
|
||||
}
|
||||
|
||||
private void unloadTileIC2()
|
||||
{
|
||||
if (this.isAddedToEnergyNet && this.worldObj != null)
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return this.getRequest(ForgeDirection.UNKNOWN) * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection direction, double amount)
|
||||
{
|
||||
if (this.getInputDirections().contains(direction))
|
||||
{
|
||||
float convertedEnergy = (float) (amount * Compatibility.IC2_RATIO);
|
||||
ElectricityPack toSend = ElectricityPack.getFromWatts(convertedEnergy, this.getVoltage());
|
||||
float receive = this.receiveElectricity(direction, toSend, true);
|
||||
|
||||
// Return the difference, since injectEnergy returns left over energy, and
|
||||
// receiveElectricity returns energy used.
|
||||
return Math.round(amount - (receive * Compatibility.TO_IC2_RATIO));
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
return receiver instanceof IEnergyTile && this.getOutputDirections().contains(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* BuildCraft power support
|
||||
*/
|
||||
public void initBuildCraft()
|
||||
{
|
||||
if (this.bcPowerHandler == null)
|
||||
{
|
||||
this.bcPowerHandler = new PowerHandler(this, this.bcBlockType);
|
||||
}
|
||||
this.bcPowerHandler.configure(0, this.maxInputEnergy, 0, (int) Math.ceil(this.getMaxEnergyStored() * Compatibility.BC3_RATIO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
this.initBuildCraft();
|
||||
return this.bcPowerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return this.getWorldObj();
|
||||
}
|
||||
}
|
|
@ -1,461 +0,0 @@
|
|||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import universalelectricity.core.block.INetworkConnection;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent;
|
||||
import universalelectricity.core.electricity.ElectricalEvent.ElectricityRequestEvent;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.grid.ElectricityNetwork;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import universalelectricity.core.path.Pathfinder;
|
||||
import universalelectricity.core.path.PathfinderChecker;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/**
|
||||
* A universal network that words with multiple energy systems.
|
||||
*
|
||||
* @author micdoodle8, Calclavia, Aidancbrady
|
||||
*
|
||||
*/
|
||||
public class UniversalNetwork extends ElectricityNetwork
|
||||
{
|
||||
@Override
|
||||
public float produce(ElectricityPack electricity, TileEntity... ignoreTiles)
|
||||
{
|
||||
ElectricityProductionEvent evt = new ElectricityProductionEvent(this, electricity, ignoreTiles);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
float totalEnergy = electricity.getWatts();
|
||||
float networkResistance = getTotalResistance();
|
||||
float proportionWasted = getTotalResistance() / (getTotalResistance() + acceptorResistance);
|
||||
float energyWasted = totalEnergy * proportionWasted;
|
||||
float totalUsableEnergy = totalEnergy - energyWasted;
|
||||
float remainingUsableEnergy = totalUsableEnergy;
|
||||
float voltage = electricity.voltage;
|
||||
|
||||
if (!evt.isCanceled())
|
||||
{
|
||||
Set<TileEntity> avaliableEnergyTiles = this.getAcceptors();
|
||||
|
||||
if (!avaliableEnergyTiles.isEmpty())
|
||||
{
|
||||
final float totalEnergyRequest = this.getRequest(ignoreTiles).getWatts();
|
||||
|
||||
if (totalEnergyRequest > 0)
|
||||
{
|
||||
boolean markRefresh = false;
|
||||
|
||||
for (TileEntity tileEntity : avaliableEnergyTiles)
|
||||
{
|
||||
if (tileEntity != null && !tileEntity.isInvalid())
|
||||
{
|
||||
if (remainingUsableEnergy > 0 && !Arrays.asList(ignoreTiles).contains(tileEntity))
|
||||
{
|
||||
if (tileEntity instanceof IElectrical)
|
||||
{
|
||||
IElectrical electricalTile = (IElectrical) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
float energyToSend = totalUsableEnergy * (Math.min(electricalTile.getRequest(direction), totalEnergyRequest) / totalEnergyRequest);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage);
|
||||
remainingUsableEnergy -= electricalTile.receiveElectricity(direction, electricityToSend, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IEnergySink)
|
||||
{
|
||||
IEnergySink electricalTile = (IEnergySink) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
|
||||
if (this.getConductors().contains(conductor) && electricalTile.acceptsEnergyFrom(conductor, direction))
|
||||
{
|
||||
float energyToSend = (float) Math.min(totalUsableEnergy * ((electricalTile.demandedEnergyUnits() * Compatibility.IC2_RATIO) / totalEnergyRequest), electricalTile.getMaxSafeInput() * Compatibility.IC2_RATIO);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
remainingUsableEnergy -= electricalTile.injectEnergyUnits(direction, energyToSend * Compatibility.TO_IC2_RATIO) * Compatibility.IC2_RATIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
IPowerReceptor electricalTile = (IPowerReceptor) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
PowerReceiver receiver = electricalTile.getPowerReceiver(direction);
|
||||
|
||||
if (receiver != null)
|
||||
{
|
||||
if (this.getConductors().contains(conductor))
|
||||
{
|
||||
float energyToSend = totalUsableEnergy * ((receiver.powerRequest() * Compatibility.BC3_RATIO) / totalEnergyRequest);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
remainingUsableEnergy -= receiver.receiveEnergy(Type.PIPE, energyToSend * Compatibility.TO_BC_RATIO, direction) * Compatibility.BC3_RATIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IEnergyHandler)
|
||||
{
|
||||
IEnergyHandler receiver = (IEnergyHandler) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
|
||||
if (receiver.canInterface(direction))
|
||||
{
|
||||
if (this.getConductors().contains(conductor))
|
||||
{
|
||||
float energyToSend = totalUsableEnergy * ((receiver.receiveEnergy(direction, (int) (remainingUsableEnergy * Compatibility.TO_TE_RATIO), true) * Compatibility.TE_RATIO) / totalEnergyRequest);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
remainingUsableEnergy -= receiver.receiveEnergy(direction, (int) (energyToSend * Compatibility.TO_TE_RATIO), false) * Compatibility.TE_RATIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
markRefresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (markRefresh)
|
||||
{
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingUsableEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getRequest(TileEntity... ignoreTiles)
|
||||
{
|
||||
List<ElectricityPack> requests = new ArrayList<ElectricityPack>();
|
||||
|
||||
Iterator<TileEntity> it = new HashSet(this.getAcceptors()).iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
TileEntity tileEntity = it.next();
|
||||
|
||||
if (Arrays.asList(ignoreTiles).contains(tileEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileEntity != null && !tileEntity.isInvalid())
|
||||
{
|
||||
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
|
||||
{
|
||||
if (tileEntity instanceof IElectrical)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IElectrical) tileEntity).canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
requests.add(ElectricityPack.getFromWatts(((IElectrical) tileEntity).getRequest(direction), ((IElectrical) tileEntity).getVoltage()));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileEntity instanceof IEnergyHandler)
|
||||
{
|
||||
IEnergyHandler receiver = (IEnergyHandler) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
|
||||
if (receiver.canInterface(direction) && this.getConductors().contains(conductor))
|
||||
{
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts(receiver.receiveEnergy(direction, (int) Integer.MAX_VALUE, true) * Compatibility.TE_RATIO, 1);
|
||||
|
||||
if (pack.getWatts() > 0)
|
||||
{
|
||||
requests.add(pack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileEntity instanceof IEnergySink)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IEnergySink) tileEntity).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction), direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts((float) (((IEnergySink) tileEntity).demandedEnergyUnits() * Compatibility.IC2_RATIO), 1);
|
||||
|
||||
if (pack.getWatts() > 0)
|
||||
{
|
||||
requests.add(pack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IPowerReceptor) tileEntity).getPowerReceiver(direction) != null)
|
||||
{
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts(((IPowerReceptor) tileEntity).getPowerReceiver(direction).powerRequest() * Compatibility.BC3_RATIO, 1);
|
||||
|
||||
if (pack.getWatts() > 0)
|
||||
{
|
||||
requests.add(pack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ElectricityPack mergedPack = ElectricityPack.merge(requests);
|
||||
ElectricityRequestEvent evt = new ElectricityRequestEvent(this, mergedPack, ignoreTiles);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return mergedPack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
this.electricalTiles.clear();
|
||||
|
||||
try
|
||||
{
|
||||
Iterator<IConductor> it = this.getConductors().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
IConductor conductor = it.next();
|
||||
|
||||
if (conductor == null)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
else if (((TileEntity) conductor).isInvalid() || ((TileEntity) conductor).getWorldObj() == null)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
else if (((TileEntity) conductor).getWorldObj().getBlockTileEntity(((TileEntity) conductor).xCoord, ((TileEntity) conductor).yCoord, ((TileEntity) conductor).zCoord) != conductor)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
conductor.setNetwork(this);
|
||||
}
|
||||
|
||||
for (int i = 0; i < conductor.getAdjacentConnections().length; i++)
|
||||
{
|
||||
TileEntity acceptor = conductor.getAdjacentConnections()[i];
|
||||
// The direction is from the perspective of the conductor.
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
|
||||
if (!(acceptor instanceof IConductor))
|
||||
{
|
||||
if (acceptor instanceof IElectrical || acceptor instanceof IEnergyHandler || acceptor instanceof IEnergyAcceptor || acceptor instanceof IPowerReceptor)
|
||||
{
|
||||
ArrayList<ForgeDirection> possibleDirections = null;
|
||||
|
||||
if (this.electricalTiles.containsKey(acceptor))
|
||||
{
|
||||
possibleDirections = this.electricalTiles.get(acceptor);
|
||||
}
|
||||
else
|
||||
{
|
||||
possibleDirections = new ArrayList<ForgeDirection>();
|
||||
}
|
||||
|
||||
if (acceptor instanceof IElectrical && ((IElectrical) acceptor).canConnect(direction))
|
||||
{
|
||||
possibleDirections.add(direction);
|
||||
}
|
||||
else if (acceptor instanceof IEnergyHandler && ((IEnergyHandler) acceptor).canInterface(direction))
|
||||
{
|
||||
possibleDirections.add(direction);
|
||||
}
|
||||
else if (acceptor instanceof IEnergyAcceptor && ((IEnergyAcceptor) acceptor).acceptsEnergyFrom((TileEntity) conductor, direction))
|
||||
{
|
||||
possibleDirections.add(direction);
|
||||
}
|
||||
else if (acceptor instanceof IPowerReceptor && ((IPowerReceptor) acceptor).getPowerReceiver(direction) != null)
|
||||
{
|
||||
possibleDirections.add(direction);
|
||||
}
|
||||
|
||||
if (!possibleDirections.isEmpty())
|
||||
{
|
||||
this.electricalTiles.put(acceptor, possibleDirections);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Universal Electricity: Failed to refresh conductor.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(IElectricityNetwork network)
|
||||
{
|
||||
if (network != null && network != this)
|
||||
{
|
||||
UniversalNetwork newNetwork = new UniversalNetwork();
|
||||
newNetwork.getConductors().addAll(this.getConductors());
|
||||
newNetwork.getConductors().addAll(network.getConductors());
|
||||
newNetwork.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void split(IConductor splitPoint)
|
||||
{
|
||||
if (splitPoint instanceof TileEntity)
|
||||
{
|
||||
this.getConductors().remove(splitPoint);
|
||||
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere.
|
||||
*/
|
||||
TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
TileEntity connectedBlockA = connectedBlocks[i];
|
||||
|
||||
if (connectedBlockA instanceof INetworkConnection)
|
||||
{
|
||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||
{
|
||||
final TileEntity connectedBlockB = connectedBlocks[ii];
|
||||
|
||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection)
|
||||
{
|
||||
Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).worldObj, (INetworkConnection) connectedBlockB, splitPoint);
|
||||
finder.init(new Vector3(connectedBlockA));
|
||||
|
||||
if (finder.results.size() > 0)
|
||||
{
|
||||
/**
|
||||
* The connections A and B are still intact elsewhere. Set all
|
||||
* references of wire connection into one network.
|
||||
*/
|
||||
|
||||
for (Vector3 node : finder.closedSet)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj);
|
||||
|
||||
if (nodeTile instanceof INetworkProvider)
|
||||
{
|
||||
if (nodeTile != splitPoint)
|
||||
{
|
||||
((INetworkProvider) nodeTile).setNetwork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* The connections A and B are not connected anymore. Give both of
|
||||
* them a new network.
|
||||
*/
|
||||
IElectricityNetwork newNetwork = new UniversalNetwork();
|
||||
|
||||
for (Vector3 node : finder.closedSet)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj);
|
||||
|
||||
if (nodeTile instanceof INetworkProvider)
|
||||
{
|
||||
if (nodeTile != splitPoint)
|
||||
{
|
||||
newNetwork.getConductors().add((IConductor) nodeTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newNetwork.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "UniversalNetwork[" + this.hashCode() + "|Wires:" + this.getConductors().size() + "|Acceptors:" + this.electricalTiles.size() + "]";
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package universalelectricity.core;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
/**
|
||||
* General Universal Electricity class.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class UniversalElectricity
|
||||
{
|
||||
/**
|
||||
* The version of the Universal Electricity API.
|
||||
*/
|
||||
public static final String MAJOR_VERSION = "@MAJOR@";
|
||||
public static final String MINOR_VERSION = "@MINOR@";
|
||||
public static final String REVISION_VERSION = "@REVIS@";
|
||||
public static final String BUILD_VERSION = "@BUILD@";
|
||||
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
|
||||
|
||||
/**
|
||||
* The Universal Electricity configuration file.
|
||||
*/
|
||||
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity.cfg"));
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
//TODO: Enable this next major MC version
|
||||
//public static float DEFAULT_VOLTAGE = 1;
|
||||
|
||||
/**
|
||||
* Set this value to true if your mod contains and has the ability to transfer electricity via
|
||||
* the ElectricityNetwork. Examples would be a mod that adds any sort of wire. This value will
|
||||
* be true as long as there is a way to conduct electricity.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isNetworkActive = false;
|
||||
|
||||
/**
|
||||
* A general material that can be used by machines. Breakable by hand, suitable for machines.
|
||||
*/
|
||||
public static final Material machine = new Material(MapColor.ironColor);
|
||||
|
||||
private static boolean INIT = false;
|
||||
|
||||
static
|
||||
{
|
||||
initiate();
|
||||
}
|
||||
|
||||
public static void initiate()
|
||||
{
|
||||
if (!INIT)
|
||||
{
|
||||
/**
|
||||
* Loads the configuration and sets all the values.
|
||||
*/
|
||||
CONFIGURATION.load();
|
||||
isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive);
|
||||
isNetworkActive = CONFIGURATION.get("Compatiblity", "Is Network Active", isNetworkActive).getBoolean(isNetworkActive);
|
||||
CONFIGURATION.save();
|
||||
|
||||
try
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(Class.forName("universalelectricity.core.electricity.ElectricityHelper").newInstance());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
INIT = true;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
public interface IConductor extends INetworkProvider, INetworkConnection
|
||||
{
|
||||
/**
|
||||
* Gets the resistance of the conductor. Used to calculate energy loss. A higher resistance
|
||||
* means a higher energy loss.
|
||||
*
|
||||
* @return The amount of resistance in Ohms.
|
||||
*/
|
||||
public float getResistance();
|
||||
|
||||
/**
|
||||
* @return The maximum amount of amps this conductor can handle before melting down.
|
||||
*/
|
||||
public float getCurrentCapacity();
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Applied to TileEntities that can connect to an electrical network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IConnector
|
||||
{
|
||||
|
||||
/**
|
||||
* @return If the connection is possible.
|
||||
*/
|
||||
public boolean canConnect(ForgeDirection direction);
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
|
||||
/**
|
||||
* Applied to all TileEntities that can interact with electricity.
|
||||
*
|
||||
* @author Calclavia, King_Lemming
|
||||
*
|
||||
*/
|
||||
public interface IElectrical extends IConnector
|
||||
{
|
||||
/**
|
||||
* Adds electricity to an block. Returns the quantity of electricity that was accepted. This
|
||||
* should always return 0 if the block cannot be externally charged.
|
||||
*
|
||||
* @param from Orientation the electricity is sent in from.
|
||||
* @param receive Maximum amount of electricity to be sent into the block.
|
||||
* @param doReceive If false, the charge will only be simulated.
|
||||
* @return Amount of energy that was accepted by the block.
|
||||
*/
|
||||
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive);
|
||||
|
||||
/**
|
||||
* Adds electricity to an block. Returns the ElectricityPack, the electricity provided. This
|
||||
* should always return null if the block cannot be externally discharged.
|
||||
*
|
||||
* @param from Orientation the electricity is requested from.
|
||||
* @param energy Maximum amount of energy to be sent into the block.
|
||||
* @param doReceive If false, the charge will only be simulated.
|
||||
* @return Amount of energy that was given out by the block.
|
||||
*/
|
||||
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide);
|
||||
|
||||
/**
|
||||
* @return How much energy does this TileEntity want?
|
||||
*/
|
||||
public float getRequest(ForgeDirection direction);
|
||||
|
||||
/**
|
||||
* @return How much energy does this TileEntity want to provide?
|
||||
*/
|
||||
public float getProvide(ForgeDirection direction);
|
||||
|
||||
/**
|
||||
* Gets the voltage of this TileEntity.
|
||||
*
|
||||
* @return The amount of volts. E.g 120v or 240v
|
||||
*/
|
||||
public float getVoltage();
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
/**
|
||||
* This interface is to be applied to all TileEntities which stores electricity within them.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public interface IElectricalStorage
|
||||
{
|
||||
/**
|
||||
* Sets the amount of joules this unit has stored.
|
||||
*/
|
||||
public void setEnergyStored(float energy);
|
||||
|
||||
/**
|
||||
* * @return Get the amount of energy currently stored in the block.
|
||||
*/
|
||||
public float getEnergyStored();
|
||||
|
||||
/**
|
||||
* @return Get the max amount of energy that can be stored in the block.
|
||||
*/
|
||||
public float getMaxEnergyStored();
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Applied to TileEntities.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface INetworkConnection extends IConnector
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets a list of all the connected TileEntities that this conductor is connected to. The
|
||||
* array's length should be always the 6 adjacent wires.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TileEntity[] getAdjacentConnections();
|
||||
|
||||
/**
|
||||
* Refreshes the conductor
|
||||
*/
|
||||
public void refresh();
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
|
||||
/**
|
||||
* Applied to TileEntities that has an instance of an electricity network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface INetworkProvider
|
||||
{
|
||||
public IElectricityNetwork getNetwork();
|
||||
|
||||
public void setNetwork(IElectricityNetwork network);
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
|
||||
public class ElectricalEvent extends Event
|
||||
{
|
||||
/**
|
||||
* Call this to have your TileEntity produce power into the network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ElectricityProduceEvent extends ElectricalEvent
|
||||
{
|
||||
public World world;
|
||||
public IElectrical tileEntity;
|
||||
|
||||
public ElectricityProduceEvent(IElectrical tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
this.world = ((TileEntity) this.tileEntity).worldObj;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkEvent extends ElectricalEvent
|
||||
{
|
||||
public final IElectricityNetwork network;
|
||||
public ElectricityPack electricityPack;
|
||||
public TileEntity[] ignoreTiles;
|
||||
|
||||
public NetworkEvent(IElectricityNetwork network, ElectricityPack electricityPack, TileEntity... ignoreTiles)
|
||||
{
|
||||
this.network = network;
|
||||
this.electricityPack = electricityPack;
|
||||
this.ignoreTiles = ignoreTiles;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal Events. These events are fired when something happens in the network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ElectricityProductionEvent extends NetworkEvent
|
||||
{
|
||||
public ElectricityProductionEvent(IElectricityNetwork network, ElectricityPack electricityPack, TileEntity... ignoreTiles)
|
||||
{
|
||||
super(network, electricityPack, ignoreTiles);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ElectricityRequestEvent extends NetworkEvent
|
||||
{
|
||||
public ElectricityRequestEvent(IElectricityNetwork network, ElectricityPack electricityPack, TileEntity... ignoreTiles)
|
||||
{
|
||||
super(network, electricityPack, ignoreTiles);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
/**
|
||||
* An easy way to display information on electricity for the client.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public class ElectricityDisplay
|
||||
{
|
||||
/**
|
||||
* Universal Electricity's units are in KILOJOULES, KILOWATTS and KILOVOLTS. Try to make your
|
||||
* energy ratio as close to real life as possible.
|
||||
*/
|
||||
public static enum ElectricUnit
|
||||
{
|
||||
AMPERE("Amp", "I"), AMP_HOUR("Amp Hour", "Ah"), VOLTAGE("Volt", "V"), WATT("Watt", "W"),
|
||||
WATT_HOUR("Watt Hour", "Wh"), RESISTANCE("Ohm", "R"), CONDUCTANCE("Siemen", "S"),
|
||||
JOULES("Joule", "J");
|
||||
|
||||
public String name;
|
||||
public String symbol;
|
||||
|
||||
private ElectricUnit(String name, String symbol)
|
||||
{
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getPlural()
|
||||
{
|
||||
return this.name + "s";
|
||||
}
|
||||
}
|
||||
|
||||
/** Metric system of measurement. */
|
||||
public static enum MeasurementUnit
|
||||
{
|
||||
MICRO("Micro", "u", 0.000001f), MILLI("Milli", "m", 0.001f), BASE("", "", 1),
|
||||
KILO("Kilo", "k", 1000f), MEGA("Mega", "M", 1000000f), GIGA("Giga", "G", 1000000000f),
|
||||
TERA("Tera", "T", 1000000000000f), PETA("Peta", "P", 1000000000000000f),
|
||||
EXA("Exa", "E", 1000000000000000000f), ZETTA("Zetta", "Z", 1000000000000000000000f),
|
||||
YOTTA("Yotta", "Y", 1000000000000000000000000f);
|
||||
|
||||
/** long name for the unit */
|
||||
public String name;
|
||||
/** short unit version of the unit */
|
||||
public String symbol;
|
||||
/** Point by which a number is consider to be of this unit */
|
||||
public float value;
|
||||
|
||||
private MeasurementUnit(String name, String symbol, float value)
|
||||
{
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName(boolean getShort)
|
||||
{
|
||||
if (getShort)
|
||||
{
|
||||
return symbol;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
/** Divides the value by the unit value start */
|
||||
public double process(double value)
|
||||
{
|
||||
return value / this.value;
|
||||
}
|
||||
|
||||
/** Checks if a value is above the unit value start */
|
||||
public boolean isAbove(float value)
|
||||
{
|
||||
return value > this.value;
|
||||
}
|
||||
|
||||
/** Checks if a value is lower than the unit value start */
|
||||
public boolean isBellow(float value)
|
||||
{
|
||||
return value < this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** By default, mods should store energy in Kilo-Joules, hence a multiplier of 1/1000. */
|
||||
public static String getDisplay(float value, ElectricUnit unit, int decimalPlaces, boolean isShort)
|
||||
{
|
||||
return getDisplay(value, unit, decimalPlaces, isShort, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the unit as text. Does handle negative numbers, and will place a negative sign in
|
||||
* front of the output string showing this. Use string.replace to remove the negative sign if
|
||||
* unwanted
|
||||
*/
|
||||
public static String getDisplay(float value, ElectricUnit unit, int decimalPlaces, boolean isShort, float multiplier)
|
||||
{
|
||||
String unitName = unit.name;
|
||||
String prefix = "";
|
||||
if (value < 0)
|
||||
{
|
||||
value = Math.abs(value);
|
||||
prefix = "-";
|
||||
}
|
||||
value *= multiplier;
|
||||
|
||||
if (isShort)
|
||||
{
|
||||
unitName = unit.symbol;
|
||||
}
|
||||
else if (value > 1)
|
||||
{
|
||||
unitName = unit.getPlural();
|
||||
}
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
return value + " " + unitName;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < MeasurementUnit.values().length; i++)
|
||||
{
|
||||
MeasurementUnit lowerMeasure = MeasurementUnit.values()[i];
|
||||
if (lowerMeasure.isBellow(value) && lowerMeasure.ordinal() == 0)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
if (lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1];
|
||||
if ((lowerMeasure.isAbove(value) && upperMeasure.isBellow(value)) || lowerMeasure.value == value)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + roundDecimals(value, decimalPlaces) + " " + unitName;
|
||||
}
|
||||
|
||||
public static String getDisplay(float value, ElectricUnit unit)
|
||||
{
|
||||
return getDisplay(value, unit, 2, false);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(float value, ElectricUnit unit)
|
||||
{
|
||||
return getDisplay(value, unit, 2, true);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(float value, ElectricUnit unit, int decimalPlaces)
|
||||
{
|
||||
return getDisplay(value, unit, decimalPlaces, true);
|
||||
}
|
||||
|
||||
public static String getDisplaySimple(float value, ElectricUnit unit, int decimalPlaces)
|
||||
{
|
||||
if (value > 1)
|
||||
{
|
||||
if (decimalPlaces < 1)
|
||||
{
|
||||
return (int) value + " " + unit.getPlural();
|
||||
}
|
||||
|
||||
return roundDecimals(value, decimalPlaces) + " " + unit.getPlural();
|
||||
}
|
||||
|
||||
if (decimalPlaces < 1)
|
||||
{
|
||||
return (int) value + " " + unit.name;
|
||||
}
|
||||
|
||||
return roundDecimals(value, decimalPlaces) + " " + unit.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds a number to a specific number place places
|
||||
*
|
||||
* @param The number
|
||||
* @return The rounded number
|
||||
*/
|
||||
public static double roundDecimals(double d, int decimalPlaces)
|
||||
{
|
||||
int j = (int) (d * Math.pow(10, decimalPlaces));
|
||||
return j / Math.pow(10, decimalPlaces);
|
||||
}
|
||||
|
||||
public static double roundDecimals(double d)
|
||||
{
|
||||
return roundDecimals(d, 2);
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* A helper class that provides additional useful functions to interact with the ElectricityNetwork
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricityHelper
|
||||
{
|
||||
public static EnumSet<ForgeDirection> getDirections(TileEntity tileEntity)
|
||||
{
|
||||
EnumSet<ForgeDirection> possibleSides = EnumSet.noneOf(ForgeDirection.class);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
if (((IConnector) tileEntity).canConnect(direction))
|
||||
{
|
||||
possibleSides.add(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return possibleSides;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
return ElectricityHelper.produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces 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 to.
|
||||
* @param producePack - The amount of electricity to be produced.
|
||||
* @return What remained in the electricity pack.
|
||||
*/
|
||||
@Deprecated
|
||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack producingPack)
|
||||
{
|
||||
ElectricityPack remainingElectricity = producingPack.clone();
|
||||
|
||||
if (tileEntity != null && approachingDirection != null)
|
||||
{
|
||||
final Set<IElectricityNetwork> connectedNetworks = ElectricityHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
||||
|
||||
if (connectedNetworks.size() > 0)
|
||||
{
|
||||
/**
|
||||
* Requests an even amount of electricity from all sides.
|
||||
*/
|
||||
float wattsPerSide = (producingPack.getWatts() / connectedNetworks.size());
|
||||
float voltage = producingPack.voltage;
|
||||
|
||||
for (IElectricityNetwork network : connectedNetworks)
|
||||
{
|
||||
if (wattsPerSide > 0 && producingPack.getWatts() > 0)
|
||||
{
|
||||
float amperes = Math.min(wattsPerSide / voltage, network.getRequest(tileEntity).getWatts() / voltage);
|
||||
|
||||
if (amperes > 0)
|
||||
{
|
||||
network.produce(new ElectricityPack(amperes, voltage));
|
||||
remainingElectricity.amperes -= amperes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingElectricity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tileEntity - The TileEntity's sides.
|
||||
* @param approachingDirection - The directions that can be connected.
|
||||
* @return A list of networks from all specified sides. There will be no repeated
|
||||
* ElectricityNetworks and it will never return null.
|
||||
*/
|
||||
public static Set<IElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection)
|
||||
{
|
||||
final Set<IElectricityNetwork> connectedNetworks = new HashSet<IElectricityNetwork>();
|
||||
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (approachingDirection.contains(side))
|
||||
{
|
||||
Vector3 position = new Vector3(tileEntity);
|
||||
position.modifyPositionFromSide(side);
|
||||
|
||||
TileEntity outputConductor = position.getTileEntity(tileEntity.worldObj);
|
||||
IElectricityNetwork electricityNetwork = ElectricityHelper.getNetworkFromTileEntity(outputConductor, side);
|
||||
|
||||
if (electricityNetwork != null)
|
||||
{
|
||||
connectedNetworks.add(electricityNetwork);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return connectedNetworks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find the electricity network based in a tile entity and checks to see if it is a
|
||||
* conductor. All machines should use this function to search for a connecting conductor around
|
||||
* it.
|
||||
*
|
||||
* @param conductor - The TileEntity conductor
|
||||
* @param approachDirection - The direction you are approaching this wire from.
|
||||
* @return The ElectricityNetwork or null if not found.
|
||||
*/
|
||||
public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection)
|
||||
{
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity instanceof INetworkProvider)
|
||||
{
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(approachDirection.getOpposite()))
|
||||
{
|
||||
return ((INetworkProvider) tileEntity).getNetwork();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((INetworkProvider) tileEntity).getNetwork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple way to store electrical data.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricityPack implements Cloneable
|
||||
{
|
||||
public float amperes;
|
||||
public float voltage;
|
||||
|
||||
public ElectricityPack(float amperes, float voltage)
|
||||
{
|
||||
this.amperes = amperes;
|
||||
this.voltage = voltage;
|
||||
}
|
||||
|
||||
public ElectricityPack()
|
||||
{
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public static ElectricityPack getFromWatts(float watts, float voltage)
|
||||
{
|
||||
return new ElectricityPack(watts / voltage, voltage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges multiple ElectricityPacks together to form one with an average voltage.
|
||||
*/
|
||||
public static ElectricityPack merge(ElectricityPack... packs)
|
||||
{
|
||||
float totalEnergy = 0;
|
||||
float totalVoltage = 0;
|
||||
|
||||
for (ElectricityPack pack : packs)
|
||||
{
|
||||
totalEnergy += pack.getWatts();
|
||||
totalVoltage += pack.voltage;
|
||||
}
|
||||
|
||||
if (totalEnergy <= 0 || totalVoltage <= 0)
|
||||
{
|
||||
return new ElectricityPack();
|
||||
}
|
||||
|
||||
return ElectricityPack.getFromWatts(totalEnergy, totalVoltage / packs.length);
|
||||
}
|
||||
|
||||
public static ElectricityPack merge(List<ElectricityPack> providedPacks)
|
||||
{
|
||||
return merge(providedPacks.toArray(new ElectricityPack[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ElectricityPack with the largest amount of energy.
|
||||
*/
|
||||
public static ElectricityPack max(ElectricityPack... packs)
|
||||
{
|
||||
ElectricityPack optimalPack = null;
|
||||
|
||||
for (ElectricityPack pack : packs)
|
||||
{
|
||||
if (optimalPack == null || (optimalPack != null && pack.getWatts() > optimalPack.getWatts()))
|
||||
{
|
||||
optimalPack = pack;
|
||||
}
|
||||
}
|
||||
|
||||
return optimalPack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ElectricityPack with the smallest amount of energy.
|
||||
*/
|
||||
public static ElectricityPack min(ElectricityPack... packs)
|
||||
{
|
||||
ElectricityPack optimalPack = null;
|
||||
|
||||
for (ElectricityPack pack : packs)
|
||||
{
|
||||
if (optimalPack == null || (optimalPack != null && pack.getWatts() < optimalPack.getWatts()))
|
||||
{
|
||||
optimalPack = pack;
|
||||
}
|
||||
}
|
||||
|
||||
return optimalPack;
|
||||
}
|
||||
|
||||
public float getWatts()
|
||||
{
|
||||
return getWatts(amperes, voltage);
|
||||
}
|
||||
|
||||
public float getConductance()
|
||||
{
|
||||
return getConductance(amperes, voltage);
|
||||
}
|
||||
|
||||
public float getResistance()
|
||||
{
|
||||
return getResistance(amperes, voltage);
|
||||
}
|
||||
|
||||
public static float getJoules(float watts, float seconds)
|
||||
{
|
||||
return watts * seconds;
|
||||
}
|
||||
|
||||
public static float getJoules(float amps, float voltage, float seconds)
|
||||
{
|
||||
return amps * voltage * seconds;
|
||||
}
|
||||
|
||||
public static float getWattsFromJoules(float joules, float seconds)
|
||||
{
|
||||
return joules / seconds;
|
||||
}
|
||||
|
||||
public static float getAmps(float watts, float voltage)
|
||||
{
|
||||
return watts / voltage;
|
||||
}
|
||||
|
||||
public static float getAmps(float ampHours)
|
||||
{
|
||||
return ampHours * 3600;
|
||||
}
|
||||
|
||||
public static float getAmpsFromWattHours(float wattHours, float voltage)
|
||||
{
|
||||
return getWatts(wattHours) / voltage;
|
||||
}
|
||||
|
||||
public static float getWattHoursFromAmpHours(float ampHours, float voltage)
|
||||
{
|
||||
return ampHours * voltage;
|
||||
}
|
||||
|
||||
public static float getAmpHours(float amps)
|
||||
{
|
||||
return amps / 3600;
|
||||
}
|
||||
|
||||
public static float getWatts(float amps, float voltage)
|
||||
{
|
||||
return amps * voltage;
|
||||
}
|
||||
|
||||
public static float getWatts(float wattHours)
|
||||
{
|
||||
return wattHours * 3600;
|
||||
}
|
||||
|
||||
public static float getWattHours(float watts)
|
||||
{
|
||||
return watts / 3600;
|
||||
}
|
||||
|
||||
public static float getWattHours(float amps, float voltage)
|
||||
{
|
||||
return getWattHours(getWatts(amps, voltage));
|
||||
}
|
||||
|
||||
public static float getResistance(float amps, float voltage)
|
||||
{
|
||||
return voltage / amps;
|
||||
}
|
||||
|
||||
public static float getConductance(float amps, float voltage)
|
||||
{
|
||||
return amps / voltage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ElectricityPack [Amps:" + this.amperes + " Volts:" + this.voltage + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack clone()
|
||||
{
|
||||
return new ElectricityPack(this.amperes, this.voltage);
|
||||
}
|
||||
|
||||
public boolean isEqual(ElectricityPack electricityPack)
|
||||
{
|
||||
return this.amperes == electricityPack.amperes && this.voltage == electricityPack.voltage;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class NetworkLoader
|
||||
{
|
||||
/**
|
||||
* The default IElectricityNetwork used for primary electrical networks.
|
||||
*/
|
||||
public static Class<? extends IElectricityNetwork> NETWORK_CLASS;
|
||||
public static final Set<Class<? extends IElectricityNetwork>> NETWORK_CLASS_REGISTRY = new HashSet<Class<? extends IElectricityNetwork>>();
|
||||
|
||||
static
|
||||
{
|
||||
setNetworkClass("universalelectricity.core.grid.ElectricityNetwork");
|
||||
}
|
||||
|
||||
public static void setNetworkClass(Class<? extends IElectricityNetwork> networkClass)
|
||||
{
|
||||
NETWORK_CLASS_REGISTRY.add(networkClass);
|
||||
NETWORK_CLASS = networkClass;
|
||||
}
|
||||
|
||||
public static void setNetworkClass(String className)
|
||||
{
|
||||
try
|
||||
{
|
||||
setNetworkClass((Class<? extends IElectricityNetwork>) Class.forName(className));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Universal Electricity: Failed to set network class with name " + className);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static IElectricityNetwork getNewNetwork(IConductor... conductors)
|
||||
{
|
||||
try
|
||||
{
|
||||
IElectricityNetwork network = NETWORK_CLASS.newInstance();
|
||||
network.getConductors().addAll(Arrays.asList(conductors));
|
||||
return network;
|
||||
}
|
||||
catch (InstantiationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,356 +0,0 @@
|
|||
package universalelectricity.core.grid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import universalelectricity.core.block.INetworkConnection;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent;
|
||||
import universalelectricity.core.electricity.ElectricalEvent.ElectricityRequestEvent;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.path.Pathfinder;
|
||||
import universalelectricity.core.path.PathfinderChecker;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/**
|
||||
* An Electrical Network specifies a wire connection. Each wire connection line will have its own
|
||||
* electrical network.
|
||||
*
|
||||
* !! Do not include this class if you do not intend to have custom wires in your mod. This will
|
||||
* increase future compatibility. !!
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricityNetwork implements IElectricityNetwork
|
||||
{
|
||||
public Map<TileEntity, ArrayList<ForgeDirection>> electricalTiles = new HashMap<TileEntity, ArrayList<ForgeDirection>>();
|
||||
|
||||
private final Set<IConductor> conductors = new HashSet<IConductor>();
|
||||
|
||||
public float acceptorResistance = 500;
|
||||
|
||||
@Override
|
||||
public float produce(ElectricityPack electricity, TileEntity... ignoreTiles)
|
||||
{
|
||||
ElectricityProductionEvent evt = new ElectricityProductionEvent(this, electricity, ignoreTiles);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
float totalEnergy = electricity.getWatts();
|
||||
float networkResistance = getTotalResistance();
|
||||
float proportionWasted = getTotalResistance() / (getTotalResistance() + acceptorResistance);
|
||||
float energyWasted = totalEnergy * proportionWasted;
|
||||
float totalUsableEnergy = totalEnergy - energyWasted;
|
||||
float remainingUsableEnergy = totalUsableEnergy;
|
||||
float voltage = electricity.voltage;
|
||||
|
||||
if (!evt.isCanceled())
|
||||
{
|
||||
Set<TileEntity> avaliableEnergyTiles = this.getAcceptors();
|
||||
|
||||
if (!avaliableEnergyTiles.isEmpty())
|
||||
{
|
||||
final float totalEnergyRequest = this.getRequest(ignoreTiles).getWatts();
|
||||
|
||||
if (totalEnergyRequest > 0)
|
||||
{
|
||||
for (TileEntity tileEntity : avaliableEnergyTiles)
|
||||
{
|
||||
if (!Arrays.asList(ignoreTiles).contains(tileEntity))
|
||||
{
|
||||
if (tileEntity instanceof IElectrical)
|
||||
{
|
||||
IElectrical electricalTile = (IElectrical) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
float energyToSend = totalUsableEnergy * (electricalTile.getRequest(direction) / totalEnergyRequest);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage);
|
||||
|
||||
remainingUsableEnergy -= ((IElectrical) tileEntity).receiveElectricity(direction, electricityToSend, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingUsableEnergy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return How much electricity this network needs.
|
||||
*/
|
||||
@Override
|
||||
public ElectricityPack getRequest(TileEntity... ignoreTiles)
|
||||
{
|
||||
List<ElectricityPack> requests = new ArrayList<ElectricityPack>();
|
||||
|
||||
Iterator<TileEntity> it = this.getAcceptors().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
TileEntity tileEntity = it.next();
|
||||
|
||||
if (Arrays.asList(ignoreTiles).contains(tileEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileEntity instanceof IElectrical)
|
||||
{
|
||||
if (!tileEntity.isInvalid())
|
||||
{
|
||||
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IElectrical) tileEntity).canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
requests.add(ElectricityPack.getFromWatts(((IElectrical) tileEntity).getRequest(direction), ((IElectrical) tileEntity).getVoltage()));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ElectricityPack mergedPack = ElectricityPack.merge(requests);
|
||||
ElectricityRequestEvent evt = new ElectricityRequestEvent(this, mergedPack, ignoreTiles);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return mergedPack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns all producers in this electricity network.
|
||||
*/
|
||||
@Override
|
||||
public Set<TileEntity> getAcceptors()
|
||||
{
|
||||
return this.electricalTiles.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tile The tile to get connections for
|
||||
* @return The list of directions that can be connected to for the provided tile
|
||||
*/
|
||||
@Override
|
||||
public ArrayList<ForgeDirection> getPossibleDirections(TileEntity tile)
|
||||
{
|
||||
return this.electricalTiles.containsKey(tile) ? this.electricalTiles.get(tile) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called to refresh all conductors in this network
|
||||
*/
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
this.electricalTiles.clear();
|
||||
|
||||
try
|
||||
{
|
||||
Iterator<IConductor> it = this.conductors.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
IConductor conductor = it.next();
|
||||
|
||||
if (conductor == null)
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else if (((TileEntity) conductor).isInvalid())
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
conductor.setNetwork(this);
|
||||
}
|
||||
|
||||
for (int i = 0; i < conductor.getAdjacentConnections().length; i++)
|
||||
{
|
||||
TileEntity acceptor = conductor.getAdjacentConnections()[i];
|
||||
|
||||
if (!(acceptor instanceof IConductor) && acceptor instanceof IConnector)
|
||||
{
|
||||
ArrayList<ForgeDirection> possibleDirections = null;
|
||||
|
||||
if (this.electricalTiles.containsKey(acceptor))
|
||||
{
|
||||
possibleDirections = this.electricalTiles.get(acceptor);
|
||||
}
|
||||
else
|
||||
{
|
||||
possibleDirections = new ArrayList<ForgeDirection>();
|
||||
}
|
||||
|
||||
possibleDirections.add(ForgeDirection.getOrientation(i));
|
||||
|
||||
this.electricalTiles.put(acceptor, possibleDirections);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Universal Electricity: Failed to refresh conductor.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTotalResistance()
|
||||
{
|
||||
float resistance = 0;
|
||||
|
||||
for (IConductor conductor : this.conductors)
|
||||
{
|
||||
resistance += conductor.getResistance();
|
||||
}
|
||||
|
||||
return resistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLowestCurrentCapacity()
|
||||
{
|
||||
float lowestAmperage = 0;
|
||||
|
||||
for (IConductor conductor : this.conductors)
|
||||
{
|
||||
if (lowestAmperage == 0 || conductor.getCurrentCapacity() < lowestAmperage)
|
||||
{
|
||||
lowestAmperage = conductor.getCurrentCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
return lowestAmperage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IConductor> getConductors()
|
||||
{
|
||||
return this.conductors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(IElectricityNetwork network)
|
||||
{
|
||||
if (network != null && network != this)
|
||||
{
|
||||
ElectricityNetwork newNetwork = new ElectricityNetwork();
|
||||
newNetwork.getConductors().addAll(this.getConductors());
|
||||
newNetwork.getConductors().addAll(network.getConductors());
|
||||
newNetwork.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void split(IConductor splitPoint)
|
||||
{
|
||||
if (splitPoint instanceof TileEntity)
|
||||
{
|
||||
this.getConductors().remove(splitPoint);
|
||||
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere.
|
||||
*/
|
||||
TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
TileEntity connectedBlockA = connectedBlocks[i];
|
||||
|
||||
if (connectedBlockA instanceof INetworkConnection)
|
||||
{
|
||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||
{
|
||||
final TileEntity connectedBlockB = connectedBlocks[ii];
|
||||
|
||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection)
|
||||
{
|
||||
Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).worldObj, (INetworkConnection) connectedBlockB, splitPoint);
|
||||
finder.init(new Vector3(connectedBlockA));
|
||||
|
||||
if (finder.results.size() > 0)
|
||||
{
|
||||
/**
|
||||
* The connections A and B are still intact elsewhere. Set all
|
||||
* references of wire connection into one network.
|
||||
*/
|
||||
|
||||
for (Vector3 node : finder.closedSet)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj);
|
||||
|
||||
if (nodeTile instanceof INetworkProvider)
|
||||
{
|
||||
if (nodeTile != splitPoint)
|
||||
{
|
||||
((INetworkProvider) nodeTile).setNetwork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* The connections A and B are not connected anymore. Give both of
|
||||
* them a new network.
|
||||
*/
|
||||
IElectricityNetwork newNetwork = new ElectricityNetwork();
|
||||
|
||||
for (Vector3 node : finder.closedSet)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj);
|
||||
|
||||
if (nodeTile instanceof INetworkProvider)
|
||||
{
|
||||
if (nodeTile != splitPoint)
|
||||
{
|
||||
newNetwork.getConductors().add((IConductor) nodeTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newNetwork.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "|Acceptors:" + this.electricalTiles.size() + "]";
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package universalelectricity.core.grid;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
|
||||
/**
|
||||
* The Electrical Network in interface form.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IElectricityNetwork extends IGridNetwork<IElectricityNetwork, IConductor, TileEntity>
|
||||
{
|
||||
/**
|
||||
* Produces electricity in this electrical network.
|
||||
*
|
||||
* @return Rejected energy in Joules.
|
||||
*/
|
||||
public float produce(ElectricityPack electricityPack, TileEntity... ignoreTiles);
|
||||
|
||||
/**
|
||||
* Gets the total amount of electricity requested/needed in the electricity network.
|
||||
*
|
||||
* @param ignoreTiles The TileEntities to ignore during this calculation (optional).
|
||||
*/
|
||||
public ElectricityPack getRequest(TileEntity... ignoreTiles);
|
||||
|
||||
/**
|
||||
* @return The total amount of resistance of this electrical network. In Ohms.
|
||||
*/
|
||||
public float getTotalResistance();
|
||||
|
||||
/**
|
||||
* @return The lowest amount of current (amperage) that this electrical network can tolerate.
|
||||
*/
|
||||
public float getLowestCurrentCapacity();
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package universalelectricity.core.grid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this in your network class/interface if you plan to have your own network defined by
|
||||
* specific conductors and acceptors.
|
||||
*
|
||||
* @author aidancbrady
|
||||
*
|
||||
* @param <N> - the class/interface Type value in which you implement this
|
||||
* @param <C> - the class/interface Type which makes up the network's conductor Set
|
||||
* @param <A> - the class/interface Type which makes up the network's acceptor Set
|
||||
*/
|
||||
public interface IGridNetwork<N, C, A>
|
||||
{
|
||||
/**
|
||||
* Refreshes and cleans up conductor references of this network, as well as updating the
|
||||
* acceptor set.
|
||||
*/
|
||||
public void refresh();
|
||||
|
||||
/**
|
||||
* Gets the Set of conductors that make up this network.
|
||||
*
|
||||
* @return conductor set
|
||||
*/
|
||||
public Set<C> getConductors();
|
||||
|
||||
/**
|
||||
* Gets the Set of AVAILABLE acceptors in this network. Make sure this doesn't include any stray
|
||||
* acceptors which cannot accept resources.
|
||||
*
|
||||
* @return available acceptor set
|
||||
*/
|
||||
public Set<A> getAcceptors();
|
||||
|
||||
/**
|
||||
* Gets the list of possible connection directions for the provided TileEntity. Tile must be in
|
||||
* this network.
|
||||
*
|
||||
* @param tile The tile to get connections for
|
||||
* @return The list of directions that can be connected to for the provided tile
|
||||
*/
|
||||
public ArrayList<ForgeDirection> getPossibleDirections(TileEntity tile);
|
||||
|
||||
/**
|
||||
* Creates a new network that makes up the current network and the network defined in the
|
||||
* parameters. Be sure to refresh the new network inside this method.
|
||||
*
|
||||
* @param network - network to merge
|
||||
*/
|
||||
public void merge(N network);
|
||||
|
||||
/**
|
||||
* Splits a network by the conductor referenced in the parameters. It will then create and
|
||||
* refresh the new independent networks possibly created by this operation.
|
||||
*
|
||||
* @param connection
|
||||
*/
|
||||
public void split(C connection);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Some helper functions for electric items.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricItemHelper
|
||||
{
|
||||
/**
|
||||
* Recharges an electric item.
|
||||
*
|
||||
* @param joules - The joules being provided to the electric item
|
||||
* @return The total amount of joules provided by the provider.
|
||||
*/
|
||||
public static float chargeItem(ItemStack itemStack, float joules)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
return ((IItemElectric) itemStack.getItem()).recharge(itemStack, Math.min(((IItemElectric) itemStack.getItem()).getTransfer(itemStack), joules), true);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decharges an electric item.
|
||||
*
|
||||
* @param joules - The joules being withdrawn from the electric item
|
||||
* @return The total amount of joules the provider received.
|
||||
*/
|
||||
public static float dischargeItem(ItemStack itemStack, float joules)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
return ((IItemElectric) itemStack.getItem()).discharge(itemStack, Math.min(((IItemElectric) itemStack.getItem()).getMaxElectricityStored(itemStack), joules), true);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an uncharged version of the electric item. Use this if you want the crafting recipe
|
||||
* to use a charged version of the electric item instead of an empty version of the electric
|
||||
* item
|
||||
*
|
||||
* @return An electrical ItemStack with a specific charge.
|
||||
*/
|
||||
public static ItemStack getWithCharge(ItemStack itemStack, float joules)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
((IItemElectric) itemStack.getItem()).setElectricity(itemStack, joules);
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStack getWithCharge(Item item, float joules)
|
||||
{
|
||||
return getWithCharge(new ItemStack(item), joules);
|
||||
}
|
||||
|
||||
public static ItemStack getCloneWithCharge(ItemStack itemStack, float joules)
|
||||
{
|
||||
return getWithCharge(itemStack.copy(), joules);
|
||||
}
|
||||
|
||||
public static ItemStack getUncharged(ItemStack itemStack)
|
||||
{
|
||||
return getWithCharge(itemStack, 0);
|
||||
}
|
||||
|
||||
public static ItemStack getUncharged(Item item)
|
||||
{
|
||||
return getUncharged(new ItemStack(item));
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemElectric
|
||||
{
|
||||
/**
|
||||
* Adds energy to an item. Returns the quantity of energy that was accepted. This should always
|
||||
* return 0 if the item cannot be externally charged.
|
||||
*
|
||||
* @param itemStack ItemStack to be charged.
|
||||
* @param energy Maximum amount of energy to be sent into the item.
|
||||
* @param doRecharge If false, the charge will only be simulated.
|
||||
* @return Amount of energy that was accepted by the item.
|
||||
*/
|
||||
public float recharge(ItemStack itemStack, float energy, boolean doRecharge);
|
||||
|
||||
/**
|
||||
* Removes energy from an item. Returns the quantity of energy that was removed. This should
|
||||
* always return 0 if the item cannot be externally discharged.
|
||||
*
|
||||
* @param itemStack ItemStack to be discharged.
|
||||
* @param energy Maximum amount of energy to be removed from the item.
|
||||
* @param doDischarge If false, the discharge will only be simulated.
|
||||
* @return Amount of energy that was removed from the item.
|
||||
*/
|
||||
public float discharge(ItemStack itemStack, float energy, boolean doDischarge);
|
||||
|
||||
/**
|
||||
* Get the amount of energy currently stored in the item.
|
||||
*/
|
||||
public float getElectricityStored(ItemStack theItem);
|
||||
|
||||
/**
|
||||
* Get the max amount of energy that can be stored in the item.
|
||||
*/
|
||||
public float getMaxElectricityStored(ItemStack theItem);
|
||||
|
||||
/**
|
||||
* Sets the amount of energy in the ItemStack.
|
||||
*
|
||||
* @param itemStack - the ItemStack.
|
||||
* @param joules - Amount of electrical energy.
|
||||
*/
|
||||
public void setElectricity(ItemStack itemStack, float joules);
|
||||
|
||||
/**
|
||||
* @return the energy request this ItemStack demands.
|
||||
*/
|
||||
public float getTransfer(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* @return The voltage in which this item runs on.
|
||||
*/
|
||||
public float getVoltage(ItemStack itemStack);
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagFloat;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
|
||||
/** Extend from this class if your item requires electricity or to be charged. Optionally, you can
|
||||
* implement IItemElectric instead.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public abstract class ItemElectric extends Item implements IItemElectric
|
||||
{
|
||||
public ItemElectric(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(100);
|
||||
this.setNoRepair();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
|
||||
{
|
||||
String color = "";
|
||||
float joules = this.getElectricityStored(itemStack);
|
||||
|
||||
if (joules <= this.getMaxElectricityStored(itemStack) / 3)
|
||||
{
|
||||
color = "\u00a74";
|
||||
}
|
||||
else if (joules > this.getMaxElectricityStored(itemStack) * 2 / 3)
|
||||
{
|
||||
color = "\u00a72";
|
||||
}
|
||||
else
|
||||
{
|
||||
color = "\u00a76";
|
||||
}
|
||||
|
||||
list.add(color + ElectricityDisplay.getDisplayShort(joules, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplayShort(this.getMaxElectricityStored(itemStack), ElectricUnit.JOULES));
|
||||
}
|
||||
|
||||
/** Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
|
||||
* not want this to happen! */
|
||||
@Override
|
||||
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
this.setElectricity(itemStack, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float recharge(ItemStack itemStack, float energy, boolean doReceive)
|
||||
{
|
||||
float rejectedElectricity = Math.max((this.getElectricityStored(itemStack) + energy) - this.getMaxElectricityStored(itemStack), 0);
|
||||
float energyToReceive = energy - rejectedElectricity;
|
||||
|
||||
if (doReceive)
|
||||
{
|
||||
this.setElectricity(itemStack, this.getElectricityStored(itemStack) + energyToReceive);
|
||||
}
|
||||
|
||||
return energyToReceive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float discharge(ItemStack itemStack, float energy, boolean doTransfer)
|
||||
{
|
||||
float energyToTransfer = Math.min(this.getElectricityStored(itemStack), energy);
|
||||
|
||||
if (doTransfer)
|
||||
{
|
||||
this.setElectricity(itemStack, this.getElectricityStored(itemStack) - energyToTransfer);
|
||||
}
|
||||
|
||||
return energyToTransfer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVoltage(ItemStack itemStack)
|
||||
{
|
||||
return 0.120f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElectricity(ItemStack itemStack, float joules)
|
||||
{
|
||||
// Saves the frequency in the ItemStack
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
float electricityStored = Math.max(Math.min(joules, this.getMaxElectricityStored(itemStack)), 0);
|
||||
itemStack.getTagCompound().setFloat("electricity", electricityStored);
|
||||
|
||||
/** Sets the damage as a percentage to render the bar properly. */
|
||||
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxElectricityStored(itemStack)) * 100));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTransfer(ItemStack itemStack)
|
||||
{
|
||||
return this.getMaxElectricityStored(itemStack) - this.getElectricityStored(itemStack);
|
||||
}
|
||||
|
||||
/** Gets the energy stored in the item. Energy is stored using item NBT */
|
||||
@Override
|
||||
public float getElectricityStored(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
float energyStored = 0f;
|
||||
if (itemStack.getTagCompound().hasKey("electricity"))
|
||||
{
|
||||
NBTBase obj = itemStack.getTagCompound().getTag("electricity");
|
||||
if (obj instanceof NBTTagDouble)
|
||||
{
|
||||
energyStored = (float) ((NBTTagDouble) obj).data;
|
||||
}
|
||||
else if (obj instanceof NBTTagFloat)
|
||||
{
|
||||
energyStored = ((NBTTagFloat) obj).data;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the damage as a percentage to render the bar properly. */
|
||||
itemStack.setItemDamage((int) (100 - (energyStored / getMaxElectricityStored(itemStack)) * 100));
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this)));
|
||||
par3List.add(ElectricItemHelper.getWithCharge(new ItemStack(this), this.getMaxElectricityStored(new ItemStack(this))));
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
public interface IPathCallBack
|
||||
{
|
||||
/**
|
||||
* @param finder - The Pathfinder object.
|
||||
* @param currentNode - The node being iterated through.
|
||||
* @return A set of nodes connected to the currentNode. Essentially one should return a set of
|
||||
* neighboring nodes.
|
||||
*/
|
||||
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode);
|
||||
|
||||
/**
|
||||
* Called when looping through nodes.
|
||||
*
|
||||
* @param finder - The Pathfinder.
|
||||
* @param node - The node being searched.
|
||||
* @return True to stop the path finding operation.
|
||||
*/
|
||||
public boolean onSearch(Pathfinder finder, Vector3 node);
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* A class that allows flexible pathfinding for different positions. Compared to AStar pathfinding,
|
||||
* this version is faster but does not calculated the most optimal path.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class Pathfinder
|
||||
{
|
||||
/**
|
||||
* A pathfinding call back interface used to call back on paths.
|
||||
*/
|
||||
public IPathCallBack callBackCheck;
|
||||
|
||||
/**
|
||||
* A list of nodes that the pathfinder already went through.
|
||||
*/
|
||||
public Set<Vector3> closedSet;
|
||||
|
||||
/**
|
||||
* The resulted path found by the pathfinder. Could be null if no path was found.
|
||||
*/
|
||||
public Set<Vector3> results;
|
||||
|
||||
public Pathfinder(IPathCallBack callBack)
|
||||
{
|
||||
this.callBackCheck = callBack;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True on success finding, false on failure.
|
||||
*/
|
||||
public boolean findNodes(Vector3 currentNode)
|
||||
{
|
||||
this.closedSet.add(currentNode);
|
||||
|
||||
if (this.callBackCheck.onSearch(this, currentNode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Vector3 node : this.callBackCheck.getConnectedNodes(this, currentNode))
|
||||
{
|
||||
if (!this.closedSet.contains(node))
|
||||
{
|
||||
if (this.findNodes(node))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to execute the pathfinding operation.
|
||||
*/
|
||||
public Pathfinder init(Vector3 startNode)
|
||||
{
|
||||
this.findNodes(startNode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pathfinder reset()
|
||||
{
|
||||
this.closedSet = new HashSet<Vector3>();
|
||||
this.results = new HashSet<Vector3>();
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* An advanced version of pathfinding to find the shortest path between two points. Uses the A*
|
||||
* Pathfinding algorithm.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class PathfinderAStar extends Pathfinder
|
||||
{
|
||||
/**
|
||||
* A pathfinding call back interface used to call back on paths.
|
||||
*/
|
||||
public IPathCallBack callBackCheck;
|
||||
|
||||
/**
|
||||
* The set of tentative nodes to be evaluated, initially containing the start node
|
||||
*/
|
||||
public Set<Vector3> openSet;
|
||||
|
||||
/**
|
||||
* The map of navigated nodes storing the data of which position came from which in the format
|
||||
* of: X came from Y.
|
||||
*/
|
||||
public HashMap<Vector3, Vector3> navigationMap;
|
||||
|
||||
/**
|
||||
* Score values, used to determine the score for a path to evaluate how optimal the path is.
|
||||
* G-Score is the cost along the best known path while F-Score is the total cost.
|
||||
*/
|
||||
public HashMap<Vector3, Double> gScore, fScore;
|
||||
|
||||
/**
|
||||
* The node in which the pathfinder is trying to reach.
|
||||
*/
|
||||
public Vector3 goal;
|
||||
|
||||
public PathfinderAStar(IPathCallBack callBack, Vector3 goal)
|
||||
{
|
||||
super(callBack);
|
||||
this.goal = goal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean findNodes(Vector3 start)
|
||||
{
|
||||
this.openSet.add(start);
|
||||
this.gScore.put(start, 0d);
|
||||
this.fScore.put(start, this.gScore.get(start) + getHeuristicEstimatedCost(start, this.goal));
|
||||
|
||||
while (!this.openSet.isEmpty())
|
||||
{
|
||||
// Current is the node in openset having the lowest f_score[] value
|
||||
Vector3 currentNode = null;
|
||||
|
||||
double lowestFScore = 0;
|
||||
|
||||
for (Vector3 node : this.openSet)
|
||||
{
|
||||
if (currentNode == null || this.fScore.get(node) < lowestFScore)
|
||||
{
|
||||
currentNode = node;
|
||||
lowestFScore = this.fScore.get(node);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentNode == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.callBackCheck.onSearch(this, currentNode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentNode.equals(this.goal))
|
||||
{
|
||||
this.results = reconstructPath(this.navigationMap, goal);
|
||||
return true;
|
||||
}
|
||||
|
||||
this.openSet.remove(currentNode);
|
||||
this.closedSet.add(currentNode);
|
||||
|
||||
for (Vector3 neighbor : getNeighborNodes(currentNode))
|
||||
{
|
||||
double tentativeGScore = this.gScore.get(currentNode) + currentNode.distanceTo(neighbor);
|
||||
|
||||
if (this.closedSet.contains(neighbor))
|
||||
{
|
||||
if (tentativeGScore >= this.gScore.get(neighbor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.openSet.contains(neighbor) || tentativeGScore < this.gScore.get(neighbor))
|
||||
{
|
||||
this.navigationMap.put(neighbor, currentNode);
|
||||
this.gScore.put(neighbor, tentativeGScore);
|
||||
this.fScore.put(neighbor, gScore.get(neighbor) + getHeuristicEstimatedCost(neighbor, goal));
|
||||
this.openSet.add(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pathfinder reset()
|
||||
{
|
||||
this.openSet = new HashSet<Vector3>();
|
||||
this.navigationMap = new HashMap<Vector3, Vector3>();
|
||||
return super.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* A recursive function to back track and find the path in which we have analyzed.
|
||||
*/
|
||||
public Set<Vector3> reconstructPath(HashMap<Vector3, Vector3> nagivationMap, Vector3 current_node)
|
||||
{
|
||||
Set<Vector3> path = new HashSet<Vector3>();
|
||||
path.add(current_node);
|
||||
|
||||
if (nagivationMap.containsKey(current_node))
|
||||
{
|
||||
path.addAll(reconstructPath(nagivationMap, nagivationMap.get(current_node)));
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An estimated cost between two points.
|
||||
*/
|
||||
public double getHeuristicEstimatedCost(Vector3 start, Vector3 goal)
|
||||
{
|
||||
return start.distanceTo(goal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A Set of neighboring Vector3 positions.
|
||||
*/
|
||||
public Set<Vector3> getNeighborNodes(Vector3 vector)
|
||||
{
|
||||
if (this.callBackCheck != null)
|
||||
{
|
||||
return this.callBackCheck.getConnectedNodes(this, vector);
|
||||
}
|
||||
else
|
||||
{
|
||||
Set<Vector3> neighbors = new HashSet<Vector3>();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
neighbors.add(vector.clone().modifyPositionFromSide(ForgeDirection.getOrientation(i)));
|
||||
}
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.INetworkConnection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* Check if a conductor connects with another.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class PathfinderChecker extends Pathfinder
|
||||
{
|
||||
public PathfinderChecker(final World world, final INetworkConnection targetConnector, final INetworkConnection... ignoreConnector)
|
||||
{
|
||||
super(new IPathCallBack()
|
||||
{
|
||||
@Override
|
||||
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
|
||||
{
|
||||
Set<Vector3> neighbors = new HashSet<Vector3>();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
Vector3 position = currentNode.clone().modifyPositionFromSide(direction);
|
||||
TileEntity connectedBlock = position.getTileEntity(world);
|
||||
|
||||
if (connectedBlock instanceof IConductor && !Arrays.asList(ignoreConnector).contains(connectedBlock))
|
||||
{
|
||||
if (((IConductor) connectedBlock).canConnect(direction.getOpposite()))
|
||||
{
|
||||
neighbors.add(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSearch(Pathfinder finder, Vector3 node)
|
||||
{
|
||||
if (node.getTileEntity(world) == targetConnector)
|
||||
{
|
||||
finder.results.add(node);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
package universalelectricity.core.vector;
|
||||
|
||||
/**
|
||||
* Quaternion class designed to be used for the rotation of objects.
|
||||
*
|
||||
* Do not use in MC 1.6.4, subject to change!
|
||||
*
|
||||
* @author DarkGuardsman, Calclavia
|
||||
*/
|
||||
public class Quaternion implements Cloneable
|
||||
{
|
||||
public static final float TOLERANCE = 0.00001f;
|
||||
public double x, y, z, w;
|
||||
|
||||
public Quaternion()
|
||||
{
|
||||
this(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
public Quaternion(Quaternion copy)
|
||||
{
|
||||
this(copy.x, copy.y, copy.z, copy.w);
|
||||
}
|
||||
|
||||
public Quaternion(double x, double y, double z, double w)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from Euler Angles. Basically we create 3 Quaternions, one for pitch, one for yaw, one
|
||||
* for roll and multiply those together. the calculation below does the same, just shorter
|
||||
*/
|
||||
public Quaternion(float pitch, float yaw, float roll)
|
||||
{
|
||||
float p = (float) (pitch * (Math.PI / 180) / 2.0);
|
||||
float y = (float) (yaw * (Math.PI / 180) / 2.0);
|
||||
float r = (float) (roll * (Math.PI / 180) / 2.0);
|
||||
|
||||
float sinp = (float) Math.sin(p);
|
||||
float siny = (float) Math.sin(y);
|
||||
float sinr = (float) Math.sin(r);
|
||||
float cosp = (float) Math.cos(p);
|
||||
float cosy = (float) Math.cos(y);
|
||||
float cosr = (float) Math.cos(r);
|
||||
|
||||
this.x = sinr * cosp * cosy - cosr * sinp * siny;
|
||||
this.y = cosr * sinp * cosy + sinr * cosp * siny;
|
||||
this.z = cosr * cosp * siny - sinr * sinp * cosy;
|
||||
this.w = cosr * cosp * cosy + sinr * sinp * siny;
|
||||
|
||||
this.normalize();
|
||||
}
|
||||
|
||||
public Quaternion(Vector3 vector, double w)
|
||||
{
|
||||
this(vector.x, vector.y, vector.z, w);
|
||||
}
|
||||
|
||||
public static Quaternion IDENTITY()
|
||||
{
|
||||
return new Quaternion();
|
||||
}
|
||||
|
||||
public Quaternion set(Quaternion quaternion)
|
||||
{
|
||||
this.w = quaternion.w;
|
||||
this.x = quaternion.x;
|
||||
this.y = quaternion.y;
|
||||
this.z = quaternion.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Quaternion set(double x, double y, double z, double w)
|
||||
{
|
||||
return this.set(new Quaternion(x, y, z, w));
|
||||
}
|
||||
|
||||
public Quaternion normalize()
|
||||
{
|
||||
double magnitude = this.magnitude();
|
||||
this.x /= magnitude;
|
||||
this.y /= magnitude;
|
||||
this.z /= magnitude;
|
||||
this.w /= magnitude;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double magnitude()
|
||||
{
|
||||
return Math.sqrt(this.magnitudeSquared());
|
||||
}
|
||||
|
||||
public double magnitudeSquared()
|
||||
{
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
|
||||
}
|
||||
|
||||
public Quaternion inverse()
|
||||
{
|
||||
double d = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
|
||||
return new Quaternion(this.x / d, -this.y / d, -this.z / d, -this.w / d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the conjugate of this Quaternion
|
||||
*/
|
||||
public Quaternion getConjugate()
|
||||
{
|
||||
return this.clone().conjugate();
|
||||
}
|
||||
|
||||
public Quaternion conjugate()
|
||||
{
|
||||
this.y = -this.y;
|
||||
this.z = -this.z;
|
||||
this.w = -this.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let the current quaternion be "a". Multiplying the a with b applies the rotation a to b.
|
||||
*/
|
||||
public Quaternion getMultiply(Quaternion b)
|
||||
{
|
||||
return this.clone().multiply(b);
|
||||
}
|
||||
|
||||
public Quaternion multiply(Quaternion b)
|
||||
{
|
||||
Quaternion a = this;
|
||||
double newX = a.x * b.x - a.y * b.y - a.z * b.z - a.w * b.w;
|
||||
double newY = a.x * b.y + a.y * b.x + a.z * b.w - a.w * b.z;
|
||||
double newZ = a.x * b.z - a.y * b.w + a.z * b.x + a.w * b.y;
|
||||
double newW = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
|
||||
this.set(newX, newY, newZ, newW);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Quaternion divide(Quaternion b)
|
||||
{
|
||||
Quaternion a = this;
|
||||
return a.inverse().multiply(b);
|
||||
}
|
||||
|
||||
/** Multi a vector against this in other words applying rotation */
|
||||
public Vector3 multi(Vector3 vec)
|
||||
{
|
||||
Vector3 vn = vec.clone();
|
||||
|
||||
Quaternion vecQuat = new Quaternion(0, 0, 0, 1), resQuat;
|
||||
vecQuat.x = (float) vn.x;
|
||||
vecQuat.y = (float) vn.y;
|
||||
vecQuat.z = (float) vn.z;
|
||||
vecQuat.w = 0.0f;
|
||||
|
||||
resQuat = vecQuat.multiply(this.getConjugate());
|
||||
resQuat = this.multiply(resQuat);
|
||||
|
||||
return new Vector3(resQuat.x, resQuat.y, resQuat.z);
|
||||
}
|
||||
|
||||
public static Quaternion fromAxis(Vector3 vector, double angle)
|
||||
{
|
||||
angle *= 0.5f;
|
||||
Vector3 vn = vector.clone().normalize();
|
||||
float sinAngle = (float) Math.sin(angle);
|
||||
return new Quaternion(vn.x * sinAngle, vn.y * sinAngle, vn.z * sinAngle, Math.cos(angle));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to Matrix public Matrix4 getMatrix() { float x2 = (float) (x * x); float y2 = (float)
|
||||
* (y * y); float z2 = (float) (z * z); float xy = (float) (x * y); float xz = (float) (x * z);
|
||||
* float yz = (float) (y * z); float wx = (float) (w * x); float wy = (float) (w * y); float wz
|
||||
* = (float) (w * z);
|
||||
*
|
||||
* // This calculation would be a lot more complicated for non-unit length quaternions // Note:
|
||||
* The constructor of Matrix4 expects the Matrix in column-major format like expected // by //
|
||||
* OpenGL return new Matrix4(1.0f - 2.0f * (y2 + z2), 2.0f * (xy - wz), 2.0f * (xz + wy), 0.0f,
|
||||
* 2.0f * (xy + wz), 1.0f - 2.0f * (x2 + z2), 2.0f * (yz - wx), 0.0f, 2.0f * (xz - wy), 2.0f *
|
||||
* (yz + wx), 1.0f - 2.0f * (x2 + y2), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convert to Axis/Angles
|
||||
*
|
||||
* @param axis - The axis of rotation
|
||||
* @param angle - The angle of rotation
|
||||
*/
|
||||
public void getAxisAngle(Vector3 axis, float angle)
|
||||
{
|
||||
float scale = (float) axis.getMagnitude();
|
||||
this.x = this.x / scale;
|
||||
this.y = this.y / scale;
|
||||
this.z = this.z / scale;
|
||||
angle = (float) (Math.acos(this.w) * 2.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Quaternion clone()
|
||||
{
|
||||
return new Quaternion(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Quaternion [" + x + ", " + y + ", " + z + ", " + w + "]";
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package universalelectricity.core.vector;
|
||||
|
||||
/**
|
||||
* Vector2 Class is used for defining objects in a 2D space.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
||||
public class Vector2 implements Cloneable
|
||||
{
|
||||
public double x;
|
||||
public double y;
|
||||
|
||||
public Vector2()
|
||||
{
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Vector2(double x, double y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer floor value.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int intX()
|
||||
{
|
||||
return (int) Math.floor(this.x);
|
||||
}
|
||||
|
||||
public int intY()
|
||||
{
|
||||
return (int) Math.floor(this.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a new copy of this Vector. Prevents variable referencing problems.
|
||||
*/
|
||||
@Override
|
||||
public Vector2 clone()
|
||||
{
|
||||
return new Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
public static double distance(Vector2 point1, Vector2 point2)
|
||||
{
|
||||
double xDifference = point1.x - point2.x;
|
||||
double yDiference = point1.y - point2.y;
|
||||
return Math.sqrt(xDifference * xDifference + yDiference * yDiference);
|
||||
}
|
||||
|
||||
public static double slope(Vector2 point1, Vector2 point2)
|
||||
{
|
||||
double xDifference = point1.x - point2.x;
|
||||
double yDiference = point1.y - point2.y;
|
||||
return yDiference / xDifference;
|
||||
}
|
||||
|
||||
public double distanceTo(Vector2 target)
|
||||
{
|
||||
double xDifference = this.x - target.x;
|
||||
double yDifference = this.y - target.y;
|
||||
return Math.sqrt(xDifference * xDifference + yDifference * yDifference);
|
||||
}
|
||||
|
||||
public Vector2 add(Vector2 par1)
|
||||
{
|
||||
this.x += par1.x;
|
||||
this.y += par1.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 add(double par1)
|
||||
{
|
||||
this.x += par1;
|
||||
this.y += par1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 invert()
|
||||
{
|
||||
this.multiply(-1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 multiply(double amount)
|
||||
{
|
||||
this.x *= amount;
|
||||
this.y *= amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 round()
|
||||
{
|
||||
return new Vector2(Math.round(this.x), Math.round(this.y));
|
||||
}
|
||||
|
||||
public Vector2 ceil()
|
||||
{
|
||||
return new Vector2(Math.ceil(this.x), Math.ceil(this.y));
|
||||
}
|
||||
|
||||
public Vector2 floor()
|
||||
{
|
||||
return new Vector2(Math.floor(this.x), Math.floor(this.y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return ("X:" + this.x + "Y:" + this.y).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o instanceof Vector2)
|
||||
{
|
||||
Vector2 vector = (Vector2) o;
|
||||
return this.x == vector.x && this.y == vector.y;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Vector2 [" + this.x + "," + this.y + "]";
|
||||
}
|
||||
}
|
|
@ -1,849 +0,0 @@
|
|||
package universalelectricity.core.vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Vector3 Class is used for defining objects in a 3D space.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
||||
public class Vector3 implements Cloneable
|
||||
{
|
||||
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
||||
public Vector3(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3()
|
||||
{
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Vector3(Vector3 vector)
|
||||
{
|
||||
this(vector.x, vector.y, vector.z);
|
||||
}
|
||||
|
||||
public Vector3(double amount)
|
||||
{
|
||||
this(amount, amount, amount);
|
||||
}
|
||||
|
||||
public Vector3(Entity par1)
|
||||
{
|
||||
this(par1.posX, par1.posY, par1.posZ);
|
||||
}
|
||||
|
||||
public Vector3(TileEntity par1)
|
||||
{
|
||||
this(par1.xCoord, par1.yCoord, par1.zCoord);
|
||||
}
|
||||
|
||||
public Vector3(Vec3 par1)
|
||||
{
|
||||
this(par1.xCoord, par1.yCoord, par1.zCoord);
|
||||
|
||||
}
|
||||
|
||||
public Vector3(MovingObjectPosition par1)
|
||||
{
|
||||
this(par1.blockX, par1.blockY, par1.blockZ);
|
||||
}
|
||||
|
||||
public Vector3(ChunkCoordinates par1)
|
||||
{
|
||||
this(par1.posX, par1.posY, par1.posZ);
|
||||
}
|
||||
|
||||
public Vector3(ForgeDirection direction)
|
||||
{
|
||||
this(direction.offsetX, direction.offsetY, direction.offsetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a Vector3 from an NBT compound.
|
||||
*/
|
||||
public Vector3(NBTTagCompound nbt)
|
||||
{
|
||||
this(nbt.getDouble("x"), nbt.getDouble("y"), nbt.getDouble("z"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Vector3 based on the rotationYaw and rotationPitch.
|
||||
*
|
||||
* @param rotationYaw - Degree
|
||||
* @param rotationPitch- Degree
|
||||
*/
|
||||
public Vector3(float rotationYaw, float rotationPitch)
|
||||
{
|
||||
this(Math.cos(Math.toRadians(rotationYaw + 90)), Math.sin(Math.toRadians(-rotationPitch)), Math.sin(Math.toRadians(rotationYaw + 90)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the coordinates as integers, ideal for block placement.
|
||||
*/
|
||||
public int intX()
|
||||
{
|
||||
return (int) Math.floor(this.x);
|
||||
}
|
||||
|
||||
public int intY()
|
||||
{
|
||||
return (int) Math.floor(this.y);
|
||||
}
|
||||
|
||||
public int intZ()
|
||||
{
|
||||
return (int) Math.floor(this.z);
|
||||
}
|
||||
|
||||
public float floatX()
|
||||
{
|
||||
return (float) this.x;
|
||||
}
|
||||
|
||||
public float floatY()
|
||||
{
|
||||
return (float) this.y;
|
||||
}
|
||||
|
||||
public float floatZ()
|
||||
{
|
||||
return (float) this.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a new copy of this Vector. Prevents variable referencing problems.
|
||||
*/
|
||||
@Override
|
||||
public Vector3 clone()
|
||||
{
|
||||
return new Vector3(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Easy block access functions.
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public int getBlockID(IBlockAccess world)
|
||||
{
|
||||
return world.getBlockId(this.intX(), this.intY(), this.intZ());
|
||||
}
|
||||
|
||||
public int getBlockMetadata(IBlockAccess world)
|
||||
{
|
||||
return world.getBlockMetadata(this.intX(), this.intY(), this.intZ());
|
||||
}
|
||||
|
||||
public TileEntity getTileEntity(IBlockAccess world)
|
||||
{
|
||||
return world.getBlockTileEntity(this.intX(), this.intY(), this.intZ());
|
||||
}
|
||||
|
||||
public boolean setBlock(World world, int id, int metadata, int notify)
|
||||
{
|
||||
return world.setBlock(this.intX(), this.intY(), this.intZ(), id, metadata, notify);
|
||||
}
|
||||
|
||||
public boolean setBlock(World world, int id, int metadata)
|
||||
{
|
||||
return this.setBlock(world, id, metadata, 3);
|
||||
}
|
||||
|
||||
public boolean setBlock(World world, int id)
|
||||
{
|
||||
return this.setBlock(world, id, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------- CONVERSION FUNCTIONS ----------------------------
|
||||
*/
|
||||
/**
|
||||
* Converts this Vector3 into a Vector2 by dropping the Y axis.
|
||||
*/
|
||||
public Vector2 toVector2()
|
||||
{
|
||||
return new Vector2(this.x, this.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this vector three into a Minecraft Vec3 object
|
||||
*/
|
||||
public Vec3 toVec3()
|
||||
{
|
||||
return Vec3.createVectorHelper(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Vector3 into a ForgeDirection.
|
||||
*/
|
||||
public ForgeDirection toForgeDirection()
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (this.x == direction.offsetX && this.y == direction.offsetY && this.z == direction.offsetZ)
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public double getMagnitude()
|
||||
{
|
||||
return Math.sqrt(this.getMagnitudeSquared());
|
||||
}
|
||||
|
||||
public double getMagnitudeSquared()
|
||||
{
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
public Vector3 normalize()
|
||||
{
|
||||
double d = this.getMagnitude();
|
||||
|
||||
if (d != 0)
|
||||
{
|
||||
this.scale(1 / d);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance between two vectors
|
||||
*
|
||||
* @return The distance
|
||||
*/
|
||||
public static double distance(Vector3 vec1, Vector3 vec2)
|
||||
{
|
||||
return vec1.distance(vec2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public double distanceTo(Vector3 vector3)
|
||||
{
|
||||
return this.distance(vector3);
|
||||
}
|
||||
|
||||
public double distance(Vector3 compare)
|
||||
{
|
||||
Vector3 difference = this.clone().difference(compare);
|
||||
return difference.getMagnitude();
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies the vector by negative one.
|
||||
*/
|
||||
public Vector3 invert()
|
||||
{
|
||||
this.scale(-1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 translate(Vector3 par1)
|
||||
{
|
||||
this.x += par1.x;
|
||||
this.y += par1.y;
|
||||
this.z += par1.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 translate(double par1)
|
||||
{
|
||||
this.x += par1;
|
||||
this.y += par1;
|
||||
this.z += par1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Vector3 translate(Vector3 translate, Vector3 par1)
|
||||
{
|
||||
translate.x += par1.x;
|
||||
translate.y += par1.y;
|
||||
translate.z += par1.z;
|
||||
return translate;
|
||||
}
|
||||
|
||||
public static Vector3 translate(Vector3 translate, double par1)
|
||||
{
|
||||
translate.x += par1;
|
||||
translate.y += par1;
|
||||
translate.z += par1;
|
||||
return translate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Vector3 add(Vector3 amount)
|
||||
{
|
||||
return translate(amount);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Vector3 add(double amount)
|
||||
{
|
||||
return translate(amount);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Vector3 subtract(Vector3 amount)
|
||||
{
|
||||
return this.translate(amount.clone().invert());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Vector3 subtract(double amount)
|
||||
{
|
||||
return this.translate(-amount);
|
||||
}
|
||||
|
||||
public Vector3 difference(Vector3 amount)
|
||||
{
|
||||
return this.translate(amount.clone().invert());
|
||||
}
|
||||
|
||||
public Vector3 difference(double amount)
|
||||
{
|
||||
return this.translate(-amount);
|
||||
}
|
||||
|
||||
public Vector3 scale(double amount)
|
||||
{
|
||||
this.x *= amount;
|
||||
this.y *= amount;
|
||||
this.z *= amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 scale(Vector3 amount)
|
||||
{
|
||||
this.x *= amount.x;
|
||||
this.y *= amount.y;
|
||||
this.z *= amount.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Vector3 scale(Vector3 vec, double amount)
|
||||
{
|
||||
return vec.scale(amount);
|
||||
}
|
||||
|
||||
public static Vector3 scale(Vector3 vec, Vector3 amount)
|
||||
{
|
||||
return vec.scale(amount);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Vector3 multiply(double amount)
|
||||
{
|
||||
return this.scale(amount);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Vector3 multiply(Vector3 amount)
|
||||
{
|
||||
return this.scale(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static versions of a lot of functions
|
||||
*/
|
||||
@Deprecated
|
||||
public static Vector3 subtract(Vector3 par1, Vector3 par2)
|
||||
{
|
||||
return new Vector3(par1.x - par2.x, par1.y - par2.y, par1.z - par2.z);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Vector3 add(Vector3 par1, Vector3 par2)
|
||||
{
|
||||
return new Vector3(par1.x + par2.x, par1.y + par2.y, par1.z + par2.z);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Vector3 add(Vector3 par1, double par2)
|
||||
{
|
||||
return new Vector3(par1.x + par2, par1.y + par2, par1.z + par2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Vector3 multiply(Vector3 vec1, Vector3 vec2)
|
||||
{
|
||||
return new Vector3(vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Vector3 multiply(Vector3 vec1, double vec2)
|
||||
{
|
||||
return new Vector3(vec1.x * vec2, vec1.y * vec2, vec1.z * vec2);
|
||||
}
|
||||
|
||||
public Vector3 round()
|
||||
{
|
||||
return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z));
|
||||
}
|
||||
|
||||
public Vector3 ceil()
|
||||
{
|
||||
return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
|
||||
}
|
||||
|
||||
public Vector3 floor()
|
||||
{
|
||||
return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
|
||||
}
|
||||
|
||||
public Vector3 toRound()
|
||||
{
|
||||
this.x = Math.round(this.x);
|
||||
this.y = Math.round(this.y);
|
||||
this.z = Math.round(this.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 toCeil()
|
||||
{
|
||||
this.x = Math.ceil(this.x);
|
||||
this.y = Math.ceil(this.y);
|
||||
this.z = Math.ceil(this.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 toFloor()
|
||||
{
|
||||
this.x = Math.floor(this.x);
|
||||
this.y = Math.floor(this.y);
|
||||
this.z = Math.floor(this.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all entities inside of this position in block space.
|
||||
*/
|
||||
public List<Entity> getEntitiesWithin(World worldObj, Class<? extends Entity> par1Class)
|
||||
{
|
||||
return worldObj.getEntitiesWithinAABB(par1Class, AxisAlignedBB.getBoundingBox(this.intX(), this.intY(), this.intZ(), this.intX() + 1, this.intY() + 1, this.intZ() + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a position relative to a position's side
|
||||
*
|
||||
* @param position - The position
|
||||
* @param side - The side. 0-5
|
||||
* @return The position relative to the original position's side
|
||||
*/
|
||||
public Vector3 modifyPositionFromSide(ForgeDirection side, double amount)
|
||||
{
|
||||
return this.translate(new Vector3(side).scale(amount));
|
||||
}
|
||||
|
||||
public Vector3 modifyPositionFromSide(ForgeDirection side)
|
||||
{
|
||||
this.modifyPositionFromSide(side, 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross product functions
|
||||
*
|
||||
* @return The cross product between this vector and another.
|
||||
*/
|
||||
public Vector3 toCrossProduct(Vector3 compare)
|
||||
{
|
||||
double newX = this.y * compare.z - this.z * compare.y;
|
||||
double newY = this.z * compare.x - this.x * compare.z;
|
||||
double newZ = this.x * compare.y - this.y * compare.x;
|
||||
this.x = newX;
|
||||
this.y = newY;
|
||||
this.z = newZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 crossProduct(Vector3 compare)
|
||||
{
|
||||
return this.clone().toCrossProduct(compare);
|
||||
}
|
||||
|
||||
public Vector3 xCrossProduct()
|
||||
{
|
||||
return new Vector3(0.0D, this.z, -this.y);
|
||||
}
|
||||
|
||||
public Vector3 zCrossProduct()
|
||||
{
|
||||
return new Vector3(-this.y, this.x, 0.0D);
|
||||
}
|
||||
|
||||
public double dotProduct(Vector3 vec2)
|
||||
{
|
||||
return this.x * vec2.x + this.y * vec2.y + this.z * vec2.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The perpendicular vector.
|
||||
*/
|
||||
public Vector3 getPerpendicular()
|
||||
{
|
||||
if (this.z == 0.0F)
|
||||
{
|
||||
return this.zCrossProduct();
|
||||
}
|
||||
|
||||
return this.xCrossProduct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if this Vector3 is zero.
|
||||
*/
|
||||
public boolean isZero()
|
||||
{
|
||||
return (this.x == 0) && (this.y == 0) && (this.z == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate by a this vector around an axis.
|
||||
*
|
||||
* @return The new Vector3 rotation.
|
||||
*/
|
||||
public Vector3 rotate(float angle, Vector3 axis)
|
||||
{
|
||||
return translateMatrix(getRotationMatrix(angle, axis), this.clone());
|
||||
}
|
||||
|
||||
public double[] getRotationMatrix(float angle)
|
||||
{
|
||||
double[] matrix = new double[16];
|
||||
Vector3 axis = this.clone().normalize();
|
||||
double x = axis.x;
|
||||
double y = axis.y;
|
||||
double z = axis.z;
|
||||
angle *= 0.0174532925D;
|
||||
float cos = (float) Math.cos(angle);
|
||||
float ocos = 1.0F - cos;
|
||||
float sin = (float) Math.sin(angle);
|
||||
matrix[0] = (x * x * ocos + cos);
|
||||
matrix[1] = (y * x * ocos + z * sin);
|
||||
matrix[2] = (x * z * ocos - y * sin);
|
||||
matrix[4] = (x * y * ocos - z * sin);
|
||||
matrix[5] = (y * y * ocos + cos);
|
||||
matrix[6] = (y * z * ocos + x * sin);
|
||||
matrix[8] = (x * z * ocos + y * sin);
|
||||
matrix[9] = (y * z * ocos - x * sin);
|
||||
matrix[10] = (z * z * ocos + cos);
|
||||
matrix[15] = 1.0F;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public static Vector3 translateMatrix(double[] matrix, Vector3 translation)
|
||||
{
|
||||
double x = translation.x * matrix[0] + translation.y * matrix[1] + translation.z * matrix[2] + matrix[3];
|
||||
double y = translation.x * matrix[4] + translation.y * matrix[5] + translation.z * matrix[6] + matrix[7];
|
||||
double z = translation.x * matrix[8] + translation.y * matrix[9] + translation.z * matrix[10] + matrix[11];
|
||||
translation.x = x;
|
||||
translation.y = y;
|
||||
translation.z = z;
|
||||
return translation;
|
||||
}
|
||||
|
||||
public static double[] getRotationMatrix(float angle, Vector3 axis)
|
||||
{
|
||||
return axis.getRotationMatrix(angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates this Vector by a yaw, pitch and roll value.
|
||||
*/
|
||||
public void rotate(double yaw, double pitch, double roll)
|
||||
{
|
||||
double yawRadians = Math.toRadians(yaw);
|
||||
double pitchRadians = Math.toRadians(pitch);
|
||||
double rollRadians = Math.toRadians(roll);
|
||||
|
||||
double x = this.x;
|
||||
double y = this.y;
|
||||
double z = this.z;
|
||||
|
||||
this.x = x * Math.cos(yawRadians) * Math.cos(pitchRadians) + z * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) - Math.sin(yawRadians) * Math.cos(rollRadians)) + y * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) + Math.sin(yawRadians) * Math.sin(rollRadians));
|
||||
this.z = x * Math.sin(yawRadians) * Math.cos(pitchRadians) + z * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) + Math.cos(yawRadians) * Math.cos(rollRadians)) + y * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) - Math.cos(yawRadians) * Math.sin(rollRadians));
|
||||
this.y = -x * Math.sin(pitchRadians) + z * Math.cos(pitchRadians) * Math.sin(rollRadians) + y * Math.cos(pitchRadians) * Math.cos(rollRadians);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point by a yaw and pitch around the anchor 0,0 by a specific angle.
|
||||
*/
|
||||
public void rotate(double yaw, double pitch)
|
||||
{
|
||||
this.rotate(yaw, pitch, 0);
|
||||
}
|
||||
|
||||
public void rotate(double yaw)
|
||||
{
|
||||
double yawRadians = Math.toRadians(yaw);
|
||||
|
||||
double x = this.x;
|
||||
double z = this.z;
|
||||
|
||||
if (yaw != 0)
|
||||
{
|
||||
this.x = x * Math.cos(yawRadians) - z * Math.sin(yawRadians);
|
||||
this.z = x * Math.sin(yawRadians) + z * Math.cos(yawRadians);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the delta look position based on the rotation yaw and pitch. Minecraft coordinates are
|
||||
* messed up. Y and Z are flipped. Yaw is displaced by 90 degrees. Pitch is inversed.
|
||||
*
|
||||
* @param rotationYaw
|
||||
* @param rotationPitch
|
||||
*/
|
||||
public static Vector3 getDeltaPositionFromRotation(float rotationYaw, float rotationPitch)
|
||||
{
|
||||
return new Vector3(rotationYaw, rotationPitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the angle between this vector and another vector.
|
||||
*
|
||||
* @return Angle in degrees
|
||||
*/
|
||||
public double getAngle(Vector3 vec2)
|
||||
{
|
||||
return anglePreNorm(this.clone().normalize(), vec2.clone().normalize());
|
||||
}
|
||||
|
||||
public static double getAngle(Vector3 vec1, Vector3 vec2)
|
||||
{
|
||||
return vec1.getAngle(vec2);
|
||||
}
|
||||
|
||||
public double anglePreNorm(Vector3 vec2)
|
||||
{
|
||||
return Math.acos(this.dotProduct(vec2));
|
||||
}
|
||||
|
||||
public static double anglePreNorm(Vector3 vec1, Vector3 vec2)
|
||||
{
|
||||
return Math.acos(vec1.clone().dotProduct(vec2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a Vector3 from an NBT compound.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Vector3 readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
return new Vector3(nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this Vector3 to disk
|
||||
*
|
||||
* @param prefix - The prefix of this save. Use some unique string.
|
||||
* @param nbt - The NBT compound object to save the data in
|
||||
*/
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setDouble("x", this.x);
|
||||
nbt.setDouble("y", this.y);
|
||||
nbt.setDouble("z", this.z);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public static Vector3 UP()
|
||||
{
|
||||
return new Vector3(0, 1, 0);
|
||||
}
|
||||
|
||||
public static Vector3 DOWN()
|
||||
{
|
||||
return new Vector3(0, -1, 0);
|
||||
}
|
||||
|
||||
public static Vector3 NORTH()
|
||||
{
|
||||
return new Vector3(0, 0, -1);
|
||||
}
|
||||
|
||||
public static Vector3 SOUTH()
|
||||
{
|
||||
return new Vector3(0, 0, 1);
|
||||
}
|
||||
|
||||
public static Vector3 WEST()
|
||||
{
|
||||
return new Vector3(-1, 0, 0);
|
||||
}
|
||||
|
||||
public static Vector3 EAST()
|
||||
{
|
||||
return new Vector3(1, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* RayTrace Code, retrieved from MachineMuse.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public MovingObjectPosition rayTrace(World world, float rotationYaw, float rotationPitch, boolean collisionFlag, double reachDistance)
|
||||
{
|
||||
// Somehow this destroys the playerPosition vector -.-
|
||||
MovingObjectPosition pickedBlock = this.rayTraceBlocks(world, rotationYaw, rotationPitch, collisionFlag, reachDistance);
|
||||
MovingObjectPosition pickedEntity = this.rayTraceEntities(world, rotationYaw, rotationPitch, reachDistance);
|
||||
|
||||
if (pickedBlock == null)
|
||||
{
|
||||
return pickedEntity;
|
||||
}
|
||||
else if (pickedEntity == null)
|
||||
{
|
||||
return pickedBlock;
|
||||
}
|
||||
else
|
||||
{
|
||||
double dBlock = this.distance(new Vector3(pickedBlock.hitVec));
|
||||
double dEntity = this.distance(new Vector3(pickedEntity.hitVec));
|
||||
|
||||
if (dEntity < dBlock)
|
||||
{
|
||||
return pickedEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pickedBlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MovingObjectPosition rayTraceBlocks(World world, float rotationYaw, float rotationPitch, boolean collisionFlag, double reachDistance)
|
||||
{
|
||||
Vector3 lookVector = this.getDeltaPositionFromRotation(rotationYaw, rotationPitch);
|
||||
Vector3 reachPoint = this.clone().translate(lookVector.clone().scale(reachDistance));
|
||||
return world.rayTraceBlocks_do_do(this.toVec3(), reachPoint.toVec3(), collisionFlag, !collisionFlag);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MovingObjectPosition rayTraceEntities(World world, float rotationYaw, float rotationPitch, boolean collisionFlag, double reachDistance)
|
||||
{
|
||||
return this.rayTraceEntities(world, rotationYaw, rotationPitch, reachDistance);
|
||||
}
|
||||
|
||||
public MovingObjectPosition rayTraceEntities(World world, float rotationYaw, float rotationPitch, double reachDistance)
|
||||
{
|
||||
return this.rayTraceEntities(world, getDeltaPositionFromRotation(rotationYaw, rotationPitch).scale(reachDistance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Does an entity raytrace.
|
||||
*
|
||||
* @param world - The world object.
|
||||
* @param target - The rotation in terms of Vector3. Convert using
|
||||
* getDeltaPositionFromRotation()
|
||||
* @return The target hit.
|
||||
*/
|
||||
public MovingObjectPosition rayTraceEntities(World world, Vector3 target)
|
||||
{
|
||||
MovingObjectPosition pickedEntity = null;
|
||||
Vec3 startingPosition = this.toVec3();
|
||||
Vec3 look = target.toVec3();
|
||||
double reachDistance = this.distance(target);
|
||||
Vec3 reachPoint = Vec3.createVectorHelper(startingPosition.xCoord + look.xCoord * reachDistance, startingPosition.yCoord + look.yCoord * reachDistance, startingPosition.zCoord + look.zCoord * reachDistance);
|
||||
|
||||
double checkBorder = 1.1 * reachDistance;
|
||||
AxisAlignedBB boxToScan = AxisAlignedBB.getAABBPool().getAABB(-checkBorder, -checkBorder, -checkBorder, checkBorder, checkBorder, checkBorder).offset(this.x, this.y, this.z);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Entity> entitiesHit = world.getEntitiesWithinAABBExcludingEntity(null, boxToScan);
|
||||
double closestEntity = reachDistance;
|
||||
|
||||
if (entitiesHit == null || entitiesHit.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (Entity entityHit : entitiesHit)
|
||||
{
|
||||
if (entityHit != null && entityHit.canBeCollidedWith() && entityHit.boundingBox != null)
|
||||
{
|
||||
float border = entityHit.getCollisionBorderSize();
|
||||
AxisAlignedBB aabb = entityHit.boundingBox.expand(border, border, border);
|
||||
MovingObjectPosition hitMOP = aabb.calculateIntercept(startingPosition, reachPoint);
|
||||
|
||||
if (hitMOP != null)
|
||||
{
|
||||
if (aabb.isVecInside(startingPosition))
|
||||
{
|
||||
if (0.0D < closestEntity || closestEntity == 0.0D)
|
||||
{
|
||||
pickedEntity = new MovingObjectPosition(entityHit);
|
||||
if (pickedEntity != null)
|
||||
{
|
||||
pickedEntity.hitVec = hitMOP.hitVec;
|
||||
closestEntity = 0.0D;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double distance = startingPosition.distanceTo(hitMOP.hitVec);
|
||||
|
||||
if (distance < closestEntity || closestEntity == 0.0D)
|
||||
{
|
||||
pickedEntity = new MovingObjectPosition(entityHit);
|
||||
pickedEntity.hitVec = hitMOP.hitVec;
|
||||
closestEntity = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pickedEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return ("X:" + this.x + "Y:" + this.y + "Z:" + this.z).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o instanceof Vector3)
|
||||
{
|
||||
Vector3 vector3 = (Vector3) o;
|
||||
return this.x == vector3.x && this.y == vector3.y && this.z == vector3.z;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package universalelectricity.core.vector;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
|
||||
public class VectorHelper
|
||||
{
|
||||
public static final int[][] RELATIVE_MATRIX = { { 3, 2, 1, 0, 5, 4 }, { 4, 5, 0, 1, 2, 3 }, { 0, 1, 3, 2, 4, 5 }, { 0, 1, 2, 3, 5, 4 }, { 0, 1, 5, 4, 3, 2 }, { 0, 1, 4, 5, 2, 3 } };
|
||||
|
||||
/**
|
||||
* Finds the direction relative to a base direction.
|
||||
*
|
||||
* @param front - The direction in which this block is facing/front. Use a number between 0 and
|
||||
* 5. Default is 3.
|
||||
* @param side - The side you are trying to find. A number between 0 and 5.
|
||||
* @return The side relative to the facing direction.
|
||||
*/
|
||||
public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side)
|
||||
{
|
||||
if (front != ForgeDirection.UNKNOWN && side != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
return ForgeDirection.getOrientation(RELATIVE_MATRIX[front.ordinal()][side.ordinal()]);
|
||||
}
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connector unit based on the given side.
|
||||
*/
|
||||
public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side)
|
||||
{
|
||||
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world, position, side);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH)))
|
||||
{
|
||||
return tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side)
|
||||
{
|
||||
return position.clone().modifyPositionFromSide(side).getTileEntity(world);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import net.minecraft.util.DamageSource;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class CustomDamageSource extends DamageSource
|
||||
{
|
||||
/**
|
||||
* Use this damage source for all types of electrical attacks.
|
||||
*/
|
||||
public static final CustomDamageSource electrocution = ((CustomDamageSource) new CustomDamageSource("electrocution").setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!");
|
||||
|
||||
public CustomDamageSource(String damageType)
|
||||
{
|
||||
super(damageType);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CustomDamageSource setDeathMessage(String deathMessage)
|
||||
{
|
||||
LanguageRegistry.instance().addStringLocalization("death.attack." + this.damageType, deathMessage);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageSource setDamageBypassesArmor()
|
||||
{
|
||||
return super.setDamageBypassesArmor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageSource setDamageAllowedInCreativeMode()
|
||||
{
|
||||
return super.setDamageAllowedInCreativeMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageSource setFireDamage()
|
||||
{
|
||||
return super.setFireDamage();
|
||||
}
|
||||
}
|
|
@ -1,192 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* This class is used to replace recipes that are already added in the existing recipe pool for
|
||||
* crafting and smelting. All recipe functions take account of the Forge Ore Dictionary. It also
|
||||
* includes some recipe helper functions to shorten some of your function calls.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class RecipeHelper
|
||||
{
|
||||
public static List<IRecipe> getRecipesByOutput(ItemStack output)
|
||||
{
|
||||
List<IRecipe> list = new ArrayList<IRecipe>();
|
||||
|
||||
for (Object obj : CraftingManager.getInstance().getRecipeList())
|
||||
{
|
||||
if (obj instanceof IRecipe)
|
||||
{
|
||||
if (((IRecipe) obj).getRecipeOutput() == output)
|
||||
{
|
||||
list.add((IRecipe) obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a recipe with a new IRecipe.
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe)
|
||||
{
|
||||
for (Object obj : CraftingManager.getInstance().getRecipeList())
|
||||
{
|
||||
if (obj instanceof IRecipe)
|
||||
{
|
||||
if (((IRecipe) obj).equals(recipe) || obj == recipe)
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList().remove(obj);
|
||||
CraftingManager.getInstance().getRecipeList().add(newRecipe);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a recipe with the resulting ItemStack with a new IRecipe.
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe)
|
||||
{
|
||||
if (removeRecipe(recipe))
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList().add(newRecipe);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a recipe by its IRecipe class.
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
public static boolean removeRecipe(IRecipe recipe)
|
||||
{
|
||||
for (Object obj : CraftingManager.getInstance().getRecipeList())
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof IRecipe)
|
||||
{
|
||||
if (((IRecipe) obj).equals(recipe) || obj == recipe)
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList().remove(obj);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the first recipe found by its output.
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
public static boolean removeRecipe(ItemStack stack)
|
||||
{
|
||||
for (Object obj : CraftingManager.getInstance().getRecipeList())
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof IRecipe)
|
||||
{
|
||||
if (((IRecipe) obj).getRecipeOutput() != null)
|
||||
{
|
||||
if (((IRecipe) obj).getRecipeOutput().isItemEqual(stack))
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList().remove(obj);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all recipes found that has this output. You may use this with Forge Ore Dictionary to
|
||||
* remove all recipes with the FoD ID.
|
||||
*
|
||||
* @return True if successful
|
||||
*/
|
||||
public static boolean removeRecipes(ItemStack... itemStacks)
|
||||
{
|
||||
boolean didRemove = false;
|
||||
|
||||
for (Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext();)
|
||||
{
|
||||
Object obj = itr.next();
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof IRecipe)
|
||||
{
|
||||
if (((IRecipe) obj).getRecipeOutput() != null)
|
||||
{
|
||||
for (ItemStack itemStack : itemStacks)
|
||||
{
|
||||
if (((IRecipe) obj).getRecipeOutput().isItemEqual(itemStack))
|
||||
{
|
||||
itr.remove();
|
||||
didRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return didRemove;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function if you want to check if the recipe is allowed in the configuration file.
|
||||
*/
|
||||
public static void addRecipe(IRecipe recipe, String name, Configuration configuration, boolean defaultBoolean)
|
||||
{
|
||||
if (configuration != null)
|
||||
{
|
||||
configuration.load();
|
||||
|
||||
if (configuration.get("Crafting", "Allow " + name + " Crafting", defaultBoolean).getBoolean(defaultBoolean))
|
||||
{
|
||||
GameRegistry.addRecipe(recipe);
|
||||
}
|
||||
|
||||
configuration.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRecipe(IRecipe recipe, Configuration config, boolean defaultBoolean)
|
||||
{
|
||||
addRecipe(recipe, recipe.getRecipeOutput().getUnlocalizedName(), config, defaultBoolean);
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* A class to help you out with translations.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TranslationHelper
|
||||
{
|
||||
/**
|
||||
* Loads all the language files for a mod. This supports the loading of "child" language files
|
||||
* for sub-languages to be loaded all from one file instead of creating multiple of them. An
|
||||
* example of this usage would be different Spanish sub-translations (es_MX, es_YU).
|
||||
*
|
||||
* @param languagePath - The path to the mod's language file folder.
|
||||
* @param languageSupported - The languages supported. E.g: new String[]{"en_US", "en_AU",
|
||||
* "en_UK"}
|
||||
* @return The amount of language files loaded successfully.
|
||||
*/
|
||||
public static int loadLanguages(String languagePath, String[] languageSupported)
|
||||
{
|
||||
int languages = 0;
|
||||
|
||||
/**
|
||||
* Load all languages.
|
||||
*/
|
||||
for (String language : languageSupported)
|
||||
{
|
||||
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false);
|
||||
|
||||
if (LanguageRegistry.instance().getStringLocalization("children", language) != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] children = LanguageRegistry.instance().getStringLocalization("children", language).split(",");
|
||||
|
||||
for (String child : children)
|
||||
{
|
||||
if (child != "" || child != null)
|
||||
{
|
||||
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false);
|
||||
languages++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Failed to load a child language file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
languages++;
|
||||
}
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the local text of your translation based on the given key. This will look through your
|
||||
* mod's translation file that was previously registered. Make sure you enter the full name
|
||||
*
|
||||
* @param key - e.g tile.block.name
|
||||
* @return The translated string or the default English translation if none was found.
|
||||
*/
|
||||
public static String getLocal(String key)
|
||||
{
|
||||
String text = null;
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
{
|
||||
text = LanguageRegistry.instance().getStringLocalization(key);
|
||||
}
|
||||
|
||||
if (text == null || text == "")
|
||||
{
|
||||
text = LanguageRegistry.instance().getStringLocalization(key, "en_US");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
package universalelectricity.prefab.block;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* An advanced block class that is to be extended for wrenching capabilities.
|
||||
*/
|
||||
public abstract class BlockAdvanced extends Block
|
||||
{
|
||||
public BlockAdvanced(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
this.setHardness(0.6f);
|
||||
}
|
||||
|
||||
/**
|
||||
* DO NOT OVERRIDE THIS FUNCTION! Called when the block is right clicked by the player. This
|
||||
* modified version detects electric items and wrench actions on your machine block. Do not
|
||||
* override this function. Use onMachineActivated instead! (It does the same thing)
|
||||
*
|
||||
* @param world The World Object.
|
||||
* @param x , y, z The coordinate of the block.
|
||||
* @param side The side the player clicked on.
|
||||
* @param hitX , hitY, hitZ The position the player clicked on relative to the block.
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
int metadata = world.getBlockMetadata(x, y, z);
|
||||
|
||||
/**
|
||||
* Check if the player is holding a wrench or an electric item. If so, call the wrench
|
||||
* event.
|
||||
*/
|
||||
if (this.isUsableWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z))
|
||||
{
|
||||
this.damageWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z);
|
||||
|
||||
if (entityPlayer.isSneaking())
|
||||
{
|
||||
if (this.onSneakUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (entityPlayer.isSneaking())
|
||||
{
|
||||
if (this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that denotes if an itemStack is a wrench that can be used. Override this for more
|
||||
* wrench compatibility. Compatible with Buildcraft and IC2 wrench API via reflection.
|
||||
*
|
||||
* @return True if it is a wrench.
|
||||
*/
|
||||
public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
|
||||
{
|
||||
if (entityPlayer != null && itemStack != null)
|
||||
{
|
||||
Class wrenchClass = itemStack.getItem().getClass();
|
||||
|
||||
/**
|
||||
* UE and Buildcraft
|
||||
*/
|
||||
try
|
||||
{
|
||||
Method methodCanWrench = wrenchClass.getMethod("canWrench", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
return (Boolean) methodCanWrench.invoke(itemStack.getItem(), entityPlayer, x, y, z);
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Industrialcraft
|
||||
*/
|
||||
try
|
||||
{
|
||||
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
|
||||
{
|
||||
return itemStack.getItemDamage() < itemStack.getMaxDamage();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function damages a wrench. Works with Buildcraft and Industrialcraft wrenches.
|
||||
*
|
||||
* @return True if damage was successfull.
|
||||
*/
|
||||
public boolean damageWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
|
||||
{
|
||||
if (this.isUsableWrench(entityPlayer, itemStack, x, y, z))
|
||||
{
|
||||
Class wrenchClass = itemStack.getItem().getClass();
|
||||
|
||||
/**
|
||||
* UE and Buildcraft
|
||||
*/
|
||||
try
|
||||
{
|
||||
Method methodWrenchUsed = wrenchClass.getMethod("wrenchUsed", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
methodWrenchUsed.invoke(itemStack.getItem(), entityPlayer, x, y, z);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Industrialcraft
|
||||
*/
|
||||
try
|
||||
{
|
||||
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
|
||||
{
|
||||
Method methodWrenchDamage = wrenchClass.getMethod("damage", ItemStack.class, Integer.TYPE, EntityPlayer.class);
|
||||
methodWrenchDamage.invoke(itemStack.getItem(), itemStack, 1, entityPlayer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the machine is right clicked by the player
|
||||
*
|
||||
* @return True if something happens
|
||||
*/
|
||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the machine is being wrenched by a player while sneaking.
|
||||
*
|
||||
* @return True if something happens
|
||||
*/
|
||||
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses a wrench on the machine
|
||||
*
|
||||
* @return True if some happens
|
||||
*/
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses a wrench on the machine while sneaking. Only works with the UE
|
||||
* wrench.
|
||||
*
|
||||
* @return True if some happens
|
||||
*/
|
||||
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
package universalelectricity.prefab.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.tile.TileEntityConductor;
|
||||
|
||||
public abstract class BlockConductor extends BlockContainer
|
||||
{
|
||||
public boolean isWireCollision = true;
|
||||
public Vector3 minVector = new Vector3(0.3, 0.3, 0.3);
|
||||
public Vector3 maxVector = new Vector3(0.7, 0.7, 0.7);
|
||||
|
||||
public BlockConductor(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the block is added into the world. Args: world, x, y, z
|
||||
*/
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
((IConductor) tileEntity).refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed
|
||||
* (coordinates passed are their own) Args: x, y, z, neighbor blockID
|
||||
*/
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
((IConductor) tileEntity).refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bounding box from the pool of bounding boxes (this means this box can change after
|
||||
* the pool has been cleared to be reused)
|
||||
*/
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
|
||||
{
|
||||
this.setBlockBoundsBasedOnState(world, x, y, z);
|
||||
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
|
||||
{
|
||||
this.setBlockBoundsBasedOnState(world, x, y, z);
|
||||
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bounding box of the wired rectangular prism to render.
|
||||
*/
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
|
||||
{
|
||||
if (this.isWireCollision)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileEntityConductor)
|
||||
{
|
||||
TileEntity[] connectable = ((TileEntityConductor) tileEntity).getAdjacentConnections();
|
||||
|
||||
if (connectable != null)
|
||||
{
|
||||
float minX = (float) this.minVector.x;
|
||||
float minY = (float) this.minVector.y;
|
||||
float minZ = (float) this.minVector.z;
|
||||
float maxX = (float) this.maxVector.x;
|
||||
float maxY = (float) this.maxVector.y;
|
||||
float maxZ = (float) this.maxVector.z;
|
||||
|
||||
if (connectable[0] != null)
|
||||
{
|
||||
minY = 0.0F;
|
||||
}
|
||||
|
||||
if (connectable[1] != null)
|
||||
{
|
||||
maxY = 1.0F;
|
||||
}
|
||||
|
||||
if (connectable[2] != null)
|
||||
{
|
||||
minZ = 0.0F;
|
||||
}
|
||||
|
||||
if (connectable[3] != null)
|
||||
{
|
||||
maxZ = 1.0F;
|
||||
}
|
||||
|
||||
if (connectable[4] != null)
|
||||
{
|
||||
minX = 0.0F;
|
||||
}
|
||||
|
||||
if (connectable[5] != null)
|
||||
{
|
||||
maxX = 1.0F;
|
||||
}
|
||||
|
||||
this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List list, Entity entity)
|
||||
{
|
||||
if (this.isWireCollision)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileEntityConductor)
|
||||
{
|
||||
TileEntity[] connectable = ((TileEntityConductor) tileEntity).getAdjacentConnections();
|
||||
|
||||
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
|
||||
if (connectable[4] != null)
|
||||
{
|
||||
this.setBlockBounds(0, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
|
||||
if (connectable[5] != null)
|
||||
{
|
||||
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, 1, (float) this.maxVector.y, (float) this.maxVector.z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
|
||||
if (connectable[0] != null)
|
||||
{
|
||||
this.setBlockBounds((float) this.minVector.x, 0, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
|
||||
if (connectable[1] != null)
|
||||
{
|
||||
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, 1, (float) this.maxVector.z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
|
||||
if (connectable[2] != null)
|
||||
{
|
||||
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, 0, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
|
||||
if (connectable[3] != null)
|
||||
{
|
||||
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, 1);
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package universalelectricity.prefab.block;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* A block that can rotate based on placed position and wrenching.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public abstract class BlockRotatable extends BlockTile implements IRotatableBlock
|
||||
{
|
||||
protected byte rotationMask = 60;
|
||||
|
||||
public BlockRotatable(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
|
||||
{
|
||||
int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
int change = 3;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 0:
|
||||
change = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
change = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
change = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
change = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, change, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis)
|
||||
{
|
||||
int currentRotMeta = worldObj.getBlockMetadata(x, y, z);
|
||||
ForgeDirection orientation = ForgeDirection.getOrientation(currentRotMeta);
|
||||
ForgeDirection rotated = orientation.getRotation(axis);
|
||||
int rmeta = rotated.ordinal();
|
||||
int rmetaBit = 1 << rmeta;
|
||||
System.out.println(rmetaBit + ": " + (rmetaBit & this.rotationMask));
|
||||
if ((rmetaBit & this.rotationMask) == rmetaBit)
|
||||
{
|
||||
worldObj.setBlockMetadataWithNotify(x, y, z, rmeta, 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getDirection(World world, int x, int y, int z)
|
||||
{
|
||||
return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(World world, int x, int y, int z, ForgeDirection direction)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3);
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
package universalelectricity.prefab.block;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* An advanced block class that is to be extended for wrenching capabilities.
|
||||
*/
|
||||
public abstract class BlockTile extends BlockAdvanced implements ITileEntityProvider
|
||||
{
|
||||
public BlockTile(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
this.isBlockContainer = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the block is added into the world. Args: world, x, y, z
|
||||
*/
|
||||
@Override
|
||||
public void onBlockAdded(World par1World, int par2, int par3, int par4)
|
||||
{
|
||||
super.onBlockAdded(par1World, par2, par3, par4);
|
||||
}
|
||||
|
||||
/**
|
||||
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
|
||||
*/
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
this.dropEntireInventory(world, x, y, z, par5, par6);
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
world.removeBlockTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the block receives a BlockEvent - see World.addBlockEvent. By default, passes it
|
||||
* on to the tile entity at this location. Args: world, x, y, z, blockID, EventID, event
|
||||
* parameter
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockEventReceived(World par1World, int par2, int par3, int par4, int par5, int par6)
|
||||
{
|
||||
super.onBlockEventReceived(par1World, par2, par3, par4, par5, par6);
|
||||
TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
return tileentity != null ? tileentity.receiveClientEvent(par5, par6) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if you don't need it. This will eject all items out of this machine if it has
|
||||
* an inventory.
|
||||
*/
|
||||
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity instanceof IInventory)
|
||||
{
|
||||
IInventory inventory = (IInventory) tileEntity;
|
||||
|
||||
for (int var6 = 0; var6 < inventory.getSizeInventory(); ++var6)
|
||||
{
|
||||
ItemStack var7 = inventory.getStackInSlot(var6);
|
||||
|
||||
if (var7 != null)
|
||||
{
|
||||
Random random = new Random();
|
||||
float var8 = random.nextFloat() * 0.8F + 0.1F;
|
||||
float var9 = random.nextFloat() * 0.8F + 0.1F;
|
||||
float var10 = random.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
while (var7.stackSize > 0)
|
||||
{
|
||||
int var11 = random.nextInt(21) + 10;
|
||||
|
||||
if (var11 > var7.stackSize)
|
||||
{
|
||||
var11 = var7.stackSize;
|
||||
}
|
||||
|
||||
var7.stackSize -= var11;
|
||||
EntityItem var12 = new EntityItem(world, (x + var8), (y + var9), (z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
|
||||
|
||||
if (var7.hasTagCompound())
|
||||
{
|
||||
var12.getEntityItem().setTagCompound((NBTTagCompound) var7.getTagCompound().copy());
|
||||
}
|
||||
|
||||
float var13 = 0.05F;
|
||||
var12.motionX = ((float) random.nextGaussian() * var13);
|
||||
var12.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
|
||||
var12.motionZ = ((float) random.nextGaussian() * var13);
|
||||
world.spawnEntityInWorld(var12);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TileEntity used by this block. You should use the metadata sensitive version of
|
||||
* this to get the maximum optimization!
|
||||
*/
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package universalelectricity.prefab.block;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/** The interface is applied to Blocks that can rotate.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
|
||||
public interface IRotatableBlock
|
||||
{
|
||||
/** @return Gets the facing direction. Always returns the front side of the block. */
|
||||
public ForgeDirection getDirection(World world, int x, int y, int z);
|
||||
|
||||
/** @param Sets the facing direction. */
|
||||
public void setDirection(World world, int x, int y, int z, ForgeDirection direection);
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package universalelectricity.prefab.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
public interface IPacketReceiver
|
||||
{
|
||||
/**
|
||||
* Sends some data to the tile entity.
|
||||
*/
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
|
||||
}
|
|
@ -1,336 +0,0 @@
|
|||
package universalelectricity.prefab.network;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/**
|
||||
* This class is used for sending and receiving packets between the server and the client. You can
|
||||
* directly use this by registering this packet manager with NetworkMod. Example:
|
||||
*
|
||||
* @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired =
|
||||
* false, packetHandler = PacketManager.class)
|
||||
*
|
||||
* Check out {@link #BasicComponents} for better reference.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public class PacketManager implements IPacketHandler, IPacketReceiver
|
||||
{
|
||||
public enum PacketType
|
||||
{
|
||||
UNSPECIFIED, TILEENTITY;
|
||||
|
||||
public static PacketType get(int id)
|
||||
{
|
||||
if (id >= 0 && id < PacketType.values().length)
|
||||
{
|
||||
return PacketType.values()[id];
|
||||
}
|
||||
return UNSPECIFIED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compressed NBTTagCompound to the OutputStream
|
||||
*/
|
||||
public static void writeNBTTagCompound(NBTTagCompound tag, DataOutputStream dataStream) throws IOException
|
||||
{
|
||||
if (tag == null)
|
||||
{
|
||||
dataStream.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = CompressedStreamTools.compress(tag);
|
||||
dataStream.writeShort((short) var2.length);
|
||||
dataStream.write(var2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeNBTTagCompound(NBTTagCompound tag, ByteArrayDataOutput dataStream) throws IOException
|
||||
{
|
||||
if (tag == null)
|
||||
{
|
||||
dataStream.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = CompressedStreamTools.compress(tag);
|
||||
dataStream.writeShort((short) var2.length);
|
||||
dataStream.write(var2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compressed NBTTagCompount in a ByteStream.
|
||||
*/
|
||||
public static NBTTagCompound readNBTTagCompound(DataInputStream dataStream) throws IOException
|
||||
{
|
||||
short var1 = dataStream.readShort();
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = new byte[var1];
|
||||
dataStream.readFully(var2);
|
||||
return CompressedStreamTools.decompress(var2);
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTTagCompound readNBTTagCompound(ByteArrayDataInput dataStream) throws IOException
|
||||
{
|
||||
short var1 = dataStream.readShort();
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = new byte[var1];
|
||||
dataStream.readFully(var2);
|
||||
return CompressedStreamTools.decompress(var2);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static Packet getPacketWithID(String channelName, int id, Object... sendData)
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try
|
||||
{
|
||||
data.writeInt(id);
|
||||
data = encodeDataStream(data, sendData);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channelName;
|
||||
packet.data = bytes.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Failed to create packet.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Packet getPacket(String channelName, Object... sendData)
|
||||
{
|
||||
return getPacketWithID(channelName, PacketType.UNSPECIFIED.ordinal(), sendData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a packet for the tile entity.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public static Packet getPacket(String channelName, TileEntity sender, Object... sendData)
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try
|
||||
{
|
||||
data.writeInt(PacketType.TILEENTITY.ordinal());
|
||||
|
||||
data.writeInt(sender.xCoord);
|
||||
data.writeInt(sender.yCoord);
|
||||
data.writeInt(sender.zCoord);
|
||||
data = encodeDataStream(data, sendData);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channelName;
|
||||
packet.data = bytes.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Failed to create packet.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends packets to clients around a specific coordinate. A wrapper using Vector3. See
|
||||
* {@PacketDispatcher} for detailed information.
|
||||
*/
|
||||
public static void sendPacketToClients(Packet packet, World worldObj, Vector3 position, double range)
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllAround(position.x, position.y, position.z, range, worldObj.provider.dimensionId, packet);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Sending packet to client failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a packet to all the clients on this server.
|
||||
*/
|
||||
public static void sendPacketToClients(Packet packet, World worldObj)
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllInDimension(packet, worldObj.provider.dimensionId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Sending packet to client failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketToClients(Packet packet)
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllPlayers(packet);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Sending packet to client failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static DataOutputStream encodeDataStream(DataOutputStream data, Object... sendData)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Object dataValue : sendData)
|
||||
{
|
||||
if (dataValue instanceof Integer)
|
||||
{
|
||||
data.writeInt((Integer) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Float)
|
||||
{
|
||||
data.writeFloat((Float) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Double)
|
||||
{
|
||||
data.writeDouble((Double) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Byte)
|
||||
{
|
||||
data.writeByte((Byte) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Boolean)
|
||||
{
|
||||
data.writeBoolean((Boolean) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof String)
|
||||
{
|
||||
data.writeUTF((String) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Short)
|
||||
{
|
||||
data.writeShort((Short) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Long)
|
||||
{
|
||||
data.writeLong((Long) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof NBTTagCompound)
|
||||
{
|
||||
writeNBTTagCompound((NBTTagCompound) dataValue, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Packet data encoding failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
ByteArrayDataInput data = ByteStreams.newDataInput(packet.data);
|
||||
|
||||
int packetTypeID = data.readInt();
|
||||
|
||||
PacketType packetType = PacketType.get(packetTypeID);
|
||||
|
||||
if (packetType == PacketType.TILEENTITY)
|
||||
{
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity instanceof IPacketReceiver)
|
||||
{
|
||||
((IPacketReceiver) tileEntity).handlePacketData(network, packetTypeID, packet, ((EntityPlayer) player), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handlePacketData(network, packetTypeID, packet, ((EntityPlayer) player), data);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
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.addOre()} 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);
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 = par3 + 8 + MathHelper.sin(var6) * this.amountPerBranch / 8.0F;
|
||||
double var9 = par3 + 8 - MathHelper.sin(var6) * this.amountPerBranch / 8.0F;
|
||||
double var11 = par5 + 8 + MathHelper.cos(var6) * this.amountPerBranch / 8.0F;
|
||||
double var13 = par5 + 8 - MathHelper.cos(var6) * this.amountPerBranch / 8.0F;
|
||||
double var15 = par4 + par2Random.nextInt(3) - 2;
|
||||
double var17 = par4 + par2Random.nextInt(3) - 2;
|
||||
|
||||
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
|
||||
{
|
||||
double var20 = var7 + (var9 - var7) * var19 / this.amountPerBranch;
|
||||
double var22 = var15 + (var17 - var15) * var19 / this.amountPerBranch;
|
||||
double var24 = var11 + (var13 - var11) * var19 / this.amountPerBranch;
|
||||
double var26 = par2Random.nextDouble() * this.amountPerBranch / 16.0D;
|
||||
double var28 = (MathHelper.sin(var19 * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
||||
double var30 = (MathHelper.sin(var19 * (float) Math.PI / 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 = (var38 + 0.5D - var20) / (var28 / 2.0D);
|
||||
|
||||
if (var39 * var39 < 1.0D)
|
||||
{
|
||||
for (int var41 = var33; var41 <= var36; ++var41)
|
||||
{
|
||||
double var42 = (var41 + 0.5D - var22) / (var30 / 2.0D);
|
||||
|
||||
if (var39 * var39 + var42 * var42 < 1.0D)
|
||||
{
|
||||
for (int var44 = var34; var44 <= var37; ++var44)
|
||||
{
|
||||
double var45 = (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.setBlock(var38, var41, var44, this.oreID, this.oreMeta, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package universalelectricity.prefab.potion;
|
||||
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
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);
|
||||
Potion.potionTypes[this.getId()] = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Potion setIconIndex(int par1, int par2)
|
||||
{
|
||||
super.setIconIndex(par1, par2);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Potion setEffectiveness(double par1)
|
||||
{
|
||||
super.setEffectiveness(par1);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package universalelectricity.prefab.tile;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* The interface is applied to TileEntities that can rotate.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
|
||||
public interface IRotatable
|
||||
{
|
||||
/**
|
||||
* @return Gets the facing direction. Always returns the front side of the block.
|
||||
*/
|
||||
public ForgeDirection getDirection();
|
||||
|
||||
/**
|
||||
* @param Sets the facing direction.
|
||||
*/
|
||||
public void setDirection(ForgeDirection direection);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package universalelectricity.prefab.tile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* A TileEntity with some pre-added functionalities.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityAdvanced extends TileEntity
|
||||
{
|
||||
protected long ticks = 0;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (this.ticks == 0)
|
||||
{
|
||||
this.initiate();
|
||||
}
|
||||
|
||||
if (this.ticks >= Long.MAX_VALUE)
|
||||
{
|
||||
this.ticks = 1;
|
||||
}
|
||||
|
||||
this.ticks++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on the TileEntity's first tick.
|
||||
*/
|
||||
public void initiate()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockMetadata()
|
||||
{
|
||||
if (this.blockMetadata == -1)
|
||||
{
|
||||
this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
return this.blockMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockType()
|
||||
{
|
||||
if (this.blockType == null)
|
||||
{
|
||||
this.blockType = Block.blocksList[this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord)];
|
||||
}
|
||||
|
||||
return this.blockType;
|
||||
}
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
package universalelectricity.prefab.tile;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.electricity.NetworkLoader;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* This tile entity pre-fabricated for all conductors.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityConductor extends TileEntityAdvanced implements IConductor
|
||||
{
|
||||
private IElectricityNetwork network;
|
||||
|
||||
public TileEntity[] adjacentConnections = null;
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
this.getNetwork().split(this);
|
||||
}
|
||||
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElectricityNetwork getNetwork()
|
||||
{
|
||||
if (this.network == null)
|
||||
{
|
||||
this.setNetwork(NetworkLoader.getNewNetwork(this));
|
||||
}
|
||||
|
||||
return this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(IElectricityNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
this.adjacentConnections = null;
|
||||
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tileEntity = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), side);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider)
|
||||
{
|
||||
this.getNetwork().merge(((INetworkProvider) tileEntity).getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.getNetwork().refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity[] getAdjacentConnections()
|
||||
{
|
||||
/**
|
||||
* Cache the adjacentConnections.
|
||||
*/
|
||||
if (this.adjacentConnections == null)
|
||||
{
|
||||
this.adjacentConnections = new TileEntity[6];
|
||||
|
||||
for (byte i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(i);
|
||||
TileEntity tileEntity = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), side);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.adjacentConnections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
|
||||
}
|
||||
}
|
|
@ -1,244 +0,0 @@
|
|||
package universalelectricity.prefab.tile;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import universalelectricity.core.block.IElectricalStorage;
|
||||
import universalelectricity.core.electricity.ElectricityHelper;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
|
||||
public abstract class TileEntityElectrical extends TileEntityAdvanced implements IElectrical, IElectricalStorage
|
||||
{
|
||||
public float energyStored = 0;
|
||||
|
||||
/**
|
||||
* Recharges electric item.
|
||||
*/
|
||||
public void recharge(ItemStack itemStack)
|
||||
{
|
||||
this.setEnergyStored(this.getEnergyStored() - ElectricItemHelper.chargeItem(itemStack, this.getProvide(ForgeDirection.UNKNOWN)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharges electric item.
|
||||
*/
|
||||
public void discharge(ItemStack itemStack)
|
||||
{
|
||||
this.setEnergyStored(this.getEnergyStored() + ElectricItemHelper.dischargeItem(itemStack, this.getRequest(ForgeDirection.UNKNOWN)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to produce the potential electricity inside this block.
|
||||
*/
|
||||
public void produce()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (ForgeDirection outputDirection : this.getOutputDirections())
|
||||
{
|
||||
this.produceUE(outputDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces UE power towards a specific direction.
|
||||
*
|
||||
* @param outputDirection - The output direction.
|
||||
*/
|
||||
public boolean produceUE(ForgeDirection outputDirection)
|
||||
{
|
||||
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
float provide = this.getProvide(outputDirection);
|
||||
|
||||
if (provide > 0)
|
||||
{
|
||||
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
|
||||
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection);
|
||||
if (outputNetwork != null)
|
||||
{
|
||||
ElectricityPack powerRequest = outputNetwork.getRequest(this);
|
||||
|
||||
if (powerRequest.getWatts() > 0)
|
||||
{
|
||||
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(this.getEnergyStored(), this.getVoltage()), ElectricityPack.getFromWatts(provide, this.getVoltage()));
|
||||
float rejectedPower = outputNetwork.produce(sendPack, this);
|
||||
this.provideElectricity(Math.max(sendPack.getWatts() - rejectedPower, 0), true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (outputTile instanceof IElectrical)
|
||||
{
|
||||
float requestedEnergy = ((IElectrical) outputTile).getRequest(outputDirection.getOpposite());
|
||||
|
||||
if (requestedEnergy > 0)
|
||||
{
|
||||
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(this.getEnergyStored(), this.getVoltage()), ElectricityPack.getFromWatts(provide, this.getVoltage()));
|
||||
float acceptedEnergy = ((IElectrical) outputTile).receiveElectricity(outputDirection.getOpposite(), sendPack, true);
|
||||
this.provideElectricity(acceptedEnergy, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The electrical input direction.
|
||||
*
|
||||
* @return The direction that electricity is entered into the tile. Return null for no input. By
|
||||
* default you can accept power from all sides.
|
||||
*/
|
||||
public EnumSet<ForgeDirection> getInputDirections()
|
||||
{
|
||||
return EnumSet.allOf(ForgeDirection.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The electrical output direction.
|
||||
*
|
||||
* @return The direction that electricity is output from the tile. Return null for no output. By
|
||||
* default it will return an empty EnumSet.
|
||||
*/
|
||||
public EnumSet<ForgeDirection> getOutputDirections()
|
||||
{
|
||||
return EnumSet.noneOf(ForgeDirection.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
|
||||
{
|
||||
if (this.getInputDirections().contains(from))
|
||||
{
|
||||
if (!doReceive)
|
||||
{
|
||||
return this.getRequest(from);
|
||||
}
|
||||
|
||||
return this.receiveElectricity(receive, doReceive);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
|
||||
{
|
||||
if (this.getOutputDirections().contains(from))
|
||||
{
|
||||
if (!doProvide)
|
||||
{
|
||||
return ElectricityPack.getFromWatts(this.getProvide(from), this.getVoltage());
|
||||
}
|
||||
|
||||
return this.provideElectricity(request, doProvide);
|
||||
}
|
||||
|
||||
return new ElectricityPack();
|
||||
}
|
||||
|
||||
/**
|
||||
* A non-side specific version of receiveElectricity for you to optionally use it internally.
|
||||
*/
|
||||
public float receiveElectricity(ElectricityPack receive, boolean doReceive)
|
||||
{
|
||||
if (receive != null)
|
||||
{
|
||||
float prevEnergyStored = this.getEnergyStored();
|
||||
float newStoredEnergy = Math.min(this.getEnergyStored() + receive.getWatts(), this.getMaxEnergyStored());
|
||||
|
||||
if (doReceive)
|
||||
{
|
||||
this.setEnergyStored(newStoredEnergy);
|
||||
}
|
||||
|
||||
return Math.max(newStoredEnergy - prevEnergyStored, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float receiveElectricity(float energy, boolean doReceive)
|
||||
{
|
||||
return this.receiveElectricity(ElectricityPack.getFromWatts(energy, this.getVoltage()), doReceive);
|
||||
}
|
||||
|
||||
/**
|
||||
* A non-side specific version of provideElectricity for you to optionally use it internally.
|
||||
*/
|
||||
public ElectricityPack provideElectricity(ElectricityPack request, boolean doProvide)
|
||||
{
|
||||
if (request != null)
|
||||
{
|
||||
float requestedEnergy = Math.min(request.getWatts(), this.energyStored);
|
||||
|
||||
if (doProvide)
|
||||
{
|
||||
this.setEnergyStored(this.energyStored - requestedEnergy);
|
||||
}
|
||||
|
||||
return ElectricityPack.getFromWatts(requestedEnergy, this.getVoltage());
|
||||
}
|
||||
|
||||
return new ElectricityPack();
|
||||
}
|
||||
|
||||
public ElectricityPack provideElectricity(float energy, boolean doProvide)
|
||||
{
|
||||
return this.provideElectricity(ElectricityPack.getFromWatts(energy, this.getVoltage()), doProvide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergyStored(float energy)
|
||||
{
|
||||
this.energyStored = Math.max(Math.min(energy, this.getMaxEnergyStored()), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored()
|
||||
{
|
||||
return this.energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
if (direction == null || direction.equals(ForgeDirection.UNKNOWN))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.getInputDirections().contains(direction) || this.getOutputDirections().contains(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVoltage()
|
||||
{
|
||||
return 0.120F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
this.energyStored = nbt.getFloat("energyStored");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setFloat("energyStored", this.energyStored);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package universalelectricity.prefab.vector;
|
||||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
|
||||
public class Region2
|
||||
{
|
||||
public Vector2 min;
|
||||
public Vector2 max;
|
||||
|
||||
public Region2()
|
||||
{
|
||||
this(new Vector2(), new Vector2());
|
||||
}
|
||||
|
||||
public Region2(Vector2 min, Vector2 max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a point is located inside a region
|
||||
*/
|
||||
public boolean isIn(Vector2 point)
|
||||
{
|
||||
return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given region intersects with this one.
|
||||
*/
|
||||
public boolean isIn(Region2 region)
|
||||
{
|
||||
return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? true : false) : false;
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
package universalelectricity.prefab.vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* A cubical region class.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public class Region3
|
||||
{
|
||||
public Vector3 min;
|
||||
public Vector3 max;
|
||||
|
||||
public Region3()
|
||||
{
|
||||
this(new Vector3(), new Vector3());
|
||||
}
|
||||
|
||||
public Region3(Vector3 min, Vector3 max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Region3(AxisAlignedBB aabb)
|
||||
{
|
||||
this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ);
|
||||
this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ);
|
||||
}
|
||||
|
||||
public AxisAlignedBB toAABB()
|
||||
{
|
||||
return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z);
|
||||
}
|
||||
|
||||
public Region2 toRegion2()
|
||||
{
|
||||
return new Region2(this.min.toVector2(), this.max.toVector2());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a point is located inside a region
|
||||
*/
|
||||
public boolean isIn(Vector3 point)
|
||||
{
|
||||
return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y) && (point.z > this.min.z && point.z < this.max.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given region intersects with this one.
|
||||
*/
|
||||
public boolean isIn(Region3 region)
|
||||
{
|
||||
return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? region.max.z > this.min.z && region.min.z < this.max.z : false) : false;
|
||||
}
|
||||
|
||||
public void expand(Vector3 difference)
|
||||
{
|
||||
this.min.subtract(difference);
|
||||
this.max.add(difference);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of vectors within this region.
|
||||
*/
|
||||
public List<Vector3> getVectors()
|
||||
{
|
||||
List<Vector3> vectors = new ArrayList<Vector3>();
|
||||
|
||||
for (int x = this.min.intX(); x < this.max.intX(); x++)
|
||||
{
|
||||
for (int y = this.min.intY(); x < this.max.intY(); y++)
|
||||
{
|
||||
for (int z = this.min.intZ(); x < this.max.intZ(); z++)
|
||||
{
|
||||
vectors.add(new Vector3(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vectors;
|
||||
}
|
||||
|
||||
public List<Vector3> getVectors(Vector3 center, int radius)
|
||||
{
|
||||
List<Vector3> vectors = new ArrayList<Vector3>();
|
||||
|
||||
for (int x = this.min.intX(); x < this.max.intX(); x++)
|
||||
{
|
||||
for (int y = this.min.intY(); x < this.max.intY(); y++)
|
||||
{
|
||||
for (int z = this.min.intZ(); x < this.max.intZ(); z++)
|
||||
{
|
||||
Vector3 vector3 = new Vector3(x, y, z);
|
||||
|
||||
if (center.distanceTo(vector3) <= radius)
|
||||
{
|
||||
vectors.add(vector3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vectors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all entities in this region.
|
||||
*/
|
||||
public List<Entity> getEntities(World world, Class<? extends Entity> entityClass)
|
||||
{
|
||||
return world.getEntitiesWithinAABB(entityClass, this.toAABB());
|
||||
}
|
||||
|
||||
public List<Entity> getEntitiesExlude(World world, Entity entity)
|
||||
{
|
||||
return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB());
|
||||
}
|
||||
|
||||
public List<Entity> getEntities(World world)
|
||||
{
|
||||
return this.getEntities(world, Entity.class);
|
||||
}
|
||||
}
|
|
@ -4,13 +4,12 @@ import java.awt.Color;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
import com.builtbroken.minecraft.IExtraInfo.IExtraBlockInfo;
|
||||
|
|
|
@ -7,8 +7,8 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.compatibility.Compatibility;
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.api.Compatibility;
|
||||
import universalelectricity.api.UniversalElectricity;
|
||||
|
||||
import com.builtbroken.minecraft.fluid.FluidHelper;
|
||||
import com.builtbroken.minecraft.helpers.PlayerKeyHandler;
|
||||
|
@ -80,8 +80,6 @@ public class DarkCore
|
|||
TickRegistry.registerTickHandler(NetworkUpdateHandler.instance(), Side.SERVER);
|
||||
TickRegistry.registerScheduledTickHandler(new PlayerKeyHandler(), Side.CLIENT);
|
||||
MinecraftForge.EVENT_BUS.register(new LaserEntityDamageSource(null));
|
||||
UniversalElectricity.initiate();
|
||||
Compatibility.initiate();
|
||||
pre = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,7 @@ import net.minecraft.world.World;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
|
|
@ -19,7 +19,7 @@ import net.minecraftforge.common.IPlantable;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.minecraft.helpers.DarksHelper;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
public class MachineMiningEvent extends Event
|
||||
{
|
||||
|
|
|
@ -4,9 +4,9 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import universalelectricity.prefab.CustomDamageSource;
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
||||
public class OtherDamageSource extends CustomDamageSource
|
||||
public class OtherDamageSource extends DamageSource
|
||||
{
|
||||
protected Object damageSource;
|
||||
|
||||
|
@ -33,13 +33,20 @@ public class OtherDamageSource extends CustomDamageSource
|
|||
return this.damageSource != null && this.damageSource instanceof EntityLiving && !(this.damageSource instanceof EntityPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OtherDamageSource setProjectile()
|
||||
{
|
||||
super.setProjectile();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static OtherDamageSource doBulletDamage(Object object)
|
||||
{
|
||||
return (OtherDamageSource) ((CustomDamageSource) new OtherDamageSource("Bullets", object).setProjectile()).setDeathMessage("%1$s was filled with holes!");
|
||||
return new OtherDamageSource("Bullets", object).setProjectile();
|
||||
}
|
||||
|
||||
public static OtherDamageSource doLaserDamage(Object object)
|
||||
{
|
||||
return (OtherDamageSource) ((CustomDamageSource) new OtherDamageSource("Laser", object).setProjectile()).setDeathMessage("%1$s was vaporized!");
|
||||
return new OtherDamageSource("Laser", object).setProjectile();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.minecraft.network.PacketManagerEffects;
|
||||
|
||||
|
|
79
src/com/builtbroken/minecraft/TranslationHelper.java
Normal file
79
src/com/builtbroken/minecraft/TranslationHelper.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package com.builtbroken.minecraft;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
/** A class to help you out with translations.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class TranslationHelper
|
||||
{
|
||||
/** Loads all the language files for a mod. This supports the loading of "child" language files
|
||||
* for sub-languages to be loaded all from one file instead of creating multiple of them. An
|
||||
* example of this usage would be different Spanish sub-translations (es_MX, es_YU).
|
||||
*
|
||||
* @param languagePath - The path to the mod's language file folder.
|
||||
* @param languageSupported - The languages supported. E.g: new String[]{"en_US", "en_AU",
|
||||
* "en_UK"}
|
||||
* @return The amount of language files loaded successfully. */
|
||||
public static int loadLanguages(String languagePath, String[] languageSupported)
|
||||
{
|
||||
int languages = 0;
|
||||
|
||||
/** Load all languages. */
|
||||
for (String language : languageSupported)
|
||||
{
|
||||
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false);
|
||||
|
||||
if (LanguageRegistry.instance().getStringLocalization("children", language) != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] children = LanguageRegistry.instance().getStringLocalization("children", language).split(",");
|
||||
|
||||
for (String child : children)
|
||||
{
|
||||
if (child != "" || child != null)
|
||||
{
|
||||
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false);
|
||||
languages++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Failed to load a child language file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
languages++;
|
||||
}
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
/** Gets the local text of your translation based on the given key. This will look through your
|
||||
* mod's translation file that was previously registered. Make sure you enter the full name
|
||||
*
|
||||
* @param key - e.g tile.block.name
|
||||
* @return The translated string or the default English translation if none was found. */
|
||||
public static String getLocal(String key)
|
||||
{
|
||||
String text = null;
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
{
|
||||
text = LanguageRegistry.instance().getStringLocalization(key);
|
||||
}
|
||||
|
||||
if (text == null || text == "")
|
||||
{
|
||||
text = LanguageRegistry.instance().getStringLocalization(key, "en_US");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ import net.minecraftforge.fluids.FluidStack;
|
|||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
import com.builtbroken.minecraft.recipes.AutoCraftingManager;
|
||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
/** Class full of generic re-usable methods
|
||||
*
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue