updated sgt2 and ue api; delaying result signal for rim carriage controller a bit, fixes #112

This commit is contained in:
Florian Nücke 2014-02-03 00:24:36 +01:00
parent 8374f6b784
commit 7ca1d23576
6 changed files with 137 additions and 124 deletions

View File

@ -21,6 +21,8 @@ class Carriage(controller: AnyRef) extends ManagedComponent {
private var shouldMove = false private var shouldMove = false
private var moving = false private var moving = false
private var signalDelay = 10
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
@LuaCallback("move") @LuaCallback("move")
@ -79,9 +81,12 @@ class Carriage(controller: AnyRef) extends ManagedComponent {
override def update() { override def update() {
if (node != null && node.network != null && moving) { if (node != null && node.network != null && moving) {
signalDelay = signalDelay - 1
if (signalDelay <= 0) {
moving = false moving = false
node.sendToReachable("computer.signal", "carriage_moved", Boolean.box(true)) node.sendToReachable("computer.signal", "carriage_moved", Boolean.box(true))
} }
}
super.update() super.update()
if (shouldMove) { if (shouldMove) {
shouldMove = false shouldMove = false

View File

@ -19,7 +19,8 @@ public interface ITileStargateBase extends ITileStargate{
* Used to try making the Stargate dial an address. * Used to try making the Stargate dial an address.
* *
* @param address The address this Stargate should dial. * @param address The address this Stargate should dial.
* @param timeout How many seconds the connection will last. (1 - 38; default: 38);
* @return whether the dialing sequence started (true) or failed (false). * @return whether the dialing sequence started (true) or failed (false).
*/ */
public boolean dial(Address address); public boolean dial(Address address, int timeout);
} }

View File

@ -192,21 +192,21 @@ public abstract class CompatibilityModule
return 0; return 0;
} }
public static long getEnergyItem(ItemStack is) public static long getEnergyItem(ItemStack itemStack)
{ {
if (isHandler(is.getItem())) if (itemStack != null && isHandler(itemStack.getItem()))
{ {
return energyHandlerCache.get(is.getItem().getClass()).doGetEnergyItem(is); return energyHandlerCache.get(itemStack.getItem().getClass()).doGetEnergyItem(itemStack);
} }
return 0; return 0;
} }
public static long getMaxEnergyItem(ItemStack is) public static long getMaxEnergyItem(ItemStack itemStack)
{ {
if (isHandler(is.getItem())) if (itemStack != null && isHandler(itemStack.getItem()))
{ {
return energyHandlerCache.get(is.getItem().getClass()).doGetMaxEnergyItem(is); return energyHandlerCache.get(itemStack.getItem().getClass()).doGetMaxEnergyItem(itemStack);
} }
return 0; return 0;

View File

@ -9,20 +9,21 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat; import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.world.World; import net.minecraft.world.World;
import universalelectricity.api.CompatibilityModule; import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.UniversalElectricity; import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.energy.UnitDisplay; import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit; import universalelectricity.api.energy.UnitDisplay.Unit;
/** /** Extend from this class if your item requires electricity or to be charged. Optionally, you can
* Extend from this class if your item requires electricity or to be charged. Optionally, you can
* implement IItemElectric instead. * implement IItemElectric instead.
* *
* @author Calclavia * @author Calclavia */
*/
public abstract class ItemElectric extends Item implements IEnergyItem, IVoltageItem public abstract class ItemElectric extends Item implements IEnergyItem, IVoltageItem
{ {
private static final String ENERGY_NBT = "electricity";
public ItemElectric(int id) public ItemElectric(int id)
{ {
super(id); super(id);
@ -53,10 +54,8 @@ public abstract class ItemElectric extends Item implements IEnergyItem, IVoltage
list.add(color + UnitDisplay.getDisplayShort(joules, Unit.JOULES) + "/" + UnitDisplay.getDisplayShort(getEnergyCapacity(itemStack), Unit.JOULES)); list.add(color + UnitDisplay.getDisplayShort(joules, Unit.JOULES) + "/" + UnitDisplay.getDisplayShort(getEnergyCapacity(itemStack), Unit.JOULES));
} }
/** /** Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do * not want this to happen! */
* not want this to happen!
*/
@Override @Override
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer) public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
{ {
@ -109,7 +108,7 @@ public abstract class ItemElectric extends Item implements IEnergyItem, IVoltage
} }
long electricityStored = Math.max(Math.min(joules, getEnergyCapacity(itemStack)), 0); long electricityStored = Math.max(Math.min(joules, getEnergyCapacity(itemStack)), 0);
itemStack.getTagCompound().setLong("electricity", electricityStored); itemStack.getTagCompound().setLong(ENERGY_NBT, electricityStored);
itemStack.setItemDamage((int) (100 - ((double) electricityStored / (double) getEnergyCapacity(itemStack)) * 100)); itemStack.setItemDamage((int) (100 - ((double) electricityStored / (double) getEnergyCapacity(itemStack)) * 100));
} }
@ -128,18 +127,18 @@ public abstract class ItemElectric extends Item implements IEnergyItem, IVoltage
long energyStored = 0; long energyStored = 0;
if (itemStack.getTagCompound().hasKey("electricity")) if (itemStack.getTagCompound().hasKey(ENERGY_NBT))
{ {
// Backwards compatibility // Backwards compatibility
NBTBase obj = itemStack.getTagCompound().getTag("electricity"); NBTBase obj = itemStack.getTagCompound().getTag(ENERGY_NBT);
if (obj instanceof NBTTagFloat) if (obj instanceof NBTTagFloat)
{ {
energyStored = (long) ((NBTTagFloat) obj).data; energyStored = (long) ((NBTTagFloat) obj).data;
} }
else else if (obj instanceof NBTTagLong)
{ {
energyStored = itemStack.getTagCompound().getLong("electricity"); energyStored = (long) ((NBTTagLong) obj).data;
} }
} }

View File

@ -150,7 +150,9 @@ public class Vector2 implements Cloneable
@Override @Override
public int hashCode() public int hashCode()
{ {
return ("X:" + this.x + "Y:" + this.y).hashCode(); long x = Double.doubleToLongBits(this.x);
long y = Double.doubleToLongBits(this.y);
return 31 * (int)(x ^ (x >>> 32)) + (int)(y ^ (y >>> 32));
} }
@Override @Override

View File

@ -816,7 +816,13 @@ public class Vector3 implements Cloneable
@Override @Override
public int hashCode() public int hashCode()
{ {
return ("X:" + this.x + "Y:" + this.y + "Z:" + this.z).hashCode(); long x = Double.doubleToLongBits(this.x);
long y = Double.doubleToLongBits(this.y);
long z = Double.doubleToLongBits(this.z);
int hash = (int)(x ^ (x >>> 32));
hash = 31 * hash + (int)(y ^ (y >>> 32));
hash = 31 * hash + (int)(z ^ (z >>> 32));
return hash;
} }
@Override @Override