chore!: move UE core/API to own mod
This commit is contained in:
parent
1a532aa4dd
commit
1c50f43014
23
build.gradle
23
build.gradle
|
@ -23,26 +23,33 @@ apply plugin: 'maven-publish'
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
version = "1.1.1"
|
version = "2.0.0"
|
||||||
group= "universalelectricity"
|
group= "universalelectricity"
|
||||||
archivesBaseName = "basiccomponents"
|
archivesBaseName = "basiccomponents"
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = "1.7.10-10.13.4.1614-1.7.10"
|
version = "1.7.10-10.13.4.1614-1.7.10"
|
||||||
runDir = "run"
|
runDir = "run"
|
||||||
|
|
||||||
|
replaceIn "basiccomponents/common/BasicComponents.java"
|
||||||
|
replace "{VERSION}", project.version
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
name = "ic2"
|
url = "https://maven.tilera.xyz/"
|
||||||
url = "https://maven.ic2.player.to/"
|
}
|
||||||
metadataSources {
|
maven {
|
||||||
artifact()
|
name = "ic2"
|
||||||
}
|
url = "https://maven.ic2.player.to/"
|
||||||
}
|
metadataSources {
|
||||||
|
artifact()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'universalelectricity:universalelectricity:5.0.0:deobf'
|
||||||
implementation 'net.industrial-craft:industrialcraft-2:2.2.660-experimental:dev'
|
implementation 'net.industrial-craft:industrialcraft-2:2.2.660-experimental:dev'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||||
import universalelectricity.compat.CompatHandler;
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
import universalelectricity.core.UniversalElectricity;
|
||||||
import universalelectricity.core.item.ElectricItemHelper;
|
import universalelectricity.core.item.ElectricItemHelper;
|
||||||
import universalelectricity.prefab.RecipeHelper;
|
import universalelectricity.prefab.RecipeHelper;
|
||||||
|
@ -49,12 +48,12 @@ import universalelectricity.prefab.ore.OreGenBase;
|
||||||
import universalelectricity.prefab.ore.OreGenReplaceStone;
|
import universalelectricity.prefab.ore.OreGenReplaceStone;
|
||||||
import universalelectricity.prefab.ore.OreGenerator;
|
import universalelectricity.prefab.ore.OreGenerator;
|
||||||
|
|
||||||
@Mod(modid = BasicComponents.MODID, name = BasicComponents.NAME, version = BasicComponents.VERSION)
|
@Mod(modid = BasicComponents.MODID, name = BasicComponents.NAME, version = BasicComponents.VERSION, dependencies = "required-after:universalelectricity")
|
||||||
public class BasicComponents {
|
public class BasicComponents {
|
||||||
|
|
||||||
public static final String NAME = "Basic Components";
|
public static final String NAME = "Basic Components";
|
||||||
public static final String MODID = "basiccomponents";
|
public static final String MODID = "basiccomponents";
|
||||||
public static final String VERSION = "1.0.0-dirty";
|
public static final String VERSION = "{VERSION}";
|
||||||
public static String CHANNEL = "";
|
public static String CHANNEL = "";
|
||||||
public static final String RESOURCE_PATH = "/mods/basiccomponents/";
|
public static final String RESOURCE_PATH = "/mods/basiccomponents/";
|
||||||
public static CommonProxy proxy;
|
public static CommonProxy proxy;
|
||||||
|
@ -120,8 +119,6 @@ public class BasicComponents {
|
||||||
registerCircuits();
|
registerCircuits();
|
||||||
registerMachines();
|
registerMachines();
|
||||||
CONFIGURATION.save();
|
CONFIGURATION.save();
|
||||||
CompatHandler.initCompatHandlers();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|
|
@ -2,6 +2,8 @@ package basiccomponents.common.tileentity;
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
import mekanism.api.energy.ICableOutputter;
|
import mekanism.api.energy.ICableOutputter;
|
||||||
|
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||||
|
import mekanism.api.energy.IStrictEnergyStorage;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -26,7 +28,7 @@ import universalelectricity.core.vector.Vector3;
|
||||||
import universalelectricity.core.vector.VectorHelper;
|
import universalelectricity.core.vector.VectorHelper;
|
||||||
import universalelectricity.prefab.tile.TileEntityElectricityStorage;
|
import universalelectricity.prefab.tile.TileEntityElectricityStorage;
|
||||||
|
|
||||||
public class TileEntityBatteryBox extends TileEntityElectricityStorage implements IElectricityStorage, ISidedInventory, ICableOutputter {
|
public class TileEntityBatteryBox extends TileEntityElectricityStorage implements IElectricityStorage, ISidedInventory, ICableOutputter, IStrictEnergyStorage, IStrictEnergyAcceptor {
|
||||||
|
|
||||||
private ItemStack[] containingItems = new ItemStack[2];
|
private ItemStack[] containingItems = new ItemStack[2];
|
||||||
public final Set<EntityPlayer> playersUsing = new HashSet();
|
public final Set<EntityPlayer> playersUsing = new HashSet();
|
||||||
|
@ -246,6 +248,34 @@ public class TileEntityBatteryBox extends TileEntityElectricityStorage implement
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double transferEnergyToAcceptor(ForgeDirection side, double amount) {
|
||||||
|
if (!canReceiveEnergy(side)) return 0;
|
||||||
|
double toUse = Math.min(getMaxEnergy()-getEnergy(), amount);
|
||||||
|
setEnergy(toUse + getEnergy());
|
||||||
|
return toUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canReceiveEnergy(ForgeDirection side) {
|
||||||
|
return getConsumingSides().contains(side);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getEnergy() {
|
||||||
|
return getJoules();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnergy(double energy) {
|
||||||
|
setJoules(energy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMaxEnergy() {
|
||||||
|
return getMaxJoules();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canOutputTo(ForgeDirection side) {
|
public boolean canOutputTo(ForgeDirection side) {
|
||||||
return side == ForgeDirection.getOrientation(this.getBlockMetadata() - 4 + 2);
|
return side == ForgeDirection.getOrientation(this.getBlockMetadata() - 4 + 2);
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package cofh.api.energy;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IEnergyConnection {
|
|
||||||
|
|
||||||
boolean canConnectEnergy(ForgeDirection var1);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package cofh.api.energy;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IEnergyProvider extends IEnergyConnection {
|
|
||||||
|
|
||||||
int extractEnergy(ForgeDirection var1, int var2, boolean var3);
|
|
||||||
|
|
||||||
int getEnergyStored(ForgeDirection var1);
|
|
||||||
|
|
||||||
int getMaxEnergyStored(ForgeDirection var1);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package cofh.api.energy;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IEnergyReceiver extends IEnergyConnection {
|
|
||||||
|
|
||||||
int receiveEnergy(ForgeDirection var1, int var2, boolean var3);
|
|
||||||
|
|
||||||
int getEnergyStored(ForgeDirection var1);
|
|
||||||
|
|
||||||
int getMaxEnergyStored(ForgeDirection var1);
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package cofh.api.energy;
|
|
||||||
|
|
||||||
|
|
||||||
public interface IEnergyStorage {
|
|
||||||
|
|
||||||
int receiveEnergy(int var1, boolean var2);
|
|
||||||
|
|
||||||
int extractEnergy(int var1, boolean var2);
|
|
||||||
|
|
||||||
int getEnergyStored();
|
|
||||||
|
|
||||||
int getMaxEnergyStored();
|
|
||||||
}
|
|
|
@ -1,326 +0,0 @@
|
||||||
package universalelectricity.api;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/** A module to extend for compatibility with other energy systems. */
|
|
||||||
public abstract class CompatibilityModule
|
|
||||||
{
|
|
||||||
public static final Set<CompatibilityModule> loadedModules = new LinkedHashSet<>();
|
|
||||||
|
|
||||||
/** A cache to know which module to use with when facing objects with a specific class. */
|
|
||||||
public static final HashMap<Class<?>, CompatibilityModule> energyHandlerCache = new HashMap<>();
|
|
||||||
public static final HashMap<Class<?>, CompatibilityModule> energyStorageCache = new HashMap<>();
|
|
||||||
|
|
||||||
public static void register(CompatibilityModule module)
|
|
||||||
{
|
|
||||||
loadedModules.add(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Can the handler connect to this specific direction? */
|
|
||||||
public static boolean canConnect(Object handler, ForgeDirection direction, Object source)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doCanConnect(handler, direction, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the handler receive energy.
|
|
||||||
*
|
|
||||||
* @return The actual energy that was used.
|
|
||||||
*/
|
|
||||||
public static double receiveEnergy(Object handler, ForgeDirection direction, double energy, boolean doReceive)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doReceiveEnergy(handler, direction, energy, doReceive);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the handler extract energy.
|
|
||||||
*
|
|
||||||
* @return The actual energy that was extract.
|
|
||||||
*/
|
|
||||||
public static double extractEnergy(Object handler, ForgeDirection direction, double energy, boolean doExtract)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doExtractEnergy(handler, direction, energy, doExtract);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the energy stored in the handler.
|
|
||||||
*/
|
|
||||||
public static double getEnergy(Object handler, ForgeDirection direction)
|
|
||||||
{
|
|
||||||
if (isEnergyContainer(handler))
|
|
||||||
{
|
|
||||||
return energyStorageCache.get(handler.getClass()).doGetEnergy(handler, direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Charges an item
|
|
||||||
*
|
|
||||||
* @return The actual energy that was accepted.
|
|
||||||
*/
|
|
||||||
public static double chargeItem(ItemStack itemStack, double energy, boolean doCharge)
|
|
||||||
{
|
|
||||||
if (itemStack != null && isHandler(itemStack.getItem()))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(itemStack.getItem().getClass()).doChargeItem(itemStack, energy, doCharge);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Discharges an item
|
|
||||||
*
|
|
||||||
* @return The actual energy that was removed.
|
|
||||||
*/
|
|
||||||
public static double dischargeItem(ItemStack itemStack, double energy, boolean doCharge)
|
|
||||||
{
|
|
||||||
if (itemStack != null && isHandler(itemStack.getItem()))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(itemStack.getItem().getClass()).doDischargeItem(itemStack, energy, doCharge);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the itemStack with a specific charge.
|
|
||||||
*
|
|
||||||
* @return ItemStack of electrical/energy item.
|
|
||||||
*/
|
|
||||||
public static ItemStack getItemWithCharge(ItemStack itemStack, double energy)
|
|
||||||
{
|
|
||||||
if (itemStack != null && isHandler(itemStack.getItem()))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(itemStack.getItem().getClass()).doGetItemWithCharge(itemStack, energy);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this object a valid energy handler?
|
|
||||||
*
|
|
||||||
* @param True if the handler can store energy. This can be for items and blocks.
|
|
||||||
*/
|
|
||||||
public static boolean isHandler(Object handler)
|
|
||||||
{
|
|
||||||
if (handler != null)
|
|
||||||
{
|
|
||||||
Class clazz = handler.getClass();
|
|
||||||
|
|
||||||
if (energyHandlerCache.containsKey(clazz))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CompatibilityModule module : CompatibilityModule.loadedModules)
|
|
||||||
{
|
|
||||||
if (module.doIsHandler(handler))
|
|
||||||
{
|
|
||||||
energyHandlerCache.put(clazz, module);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this object able to store energy?
|
|
||||||
*
|
|
||||||
* @param handler
|
|
||||||
* @return True if the handler can store energy. The handler MUST be a block.
|
|
||||||
*/
|
|
||||||
public static boolean isEnergyContainer(Object handler)
|
|
||||||
{
|
|
||||||
if (handler != null)
|
|
||||||
{
|
|
||||||
Class clazz = handler.getClass();
|
|
||||||
|
|
||||||
if (energyStorageCache.containsKey(clazz))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CompatibilityModule module : CompatibilityModule.loadedModules)
|
|
||||||
{
|
|
||||||
if (module.doIsEnergyContainer(handler))
|
|
||||||
{
|
|
||||||
energyStorageCache.put(clazz, module);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blocks only
|
|
||||||
*/
|
|
||||||
public static double getMaxEnergy(Object handler, ForgeDirection direction)
|
|
||||||
{
|
|
||||||
if (isEnergyContainer(handler))
|
|
||||||
{
|
|
||||||
return energyStorageCache.get(handler.getClass()).doGetMaxEnergy(handler, direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getInputVoltage(Object handler)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doGetInputVoltage(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getOutputVoltage(Object handler)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doGetOutputVoltage(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canReceive(Object handler, ForgeDirection side)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doCanReceive(handler, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canExtract(Object handler, ForgeDirection side)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doCanExtract(handler, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getDemandedJoules(Object handler)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doGetDemandedJoules(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getProvidedJoules(Object handler)
|
|
||||||
{
|
|
||||||
if (isHandler(handler))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(handler.getClass()).doGetProvidedJoules(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getEnergyItem(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
if (itemStack != null && isHandler(itemStack.getItem()))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(itemStack.getItem().getClass()).doGetEnergyItem(itemStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getMaxEnergyItem(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
if (itemStack != null && isHandler(itemStack.getItem()))
|
|
||||||
{
|
|
||||||
return energyHandlerCache.get(itemStack.getItem().getClass()).doGetMaxEnergyItem(itemStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract double doReceiveEnergy(Object handler, ForgeDirection direction, double energy, boolean doReceive);
|
|
||||||
|
|
||||||
public abstract double doExtractEnergy(Object handler, ForgeDirection direction, double energy, boolean doExtract);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Charges an item with the given energy
|
|
||||||
*
|
|
||||||
* @param itemStack - item stack that is the item
|
|
||||||
* @param joules - input energy
|
|
||||||
* @param docharge - do the action
|
|
||||||
* @return amount of energy accepted
|
|
||||||
*/
|
|
||||||
public abstract double doChargeItem(ItemStack itemStack, double joules, boolean docharge);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* discharges an item with the given energy
|
|
||||||
*
|
|
||||||
* @param itemStack - item stack that is the item
|
|
||||||
* @param joules - input energy
|
|
||||||
* @param docharge - do the action
|
|
||||||
* @return amount of energy that was removed
|
|
||||||
*/
|
|
||||||
public abstract double doDischargeItem(ItemStack itemStack, double joules, boolean doDischarge);
|
|
||||||
|
|
||||||
public abstract boolean doIsHandler(Object obj);
|
|
||||||
|
|
||||||
public abstract boolean doIsEnergyContainer(Object obj);
|
|
||||||
|
|
||||||
public abstract double doGetEnergy(Object obj, ForgeDirection direction);
|
|
||||||
|
|
||||||
public abstract boolean doCanConnect(Object obj, ForgeDirection direction, Object source);
|
|
||||||
|
|
||||||
public abstract ItemStack doGetItemWithCharge(ItemStack itemStack, double energy);
|
|
||||||
|
|
||||||
public abstract double doGetMaxEnergy(Object handler, ForgeDirection direction);
|
|
||||||
|
|
||||||
public abstract double doGetEnergyItem(ItemStack is);
|
|
||||||
|
|
||||||
public abstract double doGetMaxEnergyItem(ItemStack is);
|
|
||||||
|
|
||||||
public abstract double doGetInputVoltage(Object handler);
|
|
||||||
|
|
||||||
public abstract double doGetOutputVoltage(Object handler);
|
|
||||||
|
|
||||||
public abstract boolean doCanReceive(Object handler, ForgeDirection side);
|
|
||||||
|
|
||||||
public abstract boolean doCanExtract(Object handler, ForgeDirection side);
|
|
||||||
|
|
||||||
public abstract double doGetDemandedJoules(Object handler);
|
|
||||||
|
|
||||||
public abstract double doGetProvidedJoules(Object handler);
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
package universalelectricity.api;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.Loader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ORDER OF MAGNITUDE:
|
|
||||||
* A coal in Universal Electricity (based on an estimate in real life) is worth 4MJ.
|
|
||||||
* A fission reactor should make around 4-9GW.
|
|
||||||
* A fusion reactor would go into the tera-watts.
|
|
||||||
* Reika's conversion: IC2[22512], BC[56280], RF[5628]
|
|
||||||
* @author Calclavia
|
|
||||||
*/
|
|
||||||
public enum CompatibilityType
|
|
||||||
{
|
|
||||||
REDSTONE_FLUX("universalelectricity", "RedstoneFlux", "Redstone Flux", "RF", 2.5),
|
|
||||||
INDUSTRIALCRAFT("IC2", "IndustrialCraft", "Electrical Unit", "EU", 10);
|
|
||||||
|
|
||||||
public final String modID;
|
|
||||||
public final String moduleName;
|
|
||||||
public final String fullUnit;
|
|
||||||
public final String unit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Multiply UE energy by this ratio to convert it to the forgien ratio.
|
|
||||||
*/
|
|
||||||
public double ratio;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Multiply the forgien energy by this ratio to convert it into UE energy.
|
|
||||||
*/
|
|
||||||
public double reciprocal_ratio;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Universal Electricity Loader will change this value to indicate if the module is
|
|
||||||
* loaded or not.
|
|
||||||
*/
|
|
||||||
public boolean isModuleEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param modID - The Forge mod ID.
|
|
||||||
* @param moduleName - The name of the module, used for config and ASM
|
|
||||||
* @param fullUnit - The unit used
|
|
||||||
* @param unit - The unit short form used
|
|
||||||
* @param ratio - How much UE energy equates to the forgien energy?
|
|
||||||
*/
|
|
||||||
CompatibilityType(String modID, String moduleName, String fullUnit, String unit, double ratio)
|
|
||||||
{
|
|
||||||
this.modID = modID;
|
|
||||||
this.moduleName = moduleName;
|
|
||||||
this.fullUnit = fullUnit;
|
|
||||||
this.unit = unit;
|
|
||||||
this.ratio = 1.0 / ratio;
|
|
||||||
this.reciprocal_ratio = ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLoaded()
|
|
||||||
{
|
|
||||||
return Loader.isModLoaded(this.modID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompatibilityType get(String moduleName)
|
|
||||||
{
|
|
||||||
for (CompatibilityType type : values())
|
|
||||||
{
|
|
||||||
if (moduleName.equals(type.moduleName))
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double fromJoules(double joules) {
|
|
||||||
return this.ratio * joules;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double toJoules(double energy) {
|
|
||||||
return this.reciprocal_ratio * energy;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package universalelectricity.api.electricity;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import universalelectricity.api.energy.IEnergyNetwork;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extended version of the energy network that properly implements amperage and voltage.
|
|
||||||
* If you want amps get last buffer and divide it by the voltage
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman
|
|
||||||
*/
|
|
||||||
public interface IElectricalNetwork extends IEnergyNetwork
|
|
||||||
{
|
|
||||||
/** Gets the current voltage of the network at this point. */
|
|
||||||
public double getVoltage();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package universalelectricity.api.electricity;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implement this on your TileEntity if it has a voltage based energy input. You machine will still
|
|
||||||
* need to run its own voltage checks as this doesn't do anything on its own.
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman
|
|
||||||
*/
|
|
||||||
public interface IVoltageInput
|
|
||||||
{
|
|
||||||
/** Voltage input on the side mainly used for meters */
|
|
||||||
public double getVoltageInput(ForgeDirection direction);
|
|
||||||
|
|
||||||
/** Called when the network voltage doesn't equal the input */
|
|
||||||
public void onWrongVoltage(ForgeDirection direction, double voltage);
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package universalelectricity.api.electricity;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applied to electrical machines that are designed to act as sources of power in an electrical
|
|
||||||
* network. Mainly used to calculate the over all voltage of a network correctly.
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman
|
|
||||||
*/
|
|
||||||
public interface IVoltageOutput
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Can this machine emit voltage on the given side.
|
|
||||||
*
|
|
||||||
* @param side - side that the voltage will be emitted on
|
|
||||||
* @return the voltage emitted
|
|
||||||
*/
|
|
||||||
public double getVoltageOutput(ForgeDirection side);
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A dynamic network loader for injecting energy networks (NOT for other networks such as fuild
|
|
||||||
* networks).
|
|
||||||
* Example usage would be that ElectricityNetwork replaces EnergyNetwork.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EnergyNetworkLoader
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The default IElectricityNetwork used for primary energy networks.
|
|
||||||
*/
|
|
||||||
public static Class<? extends IEnergyNetwork> NETWORK_CLASS;
|
|
||||||
public static final Set<Class<? extends IEnergyNetwork>> NETWORK_CLASS_REGISTRY = new HashSet<Class<? extends IEnergyNetwork>>();
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
setNetworkClass("universalelectricity.core.net.ElectricalNetwork");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setNetworkClass(Class<? extends IEnergyNetwork> networkClass)
|
|
||||||
{
|
|
||||||
NETWORK_CLASS_REGISTRY.add(networkClass);
|
|
||||||
NETWORK_CLASS = networkClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setNetworkClass(String className)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
setNetworkClass((Class<? extends IEnergyNetwork>) Class.forName(className));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
FMLLog.severe("Universal Electricity: Failed to set network class with name " + className);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnergyNetwork getNewNetwork(IConductor... conductors)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IEnergyNetwork network = NETWORK_CLASS.newInstance();
|
|
||||||
network.getConnectors().addAll(Arrays.asList(conductors));
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
catch (InstantiationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,268 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagDouble;
|
|
||||||
import net.minecraft.nbt.NBTTagFloat;
|
|
||||||
import net.minecraft.nbt.NBTTagInt;
|
|
||||||
import net.minecraft.nbt.NBTTagLong;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can be used internally for IEnergyInterface blocks. This is optional and should be used for
|
|
||||||
* ease of use purposes.
|
|
||||||
*
|
|
||||||
* @author Calclavia, Based on Thermal Expansion
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EnergyStorageHandler
|
|
||||||
{
|
|
||||||
protected long energy;
|
|
||||||
protected long capacity;
|
|
||||||
protected long maxReceive;
|
|
||||||
protected long maxExtract;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A cache of the last energy stored through extract and receive.
|
|
||||||
*/
|
|
||||||
protected long lastEnergy;
|
|
||||||
|
|
||||||
public EnergyStorageHandler()
|
|
||||||
{
|
|
||||||
this(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyStorageHandler(long capacity)
|
|
||||||
{
|
|
||||||
this(capacity, capacity, capacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyStorageHandler(long capacity, long maxTransfer)
|
|
||||||
{
|
|
||||||
this(capacity, maxTransfer, maxTransfer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyStorageHandler(long capacity, long maxReceive, long maxExtract)
|
|
||||||
{
|
|
||||||
this.capacity = capacity;
|
|
||||||
this.maxReceive = maxReceive;
|
|
||||||
this.maxExtract = maxExtract;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyStorageHandler readFromNBT(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
NBTBase energyTag = nbt.getTag("energy");
|
|
||||||
if (energyTag instanceof NBTTagDouble)
|
|
||||||
{
|
|
||||||
this.energy = (long) ((NBTTagDouble) energyTag).func_150286_g();
|
|
||||||
}
|
|
||||||
else if (energyTag instanceof NBTTagFloat)
|
|
||||||
{
|
|
||||||
this.energy = (long) ((NBTTagFloat) energyTag).func_150288_h();
|
|
||||||
}
|
|
||||||
else if (energyTag instanceof NBTTagInt)
|
|
||||||
{
|
|
||||||
this.energy = ((NBTTagInt) energyTag).func_150287_d();
|
|
||||||
}
|
|
||||||
else if (energyTag instanceof NBTTagLong)
|
|
||||||
{
|
|
||||||
this.energy = ((NBTTagLong) energyTag).func_150291_c();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
nbt.setLong("energy", this.getEnergy());
|
|
||||||
return nbt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCapacity(long capacity)
|
|
||||||
{
|
|
||||||
this.capacity = capacity;
|
|
||||||
|
|
||||||
if (getEnergy() > capacity)
|
|
||||||
{
|
|
||||||
energy = capacity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxTransfer(long maxTransfer)
|
|
||||||
{
|
|
||||||
setMaxReceive(maxTransfer);
|
|
||||||
setMaxExtract(maxTransfer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxReceive(long maxReceive)
|
|
||||||
{
|
|
||||||
this.maxReceive = maxReceive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxExtract(long maxExtract)
|
|
||||||
{
|
|
||||||
this.maxExtract = maxExtract;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMaxReceive()
|
|
||||||
{
|
|
||||||
return maxReceive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long 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 setEnergy(long energy)
|
|
||||||
{
|
|
||||||
this.energy = energy;
|
|
||||||
|
|
||||||
if (this.getEnergy() > this.getEnergyCapacity())
|
|
||||||
{
|
|
||||||
this.energy = this.getEnergyCapacity();
|
|
||||||
}
|
|
||||||
else if (this.getEnergy() < 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(long energy)
|
|
||||||
{
|
|
||||||
this.setEnergy(this.getEmptySpace() + energy);
|
|
||||||
|
|
||||||
if (this.getEnergy() > this.getEnergyCapacity())
|
|
||||||
{
|
|
||||||
this.setEnergy(this.getEnergyCapacity());
|
|
||||||
}
|
|
||||||
else if (this.getEnergy() < 0)
|
|
||||||
{
|
|
||||||
this.setEnergy(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long receiveEnergy(long receive, boolean doReceive)
|
|
||||||
{
|
|
||||||
long energyReceived = Math.min(this.getEnergyCapacity() - this.getEnergy(), Math.min(this.getMaxReceive(), receive));
|
|
||||||
|
|
||||||
if (doReceive)
|
|
||||||
{
|
|
||||||
this.lastEnergy = this.getEnergy();
|
|
||||||
this.setEnergy(this.getEnergy() + energyReceived);
|
|
||||||
}
|
|
||||||
return energyReceived;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long receiveEnergy(boolean doReceive)
|
|
||||||
{
|
|
||||||
return this.receiveEnergy(this.getMaxReceive(), doReceive);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long receiveEnergy()
|
|
||||||
{
|
|
||||||
return this.receiveEnergy(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long extractEnergy(long extract, boolean doExtract)
|
|
||||||
{
|
|
||||||
long energyExtracted = Math.min(this.getEnergy(), Math.min(this.getMaxExtract(), extract));
|
|
||||||
|
|
||||||
if (doExtract)
|
|
||||||
{
|
|
||||||
this.lastEnergy = this.getEnergy();
|
|
||||||
this.setEnergy(this.getEnergy() - energyExtracted);
|
|
||||||
}
|
|
||||||
return energyExtracted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long extractEnergy(boolean doExtract)
|
|
||||||
{
|
|
||||||
return this.extractEnergy(this.getMaxExtract(), doExtract);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long extractEnergy()
|
|
||||||
{
|
|
||||||
return this.extractEnergy(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkReceive(long receive)
|
|
||||||
{
|
|
||||||
return this.receiveEnergy(receive, false) >= receive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkReceive()
|
|
||||||
{
|
|
||||||
return this.checkReceive(this.getMaxReceive());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkExtract(long extract)
|
|
||||||
{
|
|
||||||
return this.extractEnergy(extract, false) >= extract;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkExtract()
|
|
||||||
{
|
|
||||||
return this.checkExtract(this.getMaxExtract());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFull()
|
|
||||||
{
|
|
||||||
return this.getEnergy() >= this.getEnergyCapacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty()
|
|
||||||
{
|
|
||||||
return this.getEnergy() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastEnergy()
|
|
||||||
{
|
|
||||||
return this.lastEnergy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return True if the last energy state and the current one are either in an
|
|
||||||
* "empty or not empty" change state.
|
|
||||||
*/
|
|
||||||
public boolean didEnergyStateChange()
|
|
||||||
{
|
|
||||||
return (this.getLastEnergy() == 0 && this.getEnergy() > 0) || (this.getLastEnergy() > 0 && this.getEnergy() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the amount of energy this storage can further store.
|
|
||||||
*/
|
|
||||||
public long getEmptySpace()
|
|
||||||
{
|
|
||||||
return this.getEnergyCapacity() - this.getEnergy();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEnergy()
|
|
||||||
{
|
|
||||||
return this.energy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEnergyCapacity()
|
|
||||||
{
|
|
||||||
return this.capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return this.getClass().getSimpleName() + "[" + this.getEnergy() + "/" + this.getEnergyCapacity() + "]";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
import universalelectricity.api.net.IConnector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A connector for {EnergyNetwork}.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*/
|
|
||||||
public interface IConductor extends IConnector<IEnergyNetwork>, IEnergyInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Gets the amount of resistance of energy conducting pass this conductor.
|
|
||||||
*
|
|
||||||
* @return The amount of loss in Ohms.
|
|
||||||
*/
|
|
||||||
public double getResistance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum amount of current this conductor can buffer (the transfer rate, essentially). You
|
|
||||||
* can simply do divide your energy transfer rate by UniversalElectricity.DEFAULT_VOLTAGE if
|
|
||||||
* your conductor is not voltage sensitive.
|
|
||||||
*
|
|
||||||
* @return The amount of current in amperes.
|
|
||||||
*/
|
|
||||||
public double getCurrentCapacity();
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface is to be applied to all TileEntities which can store energy.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*/
|
|
||||||
public interface IEnergyContainer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Sets the amount of energy this unit stored.
|
|
||||||
*
|
|
||||||
* This function is NOT recommended for calling.
|
|
||||||
*/
|
|
||||||
public void setEnergy(ForgeDirection from, double energy);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * @return Get the amount of energy currently stored in the block.
|
|
||||||
*/
|
|
||||||
public double getEnergy(ForgeDirection from);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Get the max amount of energy that can be stored in the block.
|
|
||||||
*/
|
|
||||||
public double getEnergyCapacity(ForgeDirection from);
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.net.IConnectable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applied to all TileEntities that can interact with energy.
|
|
||||||
*
|
|
||||||
* @author Calclavia, Inspired by Thermal Expansion
|
|
||||||
*/
|
|
||||||
public interface IEnergyInterface extends IConnectable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Adds energy to a block. Returns the quantity of energy that was accepted. This should always
|
|
||||||
* return 0 if the block cannot be externally charged.
|
|
||||||
*
|
|
||||||
* @param from Orientation the energy is sent in from.
|
|
||||||
* @param receive Maximum amount of energy (joules) 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 double onReceiveEnergy(ForgeDirection from, double receive, boolean doReceive);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes energy from a block. Returns the quantity of energy that was extracted. This should
|
|
||||||
* always return 0 if the block cannot be externally discharged.
|
|
||||||
*
|
|
||||||
* @param from Orientation the energy is requested from. This direction MAY be passed as
|
|
||||||
* "Unknown" if it is wrapped from another energy system that has no clear way to find
|
|
||||||
* direction. (e.g BuildCraft 4)
|
|
||||||
* @param energy Maximum amount of energy to be sent into the block.
|
|
||||||
* @param doExtract If false, the charge will only be simulated.
|
|
||||||
* @return Amount of energy that was given out by the block.
|
|
||||||
*/
|
|
||||||
public double onExtractEnergy(ForgeDirection from, double extract, boolean doExtract);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.net.INodeNetwork;
|
|
||||||
import universalelectricity.api.net.IUpdate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Energy Network for energy items and blocks.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*/
|
|
||||||
public interface IEnergyNetwork extends INodeNetwork<IEnergyNetwork, IConductor, Object>, IUpdate
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Produces power to the energy network.
|
|
||||||
*
|
|
||||||
* @param conductor - The conductor that is producing into the energy.
|
|
||||||
* @param side - The direction the source is producing out towards.
|
|
||||||
* @param receive - The amount that is produced.
|
|
||||||
* @return The amount that was accepted by the network.
|
|
||||||
*/
|
|
||||||
public double produce(IConductor conductor, ForgeDirection from, double amount, boolean doProduce);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The current buffer in the network that is going sent to all energy handlers.
|
|
||||||
*/
|
|
||||||
public double getBuffer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The last buffer in the network that was sent to all energy handlers.
|
|
||||||
*/
|
|
||||||
public double getLastBuffer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an estimated value of what the network wants for energy
|
|
||||||
*/
|
|
||||||
public double getRequest();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a value that represents the amount of energy lost in the network
|
|
||||||
*/
|
|
||||||
public double getResistance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by conductors to load their internal buffers to the network. This should be called when
|
|
||||||
* reading NBT data.
|
|
||||||
*
|
|
||||||
* @param conductor
|
|
||||||
*/
|
|
||||||
public double getBufferOf(IConductor conductor);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by conductors to load their internal buffers to the network. This should be called when
|
|
||||||
* writing NBT data.
|
|
||||||
*
|
|
||||||
* @param conductor
|
|
||||||
*/
|
|
||||||
public void setBufferFor(IConductor conductor, double buffer);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the buffer of the network.
|
|
||||||
*
|
|
||||||
* @param newBuffer
|
|
||||||
*/
|
|
||||||
public void setBuffer(double newBuffer);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,217 +0,0 @@
|
||||||
package universalelectricity.api.energy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An easy way to display information on electricity for the client.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*/
|
|
||||||
public class UnitDisplay
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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 Unit
|
|
||||||
{
|
|
||||||
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"), LITER("Liter", "L"), NEWTON_METER("Newton Meter", "Nm"),
|
|
||||||
REDFLUX("Redstone-Flux", "Rf"), ELECTRICAL_UNITS("Electrical-Units", "Eu");
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
public String symbol;
|
|
||||||
|
|
||||||
private Unit(String name, String symbol)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.symbol = symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlural()
|
|
||||||
{
|
|
||||||
return this.name + "s";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Metric system of measurement. */
|
|
||||||
public static enum UnitPrefix
|
|
||||||
{
|
|
||||||
MICRO("Micro", "u", 0.000001), MILLI("Milli", "m", 0.001), BASE("", "", 1),
|
|
||||||
KILO("Kilo", "k", 1000), MEGA("Mega", "M", 1000000), GIGA("Giga", "G", 1000000000),
|
|
||||||
TERA("Tera", "T", 1000000000000d), PETA("Peta", "P", 1000000000000000d),
|
|
||||||
EXA("Exa", "E", 1000000000000000000d), ZETTA("Zetta", "Z", 1000000000000000000000d),
|
|
||||||
YOTTA("Yotta", "Y", 1000000000000000000000000d);
|
|
||||||
|
|
||||||
/** 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 double value;
|
|
||||||
|
|
||||||
private UnitPrefix(String name, String symbol, double 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(double value)
|
|
||||||
{
|
|
||||||
return value > this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Checks if a value is lower than the unit value start */
|
|
||||||
public boolean isBellow(double value)
|
|
||||||
{
|
|
||||||
return value < this.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplay(double value, Unit unit, int decimalPlaces, boolean isShort)
|
|
||||||
{
|
|
||||||
return getDisplay(value, unit, decimalPlaces, isShort, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(double value, Unit unit, int decimalPlaces, boolean isShort, double 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 < UnitPrefix.values().length; i++)
|
|
||||||
{
|
|
||||||
UnitPrefix lowerMeasure = UnitPrefix.values()[i];
|
|
||||||
|
|
||||||
if (lowerMeasure.isBellow(value) && lowerMeasure.ordinal() == 0)
|
|
||||||
{
|
|
||||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
|
||||||
}
|
|
||||||
if (lowerMeasure.ordinal() + 1 >= UnitPrefix.values().length)
|
|
||||||
{
|
|
||||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
|
||||||
}
|
|
||||||
|
|
||||||
UnitPrefix upperMeasure = UnitPrefix.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(double value, Unit unit)
|
|
||||||
{
|
|
||||||
return getDisplay(value, unit, 2, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplay(double value, Unit unit, UnitPrefix prefix)
|
|
||||||
{
|
|
||||||
return getDisplay(value, unit, 2, false, prefix.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplayShort(double value, Unit unit)
|
|
||||||
{
|
|
||||||
return getDisplay(value, unit, 2, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a display for the value with a unit that is in the specific prefix.
|
|
||||||
*/
|
|
||||||
public static String getDisplayShort(double value, Unit unit, UnitPrefix prefix)
|
|
||||||
{
|
|
||||||
return getDisplay(value, unit, 2, true, prefix.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplayShort(double value, Unit unit, int decimalPlaces)
|
|
||||||
{
|
|
||||||
return getDisplay(value, unit, decimalPlaces, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplaySimple(double value, Unit 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,47 +0,0 @@
|
||||||
package universalelectricity.api.item;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public interface IEnergyItem
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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 double recharge(ItemStack itemStack, double 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 double discharge(ItemStack itemStack, double energy, boolean doDischarge);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the amount of energy currently stored in the item.
|
|
||||||
*/
|
|
||||||
public double getEnergy(ItemStack theItem);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the max amount of energy that can be stored in the item.
|
|
||||||
*/
|
|
||||||
public double getEnergyCapacity(ItemStack theItem);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the amount of energy in the ItemStack. Use recharge or discharge instead of calling this
|
|
||||||
* to be safer!
|
|
||||||
*
|
|
||||||
* @param itemStack - the ItemStack.
|
|
||||||
* @param energy - Amount of electrical energy.
|
|
||||||
*/
|
|
||||||
public void setEnergy(ItemStack itemStack, double energy);
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package universalelectricity.api.item;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IVoltageItem
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the max amount of voltage of this item.
|
|
||||||
*/
|
|
||||||
public double getVoltage(ItemStack theItem);
|
|
||||||
}
|
|
|
@ -1,155 +0,0 @@
|
||||||
package universalelectricity.api.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.NBTTagFloat;
|
|
||||||
import net.minecraft.nbt.NBTTagDouble;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.api.CompatibilityModule;
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
|
||||||
import universalelectricity.api.energy.UnitDisplay;
|
|
||||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
|
||||||
|
|
||||||
/** 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 IEnergyItem, IVoltageItem
|
|
||||||
{
|
|
||||||
private static final String ENERGY_NBT = "electricity";
|
|
||||||
|
|
||||||
public ItemElectric()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
setMaxStackSize(1);
|
|
||||||
setMaxDamage(100);
|
|
||||||
setNoRepair();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
|
|
||||||
{
|
|
||||||
String color = "";
|
|
||||||
double joules = getEnergy(itemStack);
|
|
||||||
|
|
||||||
if (joules <= getEnergyCapacity(itemStack) / 3)
|
|
||||||
{
|
|
||||||
color = "\u00a74";
|
|
||||||
}
|
|
||||||
else if (joules > getEnergyCapacity(itemStack) * 2 / 3)
|
|
||||||
{
|
|
||||||
color = "\u00a72";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
color = "\u00a76";
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
* not want this to happen! */
|
|
||||||
@Override
|
|
||||||
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
||||||
{
|
|
||||||
setEnergy(itemStack, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double recharge(ItemStack itemStack, double energy, boolean doReceive)
|
|
||||||
{
|
|
||||||
double energyReceived = Math.min(getEnergyCapacity(itemStack) - getEnergy(itemStack), Math.min(getTransferRate(itemStack), energy));
|
|
||||||
|
|
||||||
if (doReceive)
|
|
||||||
{
|
|
||||||
setEnergy(itemStack, getEnergy(itemStack) + energyReceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
return energyReceived;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getTransferRate(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
return getEnergyCapacity(itemStack) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double discharge(ItemStack itemStack, double energy, boolean doTransfer)
|
|
||||||
{
|
|
||||||
double energyExtracted = Math.min(getEnergy(itemStack), Math.min(getTransferRate(itemStack), energy));
|
|
||||||
|
|
||||||
if (doTransfer)
|
|
||||||
{
|
|
||||||
setEnergy(itemStack, getEnergy(itemStack) - energyExtracted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return energyExtracted;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getVoltage(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
return 120.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEnergy(ItemStack itemStack, double joules)
|
|
||||||
{
|
|
||||||
if (itemStack.getTagCompound() == null)
|
|
||||||
{
|
|
||||||
itemStack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
double electricityStored = Math.max(Math.min(joules, getEnergyCapacity(itemStack)), 0);
|
|
||||||
itemStack.getTagCompound().setDouble(ENERGY_NBT, electricityStored);
|
|
||||||
itemStack.setItemDamage((int) (100 - ((double) electricityStored / (double) getEnergyCapacity(itemStack)) * 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getTransfer(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
return getEnergyCapacity(itemStack) - getEnergy(itemStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getEnergy(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
if (itemStack.getTagCompound() == null)
|
|
||||||
{
|
|
||||||
itemStack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
double energyStored = 0;
|
|
||||||
|
|
||||||
if (itemStack.getTagCompound().hasKey(ENERGY_NBT))
|
|
||||||
{
|
|
||||||
// Backwards compatibility
|
|
||||||
NBTBase obj = itemStack.getTagCompound().getTag(ENERGY_NBT);
|
|
||||||
|
|
||||||
if (obj instanceof NBTTagFloat)
|
|
||||||
{
|
|
||||||
energyStored = ((NBTTagFloat) obj).func_150286_g();
|
|
||||||
}
|
|
||||||
else if (obj instanceof NBTTagDouble)
|
|
||||||
{
|
|
||||||
energyStored = ((NBTTagDouble) obj).func_150286_g();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
itemStack.setItemDamage((int) (100 - ((double) energyStored / (double) getEnergyCapacity(itemStack)) * 100));
|
|
||||||
return energyStored;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List)
|
|
||||||
{
|
|
||||||
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this), 0));
|
|
||||||
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this), getEnergyCapacity(new ItemStack(this))));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IConnectable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Can this object connect with another?
|
|
||||||
*
|
|
||||||
* @param from - The direction the connection is coming from.
|
|
||||||
* @param source - The source calling canConnect onto this object.
|
|
||||||
* @return Return true, if the connection is possible.
|
|
||||||
*/
|
|
||||||
public boolean canConnect(ForgeDirection from, Object source);
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applied to TileEntities that has an instance of an electricity network.
|
|
||||||
*
|
|
||||||
* @author Calclavia, tilera
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IConnector<N> extends INetworkProvider<N>, IConnectable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Gets an array of all the connected IConnecables that this connector is connected to. This
|
|
||||||
* should correspond to the ForgeDirection index.
|
|
||||||
*
|
|
||||||
* @return An array of length "6".
|
|
||||||
*/
|
|
||||||
public TileEntity[] getAdjacentConnections();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets this connector instance. Used specially for MultiPart connections.
|
|
||||||
*
|
|
||||||
* @return The instance, in most cases, just return "this".
|
|
||||||
*/
|
|
||||||
public IConnector<N> getInstance(ForgeDirection dir);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A network with connectors only.
|
|
||||||
*/
|
|
||||||
public interface INetwork<N extends INetwork, C extends IConnector>
|
|
||||||
{
|
|
||||||
public void addConnector(C connector);
|
|
||||||
|
|
||||||
public void removeConnector(C connector);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the set of conductors that make up this network.
|
|
||||||
*
|
|
||||||
* @return conductor set
|
|
||||||
*/
|
|
||||||
public Set<C> getConnectors();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reconstructs the network and all objects within it.
|
|
||||||
*/
|
|
||||||
public void reconstruct();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* @return The new network instance.
|
|
||||||
*/
|
|
||||||
public N merge(N network);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits a network by removing a conductor referenced in the parameter. It will then create and
|
|
||||||
* refresh the new independent networks possibly created by this operation.
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
public void split(C connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits the network between 2 connectors, separating their networks.
|
|
||||||
*
|
|
||||||
* @param connectorA
|
|
||||||
* @param connectorB
|
|
||||||
*/
|
|
||||||
public void split(C connectorA, C connectorB);
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applied to TileEntities that has an instance of an electricity network.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface INetworkProvider<N>
|
|
||||||
{
|
|
||||||
public N getNetwork();
|
|
||||||
|
|
||||||
public void setNetwork(N network);
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A network of with connectors and individual nodes.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
* @param <N> - the class/interface Type value in which you implement this
|
|
||||||
* @param <C> - the class/interface Type which makes up the network's connector set
|
|
||||||
* @param <A> - the class/interface Type which makes up the network's node set
|
|
||||||
*/
|
|
||||||
public interface INodeNetwork<N extends INodeNetwork, C extends IConnector, A> extends INetwork<N, C>
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The nodes in a network are the objects that interact with the connectors.
|
|
||||||
*
|
|
||||||
* @return The list of nodes in the network.
|
|
||||||
*/
|
|
||||||
public Set<A> getNodes();
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
public interface IUpdate
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Updates the network. Called by the {NetworkTickHandler}.
|
|
||||||
*/
|
|
||||||
public void update();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can the network update?
|
|
||||||
*
|
|
||||||
* @return True if the network can update, otherwise the network tick handler will remove the
|
|
||||||
* network from the tick list.
|
|
||||||
*/
|
|
||||||
public boolean canUpdate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return True to leave the network in the ticker. False to remove the network from the ticker.
|
|
||||||
*/
|
|
||||||
public boolean continueUpdate();
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package universalelectricity.api.net;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
|
||||||
import cpw.mods.fml.common.eventhandler.Event;
|
|
||||||
import universalelectricity.api.energy.IEnergyNetwork;
|
|
||||||
|
|
||||||
public class NetworkEvent extends Event
|
|
||||||
{
|
|
||||||
public final IEnergyNetwork network;
|
|
||||||
|
|
||||||
public NetworkEvent(IEnergyNetwork network)
|
|
||||||
{
|
|
||||||
this.network = network;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this to have your TileEntity produce power into the network.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Cancelable
|
|
||||||
public static class EnergyProduceEvent extends NetworkEvent
|
|
||||||
{
|
|
||||||
private Object source;
|
|
||||||
private long amount;
|
|
||||||
private boolean doReceive;
|
|
||||||
|
|
||||||
public EnergyProduceEvent(IEnergyNetwork network, Object source, long amount, boolean doReceive)
|
|
||||||
{
|
|
||||||
super(network);
|
|
||||||
this.source = source;
|
|
||||||
this.amount = amount;
|
|
||||||
this.doReceive = doReceive;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* These events are fired when something happens in the network.
|
|
||||||
*
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Cancelable
|
|
||||||
public static class EnergyUpdateEvent extends NetworkEvent
|
|
||||||
{
|
|
||||||
public EnergyUpdateEvent(IEnergyNetwork network)
|
|
||||||
{
|
|
||||||
super(network);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package universalelectricity.compat;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
|
||||||
import cpw.mods.fml.common.Loader;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import universalelectricity.api.CompatibilityModule;
|
|
||||||
import universalelectricity.compat.ic2.IC2CompatModule;
|
|
||||||
import universalelectricity.prefab.tile.ElectricTileDriver;
|
|
||||||
|
|
||||||
public class CompatHandler {
|
|
||||||
|
|
||||||
static Map<TileEntity, ElectricTileDriver> ticklist = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public static void initCompatHandlers() {
|
|
||||||
FMLCommonHandler.instance().bus().register(new CompatTickHandler());
|
|
||||||
if (Loader.isModLoaded("IC2")) {
|
|
||||||
CompatibilityModule.register(new IC2CompatModule());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tick() {
|
|
||||||
for(TileEntity t : ticklist.keySet()) {
|
|
||||||
ElectricTileDriver driver = ticklist.get(t);
|
|
||||||
if (!driver.tick()) {
|
|
||||||
System.out.println("Remove driver for tile at x:" + t.xCoord + " y:" + t.yCoord + " z:" + t.zCoord);
|
|
||||||
ticklist.remove(t);
|
|
||||||
driver.invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerTile(TileEntity tile) {
|
|
||||||
if (!ticklist.containsKey(tile) && CompatibilityModule.isHandler(tile)) {
|
|
||||||
ticklist.put(tile, new ElectricTileDriver(tile));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package universalelectricity.compat;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
|
||||||
|
|
||||||
public class CompatTickHandler {
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onTick(ServerTickEvent event) {
|
|
||||||
if (event.phase == Phase.END) {
|
|
||||||
CompatHandler.tick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,242 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
import ic2.api.energy.EnergyNet;
|
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
|
||||||
import ic2.api.energy.tile.IEnergySource;
|
|
||||||
import ic2.api.energy.tile.IEnergyTile;
|
|
||||||
import ic2.api.item.ElectricItem;
|
|
||||||
import ic2.api.item.IElectricItem;
|
|
||||||
import ic2.api.tile.IEnergyStorage;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.CompatibilityModule;
|
|
||||||
import universalelectricity.api.CompatibilityType;
|
|
||||||
|
|
||||||
public class IC2CompatModule extends CompatibilityModule {
|
|
||||||
|
|
||||||
private TileEntity getENetTile(Object handler) {
|
|
||||||
if (handler instanceof TileEntity) {
|
|
||||||
TileEntity te = (TileEntity) handler;
|
|
||||||
if (te instanceof IEnergyTile) {
|
|
||||||
return te;
|
|
||||||
}
|
|
||||||
return EnergyNet.instance.getTileEntity(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doReceiveEnergy(Object handler, ForgeDirection direction, double energy, boolean doReceive) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
|
|
||||||
if (tile instanceof IEnergySink) {
|
|
||||||
IEnergySink sink = (IEnergySink) tile;
|
|
||||||
double demand = sink.getDemandedEnergy();
|
|
||||||
double toReceive = Math.min(demand, CompatibilityType.INDUSTRIALCRAFT.fromJoules(energy));
|
|
||||||
|
|
||||||
if (doReceive) {
|
|
||||||
double leftover = sink.injectEnergy(direction, toReceive, 1);
|
|
||||||
return CompatibilityType.INDUSTRIALCRAFT.toJoules(Math.max(0, toReceive - leftover));
|
|
||||||
}
|
|
||||||
|
|
||||||
return CompatibilityType.INDUSTRIALCRAFT.toJoules(toReceive);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doExtractEnergy(Object handler, ForgeDirection direction, double energy, boolean doExtract) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
if (tile instanceof IEnergySource)
|
|
||||||
{
|
|
||||||
double demand = Math.min(((IEnergySource) tile).getOfferedEnergy(), energy * CompatibilityType.INDUSTRIALCRAFT.ratio);
|
|
||||||
|
|
||||||
if (doExtract)
|
|
||||||
{
|
|
||||||
((IEnergySource) tile).drawEnergy(demand);
|
|
||||||
}
|
|
||||||
|
|
||||||
return demand * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doChargeItem(ItemStack itemStack, double joules, boolean docharge) {
|
|
||||||
if (itemStack.getItem() instanceof IElectricItem)
|
|
||||||
{
|
|
||||||
return (ElectricItem.manager.charge(itemStack, joules * CompatibilityType.INDUSTRIALCRAFT.ratio, 4, true, !docharge) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doDischargeItem(ItemStack itemStack, double joules, boolean doDischarge) {
|
|
||||||
if (itemStack.getItem() instanceof IElectricItem)
|
|
||||||
{
|
|
||||||
IElectricItem item = (IElectricItem) itemStack.getItem();
|
|
||||||
|
|
||||||
if (item.canProvideEnergy(itemStack))
|
|
||||||
{
|
|
||||||
return (long) (ElectricItem.manager.discharge(itemStack, joules * CompatibilityType.INDUSTRIALCRAFT.ratio, 4, true, false, !doDischarge) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doIsHandler(Object obj) {
|
|
||||||
return getENetTile(obj) != null || obj instanceof IElectricItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doIsEnergyContainer(Object obj) {
|
|
||||||
TileEntity tile = getENetTile(obj);
|
|
||||||
return tile instanceof IEnergyStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetEnergy(Object obj, ForgeDirection direction) {
|
|
||||||
TileEntity tile = getENetTile(obj);
|
|
||||||
|
|
||||||
if (tile instanceof IEnergyStorage) {
|
|
||||||
return CompatibilityType.INDUSTRIALCRAFT.toJoules(((IEnergyStorage)tile).getStored());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doCanConnect(Object obj, ForgeDirection direction, Object source) {
|
|
||||||
TileEntity tile = getENetTile(obj);
|
|
||||||
|
|
||||||
if (tile instanceof IEnergySink)
|
|
||||||
{
|
|
||||||
if (((IEnergySink) tile).acceptsEnergyFrom((TileEntity) source, direction))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tile instanceof IEnergySource)
|
|
||||||
{
|
|
||||||
if (((IEnergySource) tile).emitsEnergyTo((TileEntity) source, direction))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack doGetItemWithCharge(ItemStack itemStack, double energy) {
|
|
||||||
ItemStack is = itemStack.copy();
|
|
||||||
|
|
||||||
ElectricItem.manager.discharge(is, Integer.MAX_VALUE, 1, true, false, false);
|
|
||||||
ElectricItem.manager.charge(is, (int) (energy * CompatibilityType.INDUSTRIALCRAFT.ratio), 1, true, false);
|
|
||||||
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetMaxEnergy(Object handler, ForgeDirection direction) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
|
|
||||||
if (tile instanceof IEnergyStorage) {
|
|
||||||
return CompatibilityType.INDUSTRIALCRAFT.toJoules(((IEnergyStorage)tile).getCapacity());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetEnergyItem(ItemStack is) {
|
|
||||||
return ElectricItem.manager.getCharge(is) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetMaxEnergyItem(ItemStack is) {
|
|
||||||
return ((IElectricItem) is.getItem()).getMaxCharge(is) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetInputVoltage(Object handler) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
|
|
||||||
if (tile instanceof IEnergySink) {
|
|
||||||
return tierToVolt(((IEnergySink)tile).getSinkTier());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetOutputVoltage(Object handler) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
|
|
||||||
if (tile instanceof IEnergySource) {
|
|
||||||
return tierToVolt(((IEnergySource)tile).getSourceTier());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doCanReceive(Object handler, ForgeDirection side) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
if (!(tile instanceof IEnergySink)) return false;
|
|
||||||
|
|
||||||
if (side != ForgeDirection.UNKNOWN) {
|
|
||||||
return ((IEnergySink)tile).acceptsEnergyFrom(null, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doCanExtract(Object handler, ForgeDirection side) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
if (!(tile instanceof IEnergySource)) return false;
|
|
||||||
|
|
||||||
if (side != ForgeDirection.UNKNOWN) {
|
|
||||||
return ((IEnergySource)tile).emitsEnergyTo(null, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetDemandedJoules(Object handler) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
if (tile instanceof IEnergySink) {
|
|
||||||
IEnergySink sink = (IEnergySink) tile;
|
|
||||||
return CompatibilityType.INDUSTRIALCRAFT.toJoules(sink.getDemandedEnergy());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double doGetProvidedJoules(Object handler) {
|
|
||||||
TileEntity tile = getENetTile(handler);
|
|
||||||
if (tile instanceof IEnergySource) {
|
|
||||||
IEnergySource source = (IEnergySource) tile;
|
|
||||||
return CompatibilityType.INDUSTRIALCRAFT.toJoules(source.getOfferedEnergy());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int voltToTier(double volt) {
|
|
||||||
if (volt <= 120.0) return 1;
|
|
||||||
if (volt <= 240.0) return 2;
|
|
||||||
if (volt <= 480.0) return 3;
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double tierToVolt(int tier) {
|
|
||||||
switch (tier) {
|
|
||||||
case 1: return 120.0;
|
|
||||||
case 2: return 240.0;
|
|
||||||
case 3: return 480.0;
|
|
||||||
default: return 960.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package universalelectricity.core;
|
|
||||||
|
|
||||||
public class Pair<L, R> {
|
|
||||||
private final L left;
|
|
||||||
private final R right;
|
|
||||||
|
|
||||||
public Pair(L left, R right) {
|
|
||||||
this.left = left;
|
|
||||||
this.right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
public L getKey() {
|
|
||||||
return this.left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public R getValue() {
|
|
||||||
return this.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return this.left.hashCode() ^ this.right.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!(o instanceof Pair)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Pair<Object, Object> pairo = (Pair<Object, Object>)o;
|
|
||||||
return this.left.equals(pairo.getKey()) && this.right.equals(pairo.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package universalelectricity.core;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.Loader;
|
|
||||||
import java.io.File;
|
|
||||||
import net.minecraft.block.material.MapColor;
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import universalelectricity.api.CompatibilityType;
|
|
||||||
|
|
||||||
public class UniversalElectricity {
|
|
||||||
|
|
||||||
public static final String MAJOR_VERSION = "0";
|
|
||||||
public static final String MINOR_VERSION = "6";
|
|
||||||
public static final String REVISION_VERSION = "2";
|
|
||||||
public static final String BUILD_VERSION = "117";
|
|
||||||
public static final String VERSION = "0.6.2";
|
|
||||||
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity.cfg"));
|
|
||||||
public static double UE_IC2_RATIO = CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio;
|
|
||||||
public static double UE_RF_RATIO = CompatibilityType.REDSTONE_FLUX.reciprocal_ratio;
|
|
||||||
public static boolean isVoltageSensitive = true;
|
|
||||||
public static boolean isNetworkActive = false;
|
|
||||||
public static final Material machine = new Material(MapColor.ironColor);
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
CONFIGURATION.load();
|
|
||||||
isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive);
|
|
||||||
isNetworkActive = CONFIGURATION.get("Compatiblity", "Is Network Active", isNetworkActive).getBoolean(isNetworkActive);
|
|
||||||
CONFIGURATION.save();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.net.IConnector;
|
|
||||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
|
||||||
|
|
||||||
public interface IConductor extends INetworkProvider, IConnectionProvider, IConnector<IElectricityNetwork> {
|
|
||||||
|
|
||||||
double getResistance();
|
|
||||||
|
|
||||||
double getCurrentCapcity();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default IConnector<IElectricityNetwork> getInstance(ForgeDirection dir) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
|
|
||||||
public interface IConnectionProvider extends IConnector {
|
|
||||||
|
|
||||||
TileEntity[] getAdjacentConnections();
|
|
||||||
|
|
||||||
void updateAdjacentConnections();
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.net.IConnectable;
|
|
||||||
|
|
||||||
public interface IConnector extends IConnectable, ISelfDriven {
|
|
||||||
|
|
||||||
boolean canConnect(ForgeDirection from);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default boolean canConnect(ForgeDirection from, Object source) {
|
|
||||||
if (source instanceof IConnector) {
|
|
||||||
return canConnect(from);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import mekanism.api.energy.IStrictEnergyStorage;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.energy.IEnergyContainer;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public interface IElectricityStorage extends IEnergyContainer, IStrictEnergyStorage {
|
|
||||||
|
|
||||||
double getJoules();
|
|
||||||
|
|
||||||
void setJoules(double var1);
|
|
||||||
|
|
||||||
double getMaxJoules();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default double getEnergy(ForgeDirection from) {
|
|
||||||
return getJoules();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default void setEnergy(ForgeDirection from, double energy) {
|
|
||||||
setJoules(energy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default double getEnergyCapacity(ForgeDirection from) {
|
|
||||||
return getMaxEnergy();
|
|
||||||
}
|
|
||||||
|
|
||||||
default double getEnergy() {
|
|
||||||
return getJoules();
|
|
||||||
}
|
|
||||||
|
|
||||||
default void setEnergy(double energy) {
|
|
||||||
setJoules(energy);
|
|
||||||
}
|
|
||||||
|
|
||||||
default double getMaxEnergy() {
|
|
||||||
return getMaxJoules();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
|
||||||
|
|
||||||
public interface INetworkProvider extends universalelectricity.api.net.INetworkProvider<IElectricityNetwork> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
public interface ISelfDriven {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
|
|
||||||
public interface IVoltage {
|
|
||||||
|
|
||||||
double getVoltage();
|
|
||||||
}
|
|
|
@ -1,365 +0,0 @@
|
||||||
package universalelectricity.core.electricity;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
|
||||||
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.Set;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.block.IConductor;
|
|
||||||
import universalelectricity.core.block.IConnectionProvider;
|
|
||||||
import universalelectricity.core.block.INetworkProvider;
|
|
||||||
import universalelectricity.core.path.PathfinderChecker;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.core.vector.VectorHelper;
|
|
||||||
|
|
||||||
public class ElectricityNetwork implements IElectricityNetwork {
|
|
||||||
|
|
||||||
private final HashMap<TileEntity, ElectricityPack> producers = new HashMap<>();
|
|
||||||
private final HashMap<TileEntity, ElectricityPack> consumers = new HashMap<>();
|
|
||||||
private final Set<IConductor> conductors = new HashSet<>();
|
|
||||||
|
|
||||||
|
|
||||||
public ElectricityNetwork() {}
|
|
||||||
|
|
||||||
public ElectricityNetwork(IConductor ... conductors) {
|
|
||||||
this.conductors.addAll(Arrays.asList(conductors));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack) {
|
|
||||||
if(tileEntity != null && electricityPack.getWatts() > 0.0D) {
|
|
||||||
this.producers.put(tileEntity, electricityPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startProducing(TileEntity tileEntity, double amperes, double voltage) {
|
|
||||||
this.startProducing(tileEntity, new ElectricityPack(amperes, voltage));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProducing(TileEntity tileEntity) {
|
|
||||||
return this.producers.containsKey(tileEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopProducing(TileEntity tileEntity) {
|
|
||||||
this.producers.remove(tileEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack) {
|
|
||||||
if(tileEntity != null && electricityPack.getWatts() > 0.0D) {
|
|
||||||
this.consumers.put(tileEntity, electricityPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startRequesting(TileEntity tileEntity, double amperes, double voltage) {
|
|
||||||
this.startRequesting(tileEntity, new ElectricityPack(amperes, voltage));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRequesting(TileEntity tileEntity) {
|
|
||||||
return this.consumers.containsKey(tileEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRequesting(TileEntity tileEntity) {
|
|
||||||
this.consumers.remove(tileEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getProduced(TileEntity ... ignoreTiles) {
|
|
||||||
ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D);
|
|
||||||
Iterator it = this.producers.entrySet().iterator();
|
|
||||||
|
|
||||||
label47:
|
|
||||||
while(it.hasNext()) {
|
|
||||||
Entry pairs = (Entry)it.next();
|
|
||||||
if(pairs != null) {
|
|
||||||
TileEntity tileEntity = (TileEntity)pairs.getKey();
|
|
||||||
if(tileEntity == null) {
|
|
||||||
it.remove();
|
|
||||||
} else if(tileEntity.isInvalid()) {
|
|
||||||
it.remove();
|
|
||||||
} else if(tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) {
|
|
||||||
it.remove();
|
|
||||||
} else {
|
|
||||||
if(ignoreTiles != null) {
|
|
||||||
TileEntity[] pack = ignoreTiles;
|
|
||||||
int newWatts = ignoreTiles.length;
|
|
||||||
|
|
||||||
for(int i$ = 0; i$ < newWatts; ++i$) {
|
|
||||||
TileEntity newVoltage = pack[i$];
|
|
||||||
if(tileEntity == newVoltage) {
|
|
||||||
continue label47;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ElectricityPack var11 = (ElectricityPack)pairs.getValue();
|
|
||||||
if(pairs.getKey() != null && pairs.getValue() != null && var11 != null) {
|
|
||||||
double var12 = totalElectricity.getWatts() + var11.getWatts();
|
|
||||||
double var13 = Math.max(totalElectricity.voltage, var11.voltage);
|
|
||||||
totalElectricity.amperes = var12 / var13;
|
|
||||||
totalElectricity.voltage = var13;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalElectricity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getRequest(TileEntity ... ignoreTiles) {
|
|
||||||
ElectricityPack totalElectricity = this.getRequestWithoutReduction();
|
|
||||||
totalElectricity.amperes = Math.max(totalElectricity.amperes - this.getProduced(ignoreTiles).amperes, 0.0D);
|
|
||||||
return totalElectricity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getRequestWithoutReduction() {
|
|
||||||
ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D);
|
|
||||||
Iterator it = this.consumers.entrySet().iterator();
|
|
||||||
|
|
||||||
while(it.hasNext()) {
|
|
||||||
Entry pairs = (Entry)it.next();
|
|
||||||
if(pairs != null) {
|
|
||||||
TileEntity tileEntity = (TileEntity)pairs.getKey();
|
|
||||||
if(tileEntity == null) {
|
|
||||||
it.remove();
|
|
||||||
} else if(tileEntity.isInvalid()) {
|
|
||||||
it.remove();
|
|
||||||
} else if(tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) {
|
|
||||||
it.remove();
|
|
||||||
} else {
|
|
||||||
ElectricityPack pack = (ElectricityPack)pairs.getValue();
|
|
||||||
if(pack != null) {
|
|
||||||
totalElectricity.amperes += pack.amperes;
|
|
||||||
totalElectricity.voltage = Math.max(totalElectricity.voltage, pack.voltage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalElectricity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack consumeElectricity(TileEntity tileEntity) {
|
|
||||||
ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ElectricityPack e = (ElectricityPack)this.consumers.get(tileEntity);
|
|
||||||
if(this.consumers.containsKey(tileEntity) && e != null) {
|
|
||||||
totalElectricity = this.getProduced(new TileEntity[0]);
|
|
||||||
if(totalElectricity.getWatts() > 0.0D) {
|
|
||||||
ElectricityPack totalRequest = this.getRequestWithoutReduction();
|
|
||||||
totalElectricity.amperes *= e.amperes / totalRequest.amperes;
|
|
||||||
int distance = this.conductors.size();
|
|
||||||
double ampsReceived = totalElectricity.amperes - totalElectricity.amperes * totalElectricity.amperes * this.getTotalResistance() / totalElectricity.voltage;
|
|
||||||
double voltsReceived = totalElectricity.voltage - totalElectricity.amperes * this.getTotalResistance();
|
|
||||||
totalElectricity.amperes = ampsReceived;
|
|
||||||
totalElectricity.voltage = voltsReceived;
|
|
||||||
return totalElectricity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception var10) {
|
|
||||||
FMLLog.severe("Failed to consume electricity!", new Object[0]);
|
|
||||||
var10.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalElectricity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<TileEntity, ElectricityPack> getProducers() {
|
|
||||||
return this.producers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TileEntity> getProviders() {
|
|
||||||
ArrayList<TileEntity> providers = new ArrayList<>();
|
|
||||||
providers.addAll(this.producers.keySet());
|
|
||||||
return providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<TileEntity, ElectricityPack> getConsumers() {
|
|
||||||
return this.consumers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TileEntity> getReceivers() {
|
|
||||||
ArrayList<TileEntity> receivers = new ArrayList<>();
|
|
||||||
receivers.addAll(this.consumers.keySet());
|
|
||||||
return receivers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanUpConductors() {
|
|
||||||
Iterator<IConductor> it = this.conductors.iterator();
|
|
||||||
|
|
||||||
while(it.hasNext()) {
|
|
||||||
IConductor conductor = (IConductor)it.next();
|
|
||||||
if(conductor == null) {
|
|
||||||
it.remove();
|
|
||||||
} else if(((TileEntity)conductor).isInvalid()) {
|
|
||||||
it.remove();
|
|
||||||
} else {
|
|
||||||
conductor.setNetwork(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refreshConductors() {
|
|
||||||
this.cleanUpConductors();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Iterator e = this.conductors.iterator();
|
|
||||||
|
|
||||||
while(e.hasNext()) {
|
|
||||||
IConductor conductor = (IConductor)e.next();
|
|
||||||
conductor.updateAdjacentConnections();
|
|
||||||
}
|
|
||||||
} catch (Exception var3) {
|
|
||||||
FMLLog.severe("Universal Electricity: Failed to refresh conductor.", new Object[0]);
|
|
||||||
var3.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getTotalResistance() {
|
|
||||||
double resistance = 0.0D;
|
|
||||||
|
|
||||||
IConductor conductor;
|
|
||||||
for(Iterator i$ = this.conductors.iterator(); i$.hasNext(); resistance += conductor.getResistance()) {
|
|
||||||
conductor = (IConductor)i$.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
return resistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLowestCurrentCapacity() {
|
|
||||||
double lowestAmp = 0.0D;
|
|
||||||
Iterator i$ = this.conductors.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
IConductor conductor = (IConductor)i$.next();
|
|
||||||
if(lowestAmp == 0.0D || conductor.getCurrentCapcity() < lowestAmp) {
|
|
||||||
lowestAmp = conductor.getCurrentCapcity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lowestAmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<IConductor> getConductors() {
|
|
||||||
return this.conductors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mergeConnection(IElectricityNetwork network) {
|
|
||||||
if(network != null && network != this) {
|
|
||||||
ElectricityNetwork newNetwork = new ElectricityNetwork();
|
|
||||||
newNetwork.getConductors().addAll(this.getConductors());
|
|
||||||
newNetwork.getConductors().addAll(network.getConductors());
|
|
||||||
newNetwork.cleanUpConductors();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void splitNetwork(IConnectionProvider splitPoint) {
|
|
||||||
if(splitPoint instanceof TileEntity) {
|
|
||||||
this.getConductors().remove(splitPoint);
|
|
||||||
ForgeDirection[] connectedBlocks = ForgeDirection.values();
|
|
||||||
int i = connectedBlocks.length;
|
|
||||||
|
|
||||||
for(int connectedBlockA = 0; connectedBlockA < i; ++connectedBlockA) {
|
|
||||||
ForgeDirection ii = connectedBlocks[connectedBlockA];
|
|
||||||
if(ii != ForgeDirection.UNKNOWN) {
|
|
||||||
Vector3 connectedBlockB = new Vector3((TileEntity)splitPoint);
|
|
||||||
TileEntity finder = VectorHelper.getTileEntityFromSide(((TileEntity)splitPoint).getWorldObj(), connectedBlockB, ii);
|
|
||||||
if(this.producers.containsKey(finder)) {
|
|
||||||
this.stopProducing(finder);
|
|
||||||
this.stopRequesting(finder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TileEntity[] var12 = splitPoint.getAdjacentConnections();
|
|
||||||
|
|
||||||
for(i = 0; i < var12.length; ++i) {
|
|
||||||
TileEntity var13 = var12[i];
|
|
||||||
if(var13 instanceof IConnectionProvider) {
|
|
||||||
for(int var14 = 0; var14 < var12.length; ++var14) {
|
|
||||||
TileEntity var15 = var12[var14];
|
|
||||||
if(var13 != var15 && var15 instanceof IConnectionProvider) {
|
|
||||||
PathfinderChecker var16 = new PathfinderChecker(((TileEntity)splitPoint).getWorldObj(), (IConnectionProvider)var15, new IConnectionProvider[]{splitPoint});
|
|
||||||
var16.init(new Vector3(var13));
|
|
||||||
if(var16.results.size() > 0) {
|
|
||||||
Iterator newNetwork = var16.closedSet.iterator();
|
|
||||||
|
|
||||||
while(newNetwork.hasNext()) {
|
|
||||||
Vector3 i$ = (Vector3)newNetwork.next();
|
|
||||||
TileEntity node = i$.getTileEntity(((TileEntity)splitPoint).getWorldObj());
|
|
||||||
if(node instanceof INetworkProvider && node != splitPoint) {
|
|
||||||
((INetworkProvider)node).setNetwork(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ElectricityNetwork var17 = new ElectricityNetwork();
|
|
||||||
Iterator var18 = var16.closedSet.iterator();
|
|
||||||
|
|
||||||
while(var18.hasNext()) {
|
|
||||||
Vector3 var19 = (Vector3)var18.next();
|
|
||||||
TileEntity nodeTile = var19.getTileEntity(((TileEntity)splitPoint).getWorldObj());
|
|
||||||
if(nodeTile instanceof INetworkProvider && nodeTile != splitPoint) {
|
|
||||||
var17.getConductors().add((IConductor)nodeTile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var17.cleanUpConductors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addConnector(IConductor connector) {
|
|
||||||
this.conductors.add(connector);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeConnector(IConductor connector) {
|
|
||||||
this.conductors.remove(connector);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<IConductor> getConnectors() {
|
|
||||||
return this.conductors;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reconstruct() {
|
|
||||||
refreshConductors();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IElectricityNetwork merge(IElectricityNetwork network) {
|
|
||||||
this.mergeConnection(network);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void split(IConductor connection) {
|
|
||||||
splitNetwork(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void split(IConductor connectorA, IConductor connectorB) {
|
|
||||||
// TODO: implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,151 +0,0 @@
|
||||||
package universalelectricity.core.electricity;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.CompatibilityModule;
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
import universalelectricity.core.block.INetworkProvider;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.core.vector.VectorHelper;
|
|
||||||
|
|
||||||
public class ElectricityNetworkHelper {
|
|
||||||
|
|
||||||
public static void invalidate(TileEntity tileEntity) {
|
|
||||||
for(int i = 0; i < 6; ++i) {
|
|
||||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
|
||||||
TileEntity checkTile = VectorHelper.getConnectorFromSide(tileEntity.getWorldObj(), new Vector3(tileEntity), direction);
|
|
||||||
if(checkTile instanceof INetworkProvider) {
|
|
||||||
IElectricityNetwork network = ((INetworkProvider)checkTile).getNetwork();
|
|
||||||
if(network != null) {
|
|
||||||
network.stopRequesting(tileEntity);
|
|
||||||
network.stopProducing(tileEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnumSet<ForgeDirection> getDirections(TileEntity tileEntity) {
|
|
||||||
EnumSet 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) {
|
|
||||||
return produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack producingPack) {
|
|
||||||
ElectricityPack remainingElectricity = producingPack.clone();
|
|
||||||
if(tileEntity != null && approachingDirection != null) {
|
|
||||||
List connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
|
||||||
if(connectedNetworks.size() > 0) {
|
|
||||||
double wattsPerSide = producingPack.getWatts() / (double)connectedNetworks.size();
|
|
||||||
double voltage = producingPack.voltage;
|
|
||||||
Iterator i$ = connectedNetworks.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
IElectricityNetwork network = (IElectricityNetwork)i$.next();
|
|
||||||
if(wattsPerSide > 0.0D && producingPack.getWatts() > 0.0D) {
|
|
||||||
double amperes = Math.min(wattsPerSide / voltage, network.getRequest(new TileEntity[]{tileEntity}).amperes);
|
|
||||||
if(amperes > 0.0D) {
|
|
||||||
network.startProducing(tileEntity, amperes, voltage);
|
|
||||||
remainingElectricity.amperes -= amperes;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
network.stopProducing(tileEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return remainingElectricity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) {
|
|
||||||
return consumeFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack requestPack) {
|
|
||||||
ElectricityPack consumedPack = new ElectricityPack();
|
|
||||||
if(tileEntity != null && approachingDirection != null) {
|
|
||||||
List connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
|
||||||
if(connectedNetworks.size() > 0) {
|
|
||||||
double wattsPerSide = requestPack.getWatts() / (double)connectedNetworks.size();
|
|
||||||
double voltage = requestPack.voltage;
|
|
||||||
Iterator i$ = connectedNetworks.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
IElectricityNetwork network = (IElectricityNetwork)i$.next();
|
|
||||||
if(wattsPerSide > 0.0D && requestPack.getWatts() > 0.0D) {
|
|
||||||
network.startRequesting(tileEntity, wattsPerSide / voltage, voltage);
|
|
||||||
ElectricityPack receivedPack = network.consumeElectricity(tileEntity);
|
|
||||||
consumedPack.amperes += receivedPack.amperes;
|
|
||||||
consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage);
|
|
||||||
} else {
|
|
||||||
network.stopRequesting(tileEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return consumedPack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<IElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection) {
|
|
||||||
ArrayList connectedNetworks = new ArrayList();
|
|
||||||
|
|
||||||
for(int i = 0; i < 6; ++i) {
|
|
||||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
|
||||||
if(approachingDirection.contains(direction)) {
|
|
||||||
Vector3 position = new Vector3(tileEntity);
|
|
||||||
position.modifyPositionFromSide(direction);
|
|
||||||
TileEntity outputConductor = position.getTileEntity(tileEntity.getWorldObj());
|
|
||||||
IElectricityNetwork electricityNetwork = getNetworkFromTileEntity(outputConductor, direction);
|
|
||||||
if(electricityNetwork != null && !connectedNetworks.contains(electricityNetwork)) {
|
|
||||||
connectedNetworks.add(electricityNetwork);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return connectedNetworks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection) {
|
|
||||||
if(tileEntity != null && tileEntity instanceof INetworkProvider) {
|
|
||||||
if(!(tileEntity instanceof IConnector)) {
|
|
||||||
return ((INetworkProvider)tileEntity).getNetwork();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(((IConnector)tileEntity).canConnect(approachDirection.getOpposite())) {
|
|
||||||
return ((INetworkProvider)tileEntity).getNetwork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side, TileEntity source) {
|
|
||||||
if (tileEntity == null) {
|
|
||||||
return false;
|
|
||||||
} else if (tileEntity instanceof IConnector) {
|
|
||||||
return ((IConnector)tileEntity).canConnect(side, source);
|
|
||||||
} else {
|
|
||||||
return CompatibilityModule.canConnect(tileEntity, side, source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
package universalelectricity.core.electricity;
|
|
||||||
|
|
||||||
|
|
||||||
public class ElectricityPack implements Cloneable {
|
|
||||||
|
|
||||||
public double amperes;
|
|
||||||
public double voltage;
|
|
||||||
|
|
||||||
|
|
||||||
public ElectricityPack(double amperes, double voltage) {
|
|
||||||
this.amperes = amperes;
|
|
||||||
this.voltage = voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack() {
|
|
||||||
this(0.0D, 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ElectricityPack getFromWatts(double watts, double voltage) {
|
|
||||||
return new ElectricityPack(watts / voltage, voltage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getWatts() {
|
|
||||||
return getWatts(this.amperes, this.voltage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getConductance() {
|
|
||||||
return getConductance(this.amperes, this.voltage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getResistance() {
|
|
||||||
return getResistance(this.amperes, this.voltage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getJoules(double watts, double seconds) {
|
|
||||||
return watts * seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getJoules(double amps, double voltage, double seconds) {
|
|
||||||
return amps * voltage * seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getWattsFromJoules(double joules, double seconds) {
|
|
||||||
return joules / seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getAmps(double watts, double voltage) {
|
|
||||||
return watts / voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getAmps(double ampHours) {
|
|
||||||
return ampHours * 3600.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getAmpsFromWattHours(double wattHours, double voltage) {
|
|
||||||
return getWatts(wattHours) / voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getWattHoursFromAmpHours(double ampHours, double voltage) {
|
|
||||||
return ampHours * voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getAmpHours(double amps) {
|
|
||||||
return amps / 3600.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getWatts(double amps, double voltage) {
|
|
||||||
return amps * voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getWatts(double wattHours) {
|
|
||||||
return wattHours * 3600.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getWattHours(double watts) {
|
|
||||||
return watts / 3600.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getWattHours(double amps, double voltage) {
|
|
||||||
return getWattHours(getWatts(amps, voltage));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getResistance(double amps, double voltage) {
|
|
||||||
return voltage / amps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getConductance(double amps, double voltage) {
|
|
||||||
return amps / voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "ElectricityPack [Amps:" + this.amperes + " Volts:" + this.voltage + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
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,15 +0,0 @@
|
||||||
package universalelectricity.core.electricity;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import universalelectricity.core.block.IConductor;
|
|
||||||
|
|
||||||
public interface IConductorRegistry {
|
|
||||||
|
|
||||||
void register(IConductor var1);
|
|
||||||
|
|
||||||
void cleanConductors();
|
|
||||||
|
|
||||||
void resetAllConnections();
|
|
||||||
|
|
||||||
List getConductors();
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
package universalelectricity.core.electricity;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import universalelectricity.api.net.INetwork;
|
|
||||||
import universalelectricity.core.block.IConductor;
|
|
||||||
import universalelectricity.core.block.IConnectionProvider;
|
|
||||||
|
|
||||||
public interface IElectricityNetwork extends INetwork<IElectricityNetwork, IConductor> {
|
|
||||||
|
|
||||||
void startProducing(TileEntity var1, ElectricityPack var2);
|
|
||||||
|
|
||||||
void startProducing(TileEntity var1, double var2, double var4);
|
|
||||||
|
|
||||||
boolean isProducing(TileEntity var1);
|
|
||||||
|
|
||||||
void stopProducing(TileEntity var1);
|
|
||||||
|
|
||||||
void startRequesting(TileEntity var1, ElectricityPack var2);
|
|
||||||
|
|
||||||
void startRequesting(TileEntity var1, double var2, double var4);
|
|
||||||
|
|
||||||
boolean isRequesting(TileEntity var1);
|
|
||||||
|
|
||||||
void stopRequesting(TileEntity var1);
|
|
||||||
|
|
||||||
ElectricityPack getProduced(TileEntity ... var1);
|
|
||||||
|
|
||||||
ElectricityPack getRequest(TileEntity ... var1);
|
|
||||||
|
|
||||||
ElectricityPack getRequestWithoutReduction();
|
|
||||||
|
|
||||||
ElectricityPack consumeElectricity(TileEntity var1);
|
|
||||||
|
|
||||||
HashMap<TileEntity, ElectricityPack> getProducers();
|
|
||||||
|
|
||||||
List<TileEntity> getProviders();
|
|
||||||
|
|
||||||
HashMap<TileEntity, ElectricityPack> getConsumers();
|
|
||||||
|
|
||||||
List<TileEntity> getReceivers();
|
|
||||||
|
|
||||||
Set<IConductor> getConductors();
|
|
||||||
|
|
||||||
double getTotalResistance();
|
|
||||||
|
|
||||||
double getLowestCurrentCapacity();
|
|
||||||
|
|
||||||
void cleanUpConductors();
|
|
||||||
|
|
||||||
void refreshConductors();
|
|
||||||
|
|
||||||
void mergeConnection(IElectricityNetwork var1);
|
|
||||||
|
|
||||||
void splitNetwork(IConnectionProvider var1);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package universalelectricity.core.item;
|
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
import universalelectricity.core.item.IItemElectric;
|
|
||||||
|
|
||||||
public class ElectricItemHelper {
|
|
||||||
|
|
||||||
public static double chargeItem(ItemStack itemStack, double joules, double voltage) {
|
|
||||||
if(itemStack != null && itemStack.getItem() instanceof IItemElectric) {
|
|
||||||
IItemElectric electricItem = (IItemElectric)itemStack.getItem();
|
|
||||||
double providingWatts = Math.min(joules, electricItem.getReceiveRequest(itemStack).getWatts());
|
|
||||||
if(providingWatts > 0.0D) {
|
|
||||||
ElectricityPack providedElectricity = electricItem.onReceive(ElectricityPack.getFromWatts(providingWatts, voltage), itemStack);
|
|
||||||
return providedElectricity.getWatts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double dechargeItem(ItemStack itemStack, double joules, double voltage) {
|
|
||||||
if(itemStack != null && itemStack.getItem() instanceof IItemElectric) {
|
|
||||||
IItemElectric electricItem = (IItemElectric)itemStack.getItem();
|
|
||||||
double requestingWatts = Math.min(joules, electricItem.getProvideRequest(itemStack).getWatts());
|
|
||||||
if(requestingWatts > 0.0D) {
|
|
||||||
ElectricityPack receivedElectricity = electricItem.onProvide(ElectricityPack.getFromWatts(requestingWatts, voltage), itemStack);
|
|
||||||
return receivedElectricity.getWatts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getWithCharge(ItemStack itemStack, double joules) {
|
|
||||||
if(itemStack != null && itemStack.getItem() instanceof IItemElectric) {
|
|
||||||
((IItemElectric)itemStack.getItem()).setJoules(joules, itemStack);
|
|
||||||
return itemStack;
|
|
||||||
} else {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getWithCharge(Item item, double joules) {
|
|
||||||
return getWithCharge(new ItemStack(item), joules);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getCloneWithCharge(ItemStack itemStack, double joules) {
|
|
||||||
return getWithCharge(itemStack.copy(), joules);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getUncharged(ItemStack itemStack) {
|
|
||||||
return getWithCharge(itemStack, 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getUncharged(Item item) {
|
|
||||||
return getUncharged(new ItemStack(item));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package universalelectricity.core.item;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
import universalelectricity.core.item.IItemElectricityStorage;
|
|
||||||
import universalelectricity.core.item.IItemVoltage;
|
|
||||||
|
|
||||||
public interface IItemElectric extends IItemElectricityStorage, IItemVoltage {
|
|
||||||
|
|
||||||
ElectricityPack onReceive(ElectricityPack var1, ItemStack var2);
|
|
||||||
|
|
||||||
ElectricityPack onProvide(ElectricityPack var1, ItemStack var2);
|
|
||||||
|
|
||||||
ElectricityPack getReceiveRequest(ItemStack var1);
|
|
||||||
|
|
||||||
ElectricityPack getProvideRequest(ItemStack var1);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package universalelectricity.core.item;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public interface IItemElectricityStorage {
|
|
||||||
|
|
||||||
double getJoules(ItemStack var1);
|
|
||||||
|
|
||||||
void setJoules(double var1, ItemStack var3);
|
|
||||||
|
|
||||||
double getMaxJoules(ItemStack var1);
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package universalelectricity.core.item;
|
|
||||||
|
|
||||||
import universalelectricity.api.item.IVoltageItem;
|
|
||||||
|
|
||||||
public interface IItemVoltage extends IVoltageItem {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,93 +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.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.api.energy.UnitDisplay;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
import universalelectricity.core.item.ElectricItemHelper;
|
|
||||||
import universalelectricity.core.item.IItemElectric;
|
|
||||||
|
|
||||||
public abstract class ItemElectric extends Item implements IItemElectric {
|
|
||||||
|
|
||||||
public ItemElectric() {
|
|
||||||
super();
|
|
||||||
this.setMaxStackSize(1);
|
|
||||||
this.setMaxDamage(100);
|
|
||||||
this.setNoRepair();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4) {
|
|
||||||
String color = "";
|
|
||||||
double joules = this.getJoules(itemStack);
|
|
||||||
if(joules <= this.getMaxJoules(itemStack) / 3.0D) {
|
|
||||||
color = "§4";
|
|
||||||
} else if(joules > this.getMaxJoules(itemStack) * 2.0D / 3.0D) {
|
|
||||||
color = "§2";
|
|
||||||
} else {
|
|
||||||
color = "§6";
|
|
||||||
}
|
|
||||||
|
|
||||||
list.add(color + UnitDisplay.getDisplay(joules, UnitDisplay.Unit.JOULES) + "/" + UnitDisplay.getDisplay(this.getMaxJoules(itemStack), UnitDisplay.Unit.JOULES));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
|
||||||
this.setJoules(0.0D, itemStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) {
|
|
||||||
double rejectedElectricity = Math.max(this.getJoules(itemStack) + electricityPack.getWatts() - this.getMaxJoules(itemStack), 0.0D);
|
|
||||||
double joulesToStore = electricityPack.getWatts() - rejectedElectricity;
|
|
||||||
this.setJoules(this.getJoules(itemStack) + joulesToStore, itemStack);
|
|
||||||
return ElectricityPack.getFromWatts(joulesToStore, this.getVoltage(itemStack));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) {
|
|
||||||
double electricityToUse = Math.min(this.getJoules(itemStack), electricityPack.getWatts());
|
|
||||||
this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack);
|
|
||||||
return ElectricityPack.getFromWatts(electricityToUse, this.getVoltage(itemStack));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getReceiveRequest(ItemStack itemStack) {
|
|
||||||
return ElectricityPack.getFromWatts(Math.min(this.getMaxJoules(itemStack) - this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getProvideRequest(ItemStack itemStack) {
|
|
||||||
return ElectricityPack.getFromWatts(Math.min(this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack));
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getTransferRate(ItemStack itemStack) {
|
|
||||||
return this.getMaxJoules(itemStack) * 0.01D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setJoules(double joules, ItemStack itemStack) {
|
|
||||||
if(itemStack.getTagCompound() == null) {
|
|
||||||
itemStack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
double electricityStored = Math.max(Math.min(joules, this.getMaxJoules(itemStack)), 0.0D);
|
|
||||||
itemStack.getTagCompound().setDouble("electricity", electricityStored);
|
|
||||||
itemStack.setItemDamage((int)(100.0D - electricityStored / this.getMaxJoules(itemStack) * 100.0D));
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getJoules(ItemStack itemStack) {
|
|
||||||
if(itemStack.getTagCompound() == null) {
|
|
||||||
return 0.0D;
|
|
||||||
} else {
|
|
||||||
double electricityStored = itemStack.getTagCompound().getDouble("electricity");
|
|
||||||
itemStack.setItemDamage((int)(100.0D - electricityStored / this.getMaxJoules(itemStack) * 100.0D));
|
|
||||||
return electricityStored;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
|
|
||||||
par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this)));
|
|
||||||
ItemStack chargedItem = new ItemStack(this);
|
|
||||||
par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxJoules(chargedItem)));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package universalelectricity.core.path;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import universalelectricity.core.path.Pathfinder;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public interface IPathCallBack {
|
|
||||||
|
|
||||||
Set getConnectedNodes(Pathfinder var1, Vector3 var2);
|
|
||||||
|
|
||||||
boolean onSearch(Pathfinder var1, Vector3 var2);
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
package universalelectricity.core.path;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import universalelectricity.core.path.IPathCallBack;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class Pathfinder {
|
|
||||||
|
|
||||||
public IPathCallBack callBackCheck;
|
|
||||||
public Set closedSet;
|
|
||||||
public Set results;
|
|
||||||
|
|
||||||
|
|
||||||
public Pathfinder(IPathCallBack callBack) {
|
|
||||||
this.callBackCheck = callBack;
|
|
||||||
this.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean findNodes(Vector3 currentNode) {
|
|
||||||
this.closedSet.add(currentNode);
|
|
||||||
if(this.callBackCheck.onSearch(this, currentNode)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
Iterator i$ = this.callBackCheck.getConnectedNodes(this, currentNode).iterator();
|
|
||||||
|
|
||||||
Vector3 node;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
node = (Vector3)i$.next();
|
|
||||||
} while(this.closedSet.contains(node) || !this.findNodes(node));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pathfinder init(Vector3 startNode) {
|
|
||||||
this.findNodes(startNode);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pathfinder reset() {
|
|
||||||
this.closedSet = new HashSet();
|
|
||||||
this.results = new HashSet();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,112 +0,0 @@
|
||||||
package universalelectricity.core.path;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.path.IPathCallBack;
|
|
||||||
import universalelectricity.core.path.Pathfinder;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class PathfinderAStar extends Pathfinder {
|
|
||||||
|
|
||||||
public IPathCallBack callBackCheck;
|
|
||||||
public Set openSet;
|
|
||||||
public HashMap navigationMap;
|
|
||||||
public HashMap gScore;
|
|
||||||
public HashMap fScore;
|
|
||||||
public Vector3 goal;
|
|
||||||
|
|
||||||
|
|
||||||
public PathfinderAStar(IPathCallBack callBack, Vector3 goal) {
|
|
||||||
super(callBack);
|
|
||||||
this.goal = goal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean findNodes(Vector3 start) {
|
|
||||||
this.openSet.add(start);
|
|
||||||
this.gScore.put(start, Double.valueOf(0.0D));
|
|
||||||
this.fScore.put(start, Double.valueOf(((Double)this.gScore.get(start)).doubleValue() + this.getHeuristicEstimatedCost(start, this.goal)));
|
|
||||||
|
|
||||||
while(!this.openSet.isEmpty()) {
|
|
||||||
Vector3 currentNode = null;
|
|
||||||
double lowestFScore = 0.0D;
|
|
||||||
Iterator i$ = this.openSet.iterator();
|
|
||||||
|
|
||||||
Vector3 neighbor;
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
neighbor = (Vector3)i$.next();
|
|
||||||
if(currentNode == null || ((Double)this.fScore.get(neighbor)).doubleValue() < lowestFScore) {
|
|
||||||
currentNode = neighbor;
|
|
||||||
lowestFScore = ((Double)this.fScore.get(neighbor)).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentNode == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.callBackCheck.onSearch(this, currentNode)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentNode.equals(this.goal)) {
|
|
||||||
super.results = this.reconstructPath(this.navigationMap, this.goal);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.openSet.remove(currentNode);
|
|
||||||
super.closedSet.add(currentNode);
|
|
||||||
i$ = this.getNeighborNodes(currentNode).iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
neighbor = (Vector3)i$.next();
|
|
||||||
double tentativeGScore = ((Double)this.gScore.get(currentNode)).doubleValue() + currentNode.distanceTo(neighbor);
|
|
||||||
if((!super.closedSet.contains(neighbor) || tentativeGScore < ((Double)this.gScore.get(neighbor)).doubleValue()) && (!this.openSet.contains(neighbor) || tentativeGScore < ((Double)this.gScore.get(neighbor)).doubleValue())) {
|
|
||||||
this.navigationMap.put(neighbor, currentNode);
|
|
||||||
this.gScore.put(neighbor, Double.valueOf(tentativeGScore));
|
|
||||||
this.fScore.put(neighbor, Double.valueOf(((Double)this.gScore.get(neighbor)).doubleValue() + this.getHeuristicEstimatedCost(neighbor, this.goal)));
|
|
||||||
this.openSet.add(neighbor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pathfinder reset() {
|
|
||||||
this.openSet = new HashSet();
|
|
||||||
this.navigationMap = new HashMap();
|
|
||||||
return super.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set reconstructPath(HashMap nagivationMap, Vector3 current_node) {
|
|
||||||
HashSet path = new HashSet();
|
|
||||||
path.add(current_node);
|
|
||||||
if(nagivationMap.containsKey(current_node)) {
|
|
||||||
path.addAll(this.reconstructPath(nagivationMap, (Vector3)nagivationMap.get(current_node)));
|
|
||||||
return path;
|
|
||||||
} else {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getHeuristicEstimatedCost(Vector3 start, Vector3 goal) {
|
|
||||||
return start.distanceTo(goal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set getNeighborNodes(Vector3 vector) {
|
|
||||||
if(this.callBackCheck != null) {
|
|
||||||
return this.callBackCheck.getConnectedNodes(this, vector);
|
|
||||||
} else {
|
|
||||||
HashSet neighbors = new HashSet();
|
|
||||||
|
|
||||||
for(int i = 0; i < 6; ++i) {
|
|
||||||
neighbors.add(vector.clone().modifyPositionFromSide(ForgeDirection.getOrientation(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return neighbors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +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.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.net.IConnector;
|
|
||||||
import universalelectricity.core.block.IConductor;
|
|
||||||
import universalelectricity.core.block.IConnectionProvider;
|
|
||||||
import universalelectricity.core.path.IPathCallBack;
|
|
||||||
import universalelectricity.core.path.Pathfinder;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class PathfinderChecker extends Pathfinder {
|
|
||||||
|
|
||||||
public PathfinderChecker(final World world, final IConnectionProvider targetConnector, final IConnectionProvider ... ignoreConnector) {
|
|
||||||
super(new IPathCallBack() {
|
|
||||||
public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) {
|
|
||||||
HashSet neighbors = new HashSet();
|
|
||||||
|
|
||||||
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) && ((IConductor)connectedBlock).canConnect(direction.getOpposite())) {
|
|
||||||
neighbors.add(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return neighbors;
|
|
||||||
}
|
|
||||||
public boolean onSearch(Pathfinder finder, Vector3 node) {
|
|
||||||
if(node.getTileEntity(world) == targetConnector) {
|
|
||||||
finder.results.add(node);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public PathfinderChecker(final World world, final IConnector targetConnector, final IConnector[] ignoreConnector) {
|
|
||||||
super(new IPathCallBack() {
|
|
||||||
public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) {
|
|
||||||
HashSet neighbors = new HashSet();
|
|
||||||
|
|
||||||
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) && ((IConductor)connectedBlock).canConnect(direction.getOpposite())) {
|
|
||||||
neighbors.add(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return neighbors;
|
|
||||||
}
|
|
||||||
public boolean onSearch(Pathfinder finder, Vector3 node) {
|
|
||||||
if(node.getTileEntity(world) == targetConnector) {
|
|
||||||
finder.results.add(node);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
package universalelectricity.core.vector;
|
|
||||||
|
|
||||||
import net.minecraft.util.MathHelper;
|
|
||||||
|
|
||||||
public class Vector2 implements Cloneable {
|
|
||||||
|
|
||||||
public double x;
|
|
||||||
public double y;
|
|
||||||
|
|
||||||
|
|
||||||
public Vector2() {
|
|
||||||
this(0.0D, 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2(double x, double y) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int intX() {
|
|
||||||
return (int)Math.floor(this.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int intY() {
|
|
||||||
return (int)Math.floor(this.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (double)MathHelper.sqrt_double(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 (double)MathHelper.sqrt_double(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.0D);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2 multiply(double amount) {
|
|
||||||
this.x *= amount;
|
|
||||||
this.y *= amount;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2 round() {
|
|
||||||
return new Vector2((double)Math.round(this.x), (double)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));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return ("X:" + this.x + "Y:" + this.y).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if(!(o instanceof Vector2)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
Vector2 vector = (Vector2)o;
|
|
||||||
return this.x == vector.x && this.y == vector.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "Vector2 [" + this.x + "," + this.y + "]";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,286 +0,0 @@
|
||||||
package universalelectricity.core.vector;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
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.MathHelper;
|
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
|
||||||
import net.minecraft.util.Vec3;
|
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public class Vector3 implements Cloneable {
|
|
||||||
|
|
||||||
public double x;
|
|
||||||
public double y;
|
|
||||||
public double z;
|
|
||||||
|
|
||||||
|
|
||||||
public Vector3() {
|
|
||||||
this(0.0D, 0.0D, 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(double x, double y, double z) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(Entity par1) {
|
|
||||||
this.x = par1.posX;
|
|
||||||
this.y = par1.posY;
|
|
||||||
this.z = par1.posZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(TileEntity par1) {
|
|
||||||
this.x = (double)par1.xCoord;
|
|
||||||
this.y = (double)par1.yCoord;
|
|
||||||
this.z = (double)par1.zCoord;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(Vec3 par1) {
|
|
||||||
this.x = par1.xCoord;
|
|
||||||
this.y = par1.yCoord;
|
|
||||||
this.z = par1.zCoord;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(MovingObjectPosition par1) {
|
|
||||||
this.x = (double)par1.blockX;
|
|
||||||
this.y = (double)par1.blockY;
|
|
||||||
this.z = (double)par1.blockZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(ChunkCoordinates par1) {
|
|
||||||
this.x = (double)par1.posX;
|
|
||||||
this.y = (double)par1.posY;
|
|
||||||
this.z = (double)par1.posZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3(ForgeDirection direction) {
|
|
||||||
this.x = (double)direction.offsetX;
|
|
||||||
this.y = (double)direction.offsetY;
|
|
||||||
this.z = (double)direction.offsetZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 Vector3 clone() {
|
|
||||||
return new Vector3(this.x, this.y, this.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block getBlock(IBlockAccess world) {
|
|
||||||
return world.getBlock(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.getTileEntity(this.intX(), this.intY(), this.intZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setBlock(World world, Block block, int metadata, int notify) {
|
|
||||||
return world.setBlock(this.intX(), this.intY(), this.intZ(), block, metadata, notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setBlock(World world, Block block, int metadata) {
|
|
||||||
return this.setBlock(world, block, metadata, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setBlock(World world, Block block) {
|
|
||||||
return this.setBlock(world, block, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2 toVector2() {
|
|
||||||
return new Vector2(this.x, this.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3 toVec3() {
|
|
||||||
return Vec3.createVectorHelper(this.x, this.y, this.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.0D) {
|
|
||||||
this.multiply(1.0D / d);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double distance(Vector3 par1, Vector3 par2) {
|
|
||||||
double var2 = par1.x - par2.x;
|
|
||||||
double var4 = par1.y - par2.y;
|
|
||||||
double var6 = par1.z - par2.z;
|
|
||||||
return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double distanceTo(Vector3 vector3) {
|
|
||||||
double var2 = vector3.x - this.x;
|
|
||||||
double var4 = vector3.y - this.y;
|
|
||||||
double var6 = vector3.z - this.z;
|
|
||||||
return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 add(Vector3 par1) {
|
|
||||||
this.x += par1.x;
|
|
||||||
this.y += par1.y;
|
|
||||||
this.z += par1.z;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 add(double par1) {
|
|
||||||
this.x += par1;
|
|
||||||
this.y += par1;
|
|
||||||
this.z += par1;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 subtract(Vector3 amount) {
|
|
||||||
this.x -= amount.x;
|
|
||||||
this.y -= amount.y;
|
|
||||||
this.z -= amount.z;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 invert() {
|
|
||||||
this.multiply(-1.0D);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 multiply(double amount) {
|
|
||||||
this.x *= amount;
|
|
||||||
this.y *= amount;
|
|
||||||
this.z *= amount;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 multiply(Vector3 vec) {
|
|
||||||
this.x *= vec.x;
|
|
||||||
this.y *= vec.y;
|
|
||||||
this.z *= vec.z;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 subtract(Vector3 par1, Vector3 par2) {
|
|
||||||
return new Vector3(par1.x - par2.x, par1.y - par2.y, par1.z - par2.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 add(Vector3 par1, Vector3 par2) {
|
|
||||||
return new Vector3(par1.x + par2.x, par1.y + par2.y, par1.z + par2.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 add(Vector3 par1, double par2) {
|
|
||||||
return new Vector3(par1.x + par2, par1.y + par2, par1.z + par2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 multiply(Vector3 vec1, Vector3 vec2) {
|
|
||||||
return new Vector3(vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
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((double)Math.round(this.x), (double)Math.round(this.y), (double)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 List<Entity> getEntitiesWithin(World worldObj, Class<? extends Entity> par1Class) {
|
|
||||||
return worldObj.getEntitiesWithinAABB(par1Class, AxisAlignedBB.getBoundingBox((double)this.intX(), (double)this.intY(), (double)this.intZ(), (double)(this.intX() + 1), (double)(this.intY() + 1), (double)(this.intZ() + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 modifyPositionFromSide(ForgeDirection side, double amount) {
|
|
||||||
switch(side.ordinal()) {
|
|
||||||
case 0:
|
|
||||||
this.y -= amount;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
this.y += amount;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
this.z -= amount;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.z += amount;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
this.x -= amount;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
this.x += amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 modifyPositionFromSide(ForgeDirection side) {
|
|
||||||
this.modifyPositionFromSide(side, 1.0D);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 readFromNBT(NBTTagCompound nbtCompound) {
|
|
||||||
Vector3 tempVector = new Vector3();
|
|
||||||
tempVector.x = nbtCompound.getDouble("x");
|
|
||||||
tempVector.y = nbtCompound.getDouble("y");
|
|
||||||
tempVector.z = nbtCompound.getDouble("z");
|
|
||||||
return tempVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound par1NBTTagCompound) {
|
|
||||||
par1NBTTagCompound.setDouble("x", this.x);
|
|
||||||
par1NBTTagCompound.setDouble("y", this.y);
|
|
||||||
par1NBTTagCompound.setDouble("z", this.z);
|
|
||||||
return par1NBTTagCompound;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return ("X:" + this.x + "Y:" + this.y + "Z:" + this.z).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if(!(o instanceof Vector3)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
Vector3 vector3 = (Vector3)o;
|
|
||||||
return this.x == vector3.x && this.y == vector3.y && this.z == vector3.z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package universalelectricity.core.vector;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
|
|
||||||
public class VectorHelper {
|
|
||||||
|
|
||||||
public static final int[][] RELATIVE_MATRIX = new int[][]{{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}};
|
|
||||||
|
|
||||||
|
|
||||||
public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side) {
|
|
||||||
return front != ForgeDirection.UNKNOWN && side != ForgeDirection.UNKNOWN?ForgeDirection.getOrientation(RELATIVE_MATRIX[front.ordinal()][side.ordinal()]):ForgeDirection.UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side) {
|
|
||||||
TileEntity tileEntity = getTileEntityFromSide(world, position, side);
|
|
||||||
return tileEntity instanceof IConnector && ((IConnector)tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH))?tileEntity:null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side) {
|
|
||||||
return position.clone().modifyPositionFromSide(side).getTileEntity(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
package universalelectricity.prefab;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
|
||||||
import net.minecraft.util.DamageSource;
|
|
||||||
|
|
||||||
public class CustomDamageSource extends DamageSource {
|
|
||||||
|
|
||||||
public static final CustomDamageSource electrocution = ((CustomDamageSource)(new CustomDamageSource("electrocution")).setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!");
|
|
||||||
|
|
||||||
|
|
||||||
public CustomDamageSource(String damageType) {
|
|
||||||
super(damageType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomDamageSource setDeathMessage(String deathMessage) {
|
|
||||||
LanguageRegistry.instance().addStringLocalization("death.attack." + super.damageType, deathMessage);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DamageSource setDamageBypassesArmor() {
|
|
||||||
return super.setDamageBypassesArmor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DamageSource setDamageAllowedInCreativeMode() {
|
|
||||||
return super.setDamageAllowedInCreativeMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DamageSource setFireDamage() {
|
|
||||||
return super.setFireDamage();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
package universalelectricity.prefab;
|
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
|
||||||
import net.minecraft.client.renderer.OpenGlHelper;
|
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public abstract class GuiBase extends GuiScreen {
|
|
||||||
|
|
||||||
protected int xSize = 176;
|
|
||||||
protected int ySize = 166;
|
|
||||||
protected int guiLeft;
|
|
||||||
protected int guiTop;
|
|
||||||
|
|
||||||
|
|
||||||
public void initGui() {
|
|
||||||
super.initGui();
|
|
||||||
this.guiLeft = (this.width - this.xSize) / 2;
|
|
||||||
this.guiTop = (this.height - this.ySize) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawScreen(int par1, int par2, float par3) {
|
|
||||||
this.drawDefaultBackground();
|
|
||||||
int var4 = this.guiLeft;
|
|
||||||
int var5 = this.guiTop;
|
|
||||||
this.drawBackgroundLayer(par1, par2, par3);
|
|
||||||
GL11.glPushMatrix();
|
|
||||||
GL11.glTranslatef((float)var4, (float)var5, 0.0F);
|
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
GL11.glEnable('\u803a');
|
|
||||||
short var7 = 240;
|
|
||||||
short var8 = 240;
|
|
||||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var7 / 1.0F, (float)var8 / 1.0F);
|
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
this.drawForegroundLayer(par1, par2, par3);
|
|
||||||
GL11.glDisable('\u803a');
|
|
||||||
GL11.glDisable(2896);
|
|
||||||
GL11.glDisable(2929);
|
|
||||||
GL11.glPopMatrix();
|
|
||||||
super.drawScreen(par1, par2, par3);
|
|
||||||
GL11.glEnable(2896);
|
|
||||||
GL11.glEnable(2929);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void drawForegroundLayer(int var1, int var2, float var3);
|
|
||||||
|
|
||||||
protected abstract void drawBackgroundLayer(int var1, int var2, float var3);
|
|
||||||
|
|
||||||
protected void keyTyped(char x, int y) {
|
|
||||||
if(y == 1 || y == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
|
||||||
this.mc.thePlayer.closeScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean doesGuiPauseGame() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreen() {
|
|
||||||
super.updateScreen();
|
|
||||||
if(!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) {
|
|
||||||
this.mc.thePlayer.closeScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawTooltip(int x, int y, String ... toolTips) {
|
|
||||||
GL11.glDisable('\u803a');
|
|
||||||
RenderHelper.disableStandardItemLighting();
|
|
||||||
GL11.glDisable(2896);
|
|
||||||
GL11.glDisable(2929);
|
|
||||||
if(toolTips != null) {
|
|
||||||
int var5 = 0;
|
|
||||||
|
|
||||||
int var6;
|
|
||||||
int var7;
|
|
||||||
for(var6 = 0; var6 < toolTips.length; ++var6) {
|
|
||||||
var7 = this.fontRendererObj.getStringWidth(toolTips[var6]);
|
|
||||||
if(var7 > var5) {
|
|
||||||
var5 = var7;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var6 = x + 12;
|
|
||||||
var7 = y - 12;
|
|
||||||
int var9 = 8;
|
|
||||||
if(toolTips.length > 1) {
|
|
||||||
var9 += 2 + (toolTips.length - 1) * 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.guiTop + var7 + var9 + 6 > this.height) {
|
|
||||||
var7 = this.height - var9 - this.guiTop - 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.zLevel = 300.0F;
|
|
||||||
int var10 = -267386864;
|
|
||||||
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
|
|
||||||
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
|
|
||||||
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
|
|
||||||
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
|
|
||||||
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
|
|
||||||
int var11 = 1347420415;
|
|
||||||
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
|
|
||||||
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
|
|
||||||
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
|
|
||||||
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
|
|
||||||
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
|
|
||||||
|
|
||||||
for(int var13 = 0; var13 < toolTips.length; ++var13) {
|
|
||||||
String var14 = toolTips[var13];
|
|
||||||
this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1);
|
|
||||||
if(var13 == 0) {
|
|
||||||
var7 += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
var7 += 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.zLevel = 0.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
GL11.glEnable(2929);
|
|
||||||
GL11.glEnable(2896);
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
|
||||||
GL11.glEnable('\u803a');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
package universalelectricity.prefab;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
|
||||||
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.config.Configuration;
|
|
||||||
|
|
||||||
public class RecipeHelper {
|
|
||||||
|
|
||||||
public static List getRecipesByOutput(ItemStack output) {
|
|
||||||
ArrayList list = new ArrayList();
|
|
||||||
Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
Object obj = i$.next();
|
|
||||||
if(obj instanceof IRecipe && ((IRecipe)obj).getRecipeOutput() == output) {
|
|
||||||
list.add((IRecipe)obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe) {
|
|
||||||
Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator();
|
|
||||||
|
|
||||||
Object obj;
|
|
||||||
do {
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = i$.next();
|
|
||||||
} while(!(obj instanceof IRecipe));
|
|
||||||
} while(!((IRecipe)obj).equals(recipe) && obj != recipe);
|
|
||||||
|
|
||||||
CraftingManager.getInstance().getRecipeList().remove(obj);
|
|
||||||
CraftingManager.getInstance().getRecipeList().add(newRecipe);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe) {
|
|
||||||
if(removeRecipe(recipe)) {
|
|
||||||
CraftingManager.getInstance().getRecipeList().add(newRecipe);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean removeRecipe(IRecipe recipe) {
|
|
||||||
Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator();
|
|
||||||
|
|
||||||
Object obj;
|
|
||||||
do {
|
|
||||||
do {
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = i$.next();
|
|
||||||
} while(obj == null);
|
|
||||||
} while(!(obj instanceof IRecipe));
|
|
||||||
} while(!((IRecipe)obj).equals(recipe) && obj != recipe);
|
|
||||||
|
|
||||||
CraftingManager.getInstance().getRecipeList().remove(obj);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean removeRecipe(ItemStack stack) {
|
|
||||||
Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator();
|
|
||||||
|
|
||||||
Object obj;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = i$.next();
|
|
||||||
} while(obj == null || !(obj instanceof IRecipe) || ((IRecipe)obj).getRecipeOutput() == null || !((IRecipe)obj).getRecipeOutput().isItemEqual(stack));
|
|
||||||
|
|
||||||
CraftingManager.getInstance().getRecipeList().remove(obj);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean removeRecipes(ItemStack ... itemStacks) {
|
|
||||||
boolean didRemove = false;
|
|
||||||
Iterator itr = CraftingManager.getInstance().getRecipeList().iterator();
|
|
||||||
|
|
||||||
while(itr.hasNext()) {
|
|
||||||
Object obj = itr.next();
|
|
||||||
if(obj != null && obj instanceof IRecipe && ((IRecipe)obj).getRecipeOutput() != null) {
|
|
||||||
ItemStack[] arr$ = itemStacks;
|
|
||||||
int len$ = itemStacks.length;
|
|
||||||
|
|
||||||
for(int i$ = 0; i$ < len$; ++i$) {
|
|
||||||
ItemStack itemStack = arr$[i$];
|
|
||||||
if(((IRecipe)obj).getRecipeOutput().isItemEqual(itemStack)) {
|
|
||||||
itr.remove();
|
|
||||||
didRemove = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return didRemove;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,74 +0,0 @@
|
||||||
package universalelectricity.prefab;
|
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.inventory.Slot;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public class SlotSpecific extends Slot {
|
|
||||||
|
|
||||||
public ItemStack[] validItemStacks = new ItemStack[0];
|
|
||||||
public Class[] validClasses = new Class[0];
|
|
||||||
public boolean isInverted = false;
|
|
||||||
public boolean isMetadataSensitive = false;
|
|
||||||
|
|
||||||
|
|
||||||
public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, ItemStack ... itemStacks) {
|
|
||||||
super(par2IInventory, par3, par4, par5);
|
|
||||||
this.setItemStacks(itemStacks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, Class ... validClasses) {
|
|
||||||
super(par2IInventory, par3, par4, par5);
|
|
||||||
this.setClasses(validClasses);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlotSpecific setMetadataSensitive() {
|
|
||||||
this.isMetadataSensitive = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlotSpecific setItemStacks(ItemStack ... validItemStacks) {
|
|
||||||
this.validItemStacks = validItemStacks;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlotSpecific setClasses(Class ... validClasses) {
|
|
||||||
this.validClasses = validClasses;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlotSpecific toggleInverted() {
|
|
||||||
this.isInverted = !this.isInverted;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isItemValid(ItemStack compareStack) {
|
|
||||||
boolean returnValue = false;
|
|
||||||
ItemStack[] arr$ = this.validItemStacks;
|
|
||||||
int len$ = arr$.length;
|
|
||||||
|
|
||||||
int i$;
|
|
||||||
for(i$ = 0; i$ < len$; ++i$) {
|
|
||||||
ItemStack clazz = arr$[i$];
|
|
||||||
if(compareStack.isItemEqual(clazz) || !this.isMetadataSensitive && compareStack.getItem() == clazz.getItem()) {
|
|
||||||
returnValue = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!returnValue) {
|
|
||||||
Class[] var7 = this.validClasses;
|
|
||||||
len$ = var7.length;
|
|
||||||
|
|
||||||
for(i$ = 0; i$ < len$; ++i$) {
|
|
||||||
Class var8 = var7[i$];
|
|
||||||
if(var8.equals(compareStack.getItem().getClass()) || var8.isInstance(compareStack.getItem())) {
|
|
||||||
returnValue = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.isInverted?!returnValue:returnValue;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package universalelectricity.prefab;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
|
||||||
|
|
||||||
public class TranslationHelper {
|
|
||||||
|
|
||||||
public static int loadLanguages(String languagePath, String[] languageSupported) {
|
|
||||||
int languages = 0;
|
|
||||||
String[] arr$ = languageSupported;
|
|
||||||
int len$ = languageSupported.length;
|
|
||||||
|
|
||||||
for(int i$ = 0; i$ < len$; ++i$) {
|
|
||||||
String language = arr$[i$];
|
|
||||||
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false);
|
|
||||||
if(LanguageRegistry.instance().getStringLocalization("children", language) != "") {
|
|
||||||
try {
|
|
||||||
String[] e = LanguageRegistry.instance().getStringLocalization("children", language).split(",");
|
|
||||||
String[] arr$1 = e;
|
|
||||||
int len$1 = e.length;
|
|
||||||
|
|
||||||
for(int i$1 = 0; i$1 < len$1; ++i$1) {
|
|
||||||
String child = arr$1[i$1];
|
|
||||||
if(child != "" || child != null) {
|
|
||||||
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false);
|
|
||||||
++languages;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception var12) {
|
|
||||||
FMLLog.severe("Failed to load a child language file.", new Object[0]);
|
|
||||||
var12.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++languages;
|
|
||||||
}
|
|
||||||
|
|
||||||
return languages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLocal(String key) {
|
|
||||||
String text = LanguageRegistry.instance().getStringLocalization(key);
|
|
||||||
if(text == null || text == "") {
|
|
||||||
text = LanguageRegistry.instance().getStringLocalization(key, "en_US");
|
|
||||||
}
|
|
||||||
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,149 +0,0 @@
|
||||||
package universalelectricity.prefab.block;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockContainer;
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public abstract class BlockAdvanced extends BlockContainer {
|
|
||||||
|
|
||||||
public BlockAdvanced(Material material) {
|
|
||||||
super(material);
|
|
||||||
this.setHardness(0.6F);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
|
|
||||||
world.getBlockMetadata(x, y, z);
|
|
||||||
if(this.isUsableWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z)) {
|
|
||||||
this.damageWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z);
|
|
||||||
if(entityPlayer.isSneaking() && 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entityPlayer.isSneaking() && this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)?true:this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z) {
|
|
||||||
if(entityPlayer != null && itemStack != null) {
|
|
||||||
Class wrenchClass = itemStack.getItem().getClass();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Method e = wrenchClass.getMethod("canWrench", new Class[]{EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE});
|
|
||||||
return ((Boolean)e.invoke(itemStack.getItem(), new Object[]{entityPlayer, Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)})).booleanValue();
|
|
||||||
} catch (NoClassDefFoundError var8) {
|
|
||||||
;
|
|
||||||
} catch (Exception var9) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 var10) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
Method e;
|
|
||||||
try {
|
|
||||||
e = wrenchClass.getMethod("wrenchUsed", new Class[]{EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE});
|
|
||||||
e.invoke(itemStack.getItem(), new Object[]{entityPlayer, Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)});
|
|
||||||
return true;
|
|
||||||
} catch (Exception var9) {
|
|
||||||
try {
|
|
||||||
if(wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric")) {
|
|
||||||
e = wrenchClass.getMethod("damage", new Class[]{ItemStack.class, Integer.TYPE, EntityPlayer.class});
|
|
||||||
e.invoke(itemStack.getItem(), new Object[]{itemStack, Integer.valueOf(1), entityPlayer});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (Exception var8) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
|
|
||||||
this.dropEntireInventory(world, x, y, z, par5, par6);
|
|
||||||
super.breakBlock(world, x, y, z, par5, par6);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dropEntireInventory(World world, int x, int y, int z, Block par5, int par6) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
||||||
if(tileEntity != null && 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, (double)((float)x + var8), (double)((float)y + var9), (double)((float)z + var10), new ItemStack(var7.getItem(), var11, var7.getItemDamage()));
|
|
||||||
if(var7.hasTagCompound()) {
|
|
||||||
var12.getEntityItem().setTagCompound((NBTTagCompound)var7.getTagCompound().copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
float var13 = 0.05F;
|
|
||||||
var12.motionX = (double)((float)random.nextGaussian() * var13);
|
|
||||||
var12.motionY = (double)((float)random.nextGaussian() * var13 + 0.2F);
|
|
||||||
var12.motionZ = (double)((float)random.nextGaussian() * var13);
|
|
||||||
world.spawnEntityInWorld(var12);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package universalelectricity.prefab.block;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockContainer;
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.core.block.IConductor;
|
|
||||||
|
|
||||||
public abstract class BlockConductor extends BlockContainer {
|
|
||||||
|
|
||||||
public BlockConductor(Material material) {
|
|
||||||
super(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockAdded(World world, int x, int y, int z) {
|
|
||||||
super.onBlockAdded(world, x, y, z);
|
|
||||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
||||||
if(tileEntity instanceof IConductor) {
|
|
||||||
((IConductor)tileEntity).updateAdjacentConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block blockID) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
||||||
if(tileEntity instanceof IConductor) {
|
|
||||||
((IConductor)tileEntity).updateAdjacentConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +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.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.prefab.implement.IRotatable;
|
|
||||||
|
|
||||||
public abstract class BlockRotatable extends BlockAdvanced implements IRotatable {
|
|
||||||
|
|
||||||
public BlockRotatable(Material material) {
|
|
||||||
super(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
|
|
||||||
int angle = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
|
||||||
byte change = 3;
|
|
||||||
switch(angle) {
|
|
||||||
case 0:
|
|
||||||
change = 2;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
change = 5;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
change = 3;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
change = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setDirection(world, x, y, z, ForgeDirection.getOrientation(change));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) {
|
|
||||||
this.setDirection(world, x, y, z, ForgeDirection.getOrientation(ForgeDirection.ROTATION_MATRIX[0][this.getDirection(world, x, y, z).ordinal()]));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) {
|
|
||||||
return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection) {
|
|
||||||
world.setBlockMetadataWithNotify(x, y, z, facingDirection.ordinal(), 3);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,226 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import net.minecraft.command.CommandBase;
|
|
||||||
import net.minecraft.command.ICommandSender;
|
|
||||||
import net.minecraft.command.WrongUsageException;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.util.ChatComponentText;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class CommandFlag extends CommandBase {
|
|
||||||
|
|
||||||
public static final String[] COMMANDS = new String[]{"list", "setregion", "removeregion", "set"};
|
|
||||||
public String commandName;
|
|
||||||
public ModFlag modFlagData;
|
|
||||||
|
|
||||||
|
|
||||||
public CommandFlag(ModFlag modFlag) {
|
|
||||||
this.commandName = "modflag";
|
|
||||||
this.modFlagData = modFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandFlag(ModFlag modFlag, String commandName) {
|
|
||||||
this(modFlag);
|
|
||||||
this.commandName = commandName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandName() {
|
|
||||||
return this.commandName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandUsage(ICommandSender par1ICommandSender) {
|
|
||||||
String returnString = "";
|
|
||||||
String[] arr$ = COMMANDS;
|
|
||||||
int len$ = arr$.length;
|
|
||||||
|
|
||||||
for(int i$ = 0; i$ < len$; ++i$) {
|
|
||||||
String command = arr$[i$];
|
|
||||||
returnString = returnString + "\n/" + this.getCommandName() + " " + command;
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processCommand(ICommandSender sender, String[] args) {
|
|
||||||
if(args.length > 0) {
|
|
||||||
EntityPlayer entityPlayer = (EntityPlayer)sender;
|
|
||||||
FlagWorld flagWorld = this.modFlagData.getFlagWorld(entityPlayer.worldObj);
|
|
||||||
String commandName = args[0].toLowerCase();
|
|
||||||
String regionName;
|
|
||||||
String flagName;
|
|
||||||
FlagRegion flagRegion;
|
|
||||||
if(commandName.equalsIgnoreCase("list")) {
|
|
||||||
if(args.length > 1) {
|
|
||||||
regionName = args[1];
|
|
||||||
Iterator flagRegion1;
|
|
||||||
if(regionName.equalsIgnoreCase("all")) {
|
|
||||||
flagName = "";
|
|
||||||
flagRegion1 = this.modFlagData.getFlagWorlds().iterator();
|
|
||||||
|
|
||||||
FlagRegion i$1;
|
|
||||||
while(flagRegion1.hasNext()) {
|
|
||||||
for(Iterator flags1 = ((FlagWorld)flagRegion1.next()).getRegions().iterator(); flags1.hasNext(); flagName = flagName + " " + i$1.name + " (" + i$1.region.min.x + "," + i$1.region.min.z + ")" + ",") {
|
|
||||||
i$1 = (FlagRegion)flags1.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flagName != "") {
|
|
||||||
flagName = "List of regions in world:\n" + flagName;
|
|
||||||
} else {
|
|
||||||
flagName = "No regions in this world.";
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.addChatMessage(new ChatComponentText(flagName));
|
|
||||||
} else {
|
|
||||||
Flag flags2;
|
|
||||||
if(flagWorld.getRegion(regionName) != null) {
|
|
||||||
flagName = "";
|
|
||||||
|
|
||||||
for(flagRegion1 = flagWorld.getRegion(regionName).getFlags().iterator(); flagRegion1.hasNext(); flagName = flagName + " " + flags2.name + " => " + flags2.value + ",") {
|
|
||||||
flags2 = (Flag)flagRegion1.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flagName != "") {
|
|
||||||
flagName = "List of flags in region " + regionName + ":\n" + flagName;
|
|
||||||
} else {
|
|
||||||
flagName = "No flags in this region.";
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.addChatMessage(new ChatComponentText(flagName));
|
|
||||||
} else {
|
|
||||||
flagName = "Region does not exist, but here are existing flags in the position you are standing on:\n";
|
|
||||||
|
|
||||||
for(flagRegion1 = flagWorld.getFlagsInPosition(new Vector3(entityPlayer)).iterator(); flagRegion1.hasNext(); flagName = flagName + " " + flags2.name + "=>" + flags2.value + ",") {
|
|
||||||
flags2 = (Flag)flagRegion1.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.addChatMessage(new ChatComponentText(flagName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
regionName = "";
|
|
||||||
|
|
||||||
for(Iterator flagName3 = flagWorld.getRegions().iterator(); flagName3.hasNext(); regionName = regionName + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",") {
|
|
||||||
flagRegion = (FlagRegion)flagName3.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(regionName != "") {
|
|
||||||
regionName = "List of regions in this dimension:\n" + regionName;
|
|
||||||
} else {
|
|
||||||
regionName = "No regions in this dimension.";
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.addChatMessage(new ChatComponentText(regionName));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(commandName.equalsIgnoreCase("setregion")) {
|
|
||||||
if(args.length > 1) {
|
|
||||||
regionName = args[1];
|
|
||||||
if(regionName.equalsIgnoreCase("dimension")) {
|
|
||||||
if(flagWorld.addRegion(regionName, new Vector3(entityPlayer), 1)) {
|
|
||||||
sender.addChatMessage(new ChatComponentText("Created global dimension region setting."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(args.length <= 2) {
|
|
||||||
throw new WrongUsageException("/" + this.getCommandName() + " addregion <name> <radius>", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean flagName1 = false;
|
|
||||||
|
|
||||||
int flagName2;
|
|
||||||
try {
|
|
||||||
flagName2 = Integer.parseInt(args[2]);
|
|
||||||
} catch (Exception var12) {
|
|
||||||
throw new WrongUsageException("Radius not a number!", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flagName2 <= 0) {
|
|
||||||
throw new WrongUsageException("Radius has to be greater than zero!", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
flagRegion = flagWorld.getRegion(regionName);
|
|
||||||
if(flagRegion == null) {
|
|
||||||
if(flagWorld.addRegion(regionName, new Vector3(entityPlayer), flagName2)) {
|
|
||||||
sender.addChatMessage(new ChatComponentText("Region " + regionName + " added."));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
flagRegion.edit(new Vector3(entityPlayer), flagName2);
|
|
||||||
sender.addChatMessage(new ChatComponentText("Region " + regionName + " already exists. Modified region to have a radius of: " + flagName2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new WrongUsageException("Please specify the region name.", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(commandName.equalsIgnoreCase("removeregion")) {
|
|
||||||
if(args.length > 1) {
|
|
||||||
regionName = args[1];
|
|
||||||
if(flagWorld.removeRegion(regionName)) {
|
|
||||||
sender.addChatMessage(new ChatComponentText("Region with name " + regionName + " is removed."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new WrongUsageException("The specified region does not exist in this world.", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new WrongUsageException("Please specify the region name.", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(commandName.equalsIgnoreCase("set")) {
|
|
||||||
if(args.length <= 2) {
|
|
||||||
throw new WrongUsageException("/" + this.getCommandName() + " set <regionName> <flagName> <value>", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
regionName = args[1];
|
|
||||||
flagName = args[2];
|
|
||||||
flagRegion = flagWorld.getRegion(regionName);
|
|
||||||
if(flagRegion == null) {
|
|
||||||
throw new WrongUsageException("The specified region \'" + regionName + "\' does not exist.", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
String flags;
|
|
||||||
if(FlagRegistry.flags.contains(flagName)) {
|
|
||||||
if(args.length > 3) {
|
|
||||||
flags = args[3];
|
|
||||||
flagRegion.setFlag(flagName, flags);
|
|
||||||
sender.addChatMessage(new ChatComponentText("Flag \'" + flagName + "\' has been set to \'" + flags + "\' in " + regionName + "."));
|
|
||||||
} else {
|
|
||||||
flagRegion.removeFlag(flagName);
|
|
||||||
sender.addChatMessage(new ChatComponentText("Removed flag \'" + flagName + "\'."));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = "Flag does not exist. Existing flags:\n";
|
|
||||||
|
|
||||||
String registeredFlag;
|
|
||||||
for(Iterator i$ = FlagRegistry.flags.iterator(); i$.hasNext(); flags = flags + registeredFlag + ", ") {
|
|
||||||
registeredFlag = (String)i$.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new WrongUsageException(flags, new Object[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new WrongUsageException(this.getCommandUsage(sender), new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRequiredPermissionLevel() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
|
||||||
return args.length == 1?getListOfStringsMatchingLastWord(args, COMMANDS):null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
public class Flag extends FlagBase {
|
|
||||||
|
|
||||||
public FlagRegion flagRegion;
|
|
||||||
public String name;
|
|
||||||
public String value;
|
|
||||||
|
|
||||||
|
|
||||||
public Flag(FlagRegion flagRegion) {
|
|
||||||
this.flagRegion = flagRegion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flag(FlagRegion flagRegion, String name, String value) {
|
|
||||||
this(flagRegion);
|
|
||||||
this.name = name;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
|
||||||
this.name = nbt.getString("name");
|
|
||||||
this.value = nbt.getString("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
|
||||||
nbt.setString("name", this.name);
|
|
||||||
nbt.setString("value", this.value);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
public abstract class FlagBase {
|
|
||||||
|
|
||||||
public abstract void readFromNBT(NBTTagCompound var1);
|
|
||||||
|
|
||||||
public abstract void writeToNBT(NBTTagCompound var1);
|
|
||||||
|
|
||||||
public NBTTagCompound getNBT() {
|
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.writeToNBT(nbt);
|
|
||||||
} catch (Exception var3) {
|
|
||||||
System.out.println("Failed to read flag");
|
|
||||||
var3.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return nbt;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,130 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.prefab.vector.Region3;
|
|
||||||
|
|
||||||
public class FlagRegion extends FlagBase {
|
|
||||||
|
|
||||||
public FlagWorld flagWorld;
|
|
||||||
public String name;
|
|
||||||
public Region3 region;
|
|
||||||
private final List<Flag> flags = new ArrayList();
|
|
||||||
|
|
||||||
|
|
||||||
public FlagRegion(FlagWorld worldFlagData) {
|
|
||||||
this.flagWorld = worldFlagData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlagRegion(FlagWorld flagWorld, String name, Region3 region) {
|
|
||||||
this.flagWorld = flagWorld;
|
|
||||||
this.name = name;
|
|
||||||
this.region = region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
|
||||||
this.name = nbt.getString("name");
|
|
||||||
Vector3 startVector = Vector3.readFromNBT(nbt.getCompoundTag("min"));
|
|
||||||
Vector3 endVector = Vector3.readFromNBT(nbt.getCompoundTag("max"));
|
|
||||||
this.region = new Region3(startVector, endVector);
|
|
||||||
NBTTagList flagList = nbt.getTagList("flags", 10);
|
|
||||||
|
|
||||||
for(int i = 0; i < flagList.tagCount(); ++i) {
|
|
||||||
NBTTagCompound childNode = (NBTTagCompound)flagList.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
Flag e = new Flag(this);
|
|
||||||
e.readFromNBT(childNode);
|
|
||||||
this.flags.add(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
|
||||||
nbt.setString("name", this.name);
|
|
||||||
nbt.setTag("min", this.region.min.writeToNBT(new NBTTagCompound()));
|
|
||||||
nbt.setTag("max", this.region.max.writeToNBT(new NBTTagCompound()));
|
|
||||||
NBTTagList flagList = new NBTTagList();
|
|
||||||
|
|
||||||
for (Flag flag : this.getFlags()) {
|
|
||||||
flagList.appendTag(flag.getNBT());
|
|
||||||
}
|
|
||||||
|
|
||||||
nbt.setTag("flags", flagList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsValue(String flagName, String checkValue, Vector3 position) {
|
|
||||||
Iterator i$ = this.flags.iterator();
|
|
||||||
|
|
||||||
Flag flag;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
flag = (Flag)i$.next();
|
|
||||||
} while(!flag.name.equalsIgnoreCase(flagName) || !flag.value.equalsIgnoreCase(checkValue));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setFlag(String flagName, String value) {
|
|
||||||
this.removeFlag(flagName);
|
|
||||||
return value != null && value != "" && !this.containsFlag(flagName)?this.flags.add(new Flag(this, flagName, value)):false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsFlag(String flagName) {
|
|
||||||
Iterator i$ = this.flags.iterator();
|
|
||||||
|
|
||||||
Flag region;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
region = (Flag)i$.next();
|
|
||||||
} while(!region.name.equalsIgnoreCase(flagName));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeFlag(String flagName) {
|
|
||||||
Iterator i$ = this.flags.iterator();
|
|
||||||
|
|
||||||
Flag region;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
region = (Flag)i$.next();
|
|
||||||
} while(!region.name.equalsIgnoreCase(flagName));
|
|
||||||
|
|
||||||
this.flags.remove(region);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Flag> getFlags() {
|
|
||||||
Iterator<Flag> it = this.flags.iterator();
|
|
||||||
|
|
||||||
while(it.hasNext()) {
|
|
||||||
Flag flag = (Flag)it.next();
|
|
||||||
if(flag == null) {
|
|
||||||
it.remove();
|
|
||||||
} else if(flag.name == null || flag.name == "") {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void edit(Vector3 position, int radius) {
|
|
||||||
Vector3 minVec = new Vector3((double)(position.intX() - radius), 0.0D, (double)(position.intZ() - radius));
|
|
||||||
Vector3 maxVec = new Vector3((double)(position.intX() + radius), (double)this.flagWorld.world.getHeight(), (double)(position.intZ() + radius));
|
|
||||||
this.region = new Region3(minVec, maxVec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import universalelectricity.prefab.flag.ModFlag;
|
|
||||||
|
|
||||||
public class FlagRegistry {
|
|
||||||
|
|
||||||
public static final String DEFAULT_NAME = "ModFlags";
|
|
||||||
private static final HashMap MOD_FLAGS = new HashMap();
|
|
||||||
public static final List flags = new ArrayList();
|
|
||||||
public static boolean isInitiated = false;
|
|
||||||
|
|
||||||
|
|
||||||
public static void registerModFlag(String name, ModFlag flagData) {
|
|
||||||
MOD_FLAGS.put(name, flagData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ModFlag getModFlag(String name) {
|
|
||||||
return (ModFlag)MOD_FLAGS.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String registerFlag(String name) {
|
|
||||||
if(!isInitiated) {
|
|
||||||
isInitiated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = name.toLowerCase();
|
|
||||||
if(!flags.contains(name)) {
|
|
||||||
flags.add(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,164 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.prefab.vector.Region3;
|
|
||||||
|
|
||||||
public class FlagWorld extends FlagBase {
|
|
||||||
|
|
||||||
public static final String GLOBAL_REGION = "dimension";
|
|
||||||
public World world;
|
|
||||||
private final List<FlagRegion> regions = new ArrayList();
|
|
||||||
|
|
||||||
|
|
||||||
public FlagWorld(World world) {
|
|
||||||
this.world = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
|
||||||
|
|
||||||
for(String key : (Set<String>) nbt.func_150296_c()) {
|
|
||||||
NBTTagCompound childCompound = nbt.getCompoundTag(key);
|
|
||||||
FlagRegion e = new FlagRegion(this);
|
|
||||||
e.readFromNBT(childCompound);
|
|
||||||
this.regions.add(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
|
||||||
Iterator i$ = this.regions.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
FlagRegion region = (FlagRegion)i$.next();
|
|
||||||
|
|
||||||
try {
|
|
||||||
NBTTagCompound e = new NBTTagCompound();
|
|
||||||
region.writeToNBT(e);
|
|
||||||
nbt.setTag(region.name, e);
|
|
||||||
} catch (Exception var5) {
|
|
||||||
System.out.println("Failed to save world flag data: " + region.name);
|
|
||||||
var5.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List getFlagsInPosition(Vector3 position) {
|
|
||||||
ArrayList returnFlags = new ArrayList();
|
|
||||||
Iterator i$ = this.regions.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
FlagRegion flagRegion = (FlagRegion)i$.next();
|
|
||||||
if(flagRegion.region.isIn(position) || flagRegion.name.equalsIgnoreCase("dimension")) {
|
|
||||||
Iterator i$1 = flagRegion.getFlags().iterator();
|
|
||||||
|
|
||||||
while(i$1.hasNext()) {
|
|
||||||
Flag flag = (Flag)i$1.next();
|
|
||||||
returnFlags.add(flag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnFlags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List getValues(String flagName, Vector3 position) {
|
|
||||||
ArrayList values = new ArrayList();
|
|
||||||
Iterator i$ = this.getFlagsInPosition(position).iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
Flag flag = (Flag)i$.next();
|
|
||||||
values.add(flag.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsValue(String flagName, String checkValue, Vector3 position) {
|
|
||||||
Iterator i$ = this.getFlagsInPosition(position).iterator();
|
|
||||||
|
|
||||||
Flag flag;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
flag = (Flag)i$.next();
|
|
||||||
} while(!flag.name.equalsIgnoreCase(flagName) || !flag.value.equalsIgnoreCase(checkValue));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addRegion(String name, Vector3 position, int radius) {
|
|
||||||
Vector3 minVec = new Vector3((double)(position.intX() - radius), 0.0D, (double)(position.intZ() - radius));
|
|
||||||
Vector3 maxVec = new Vector3((double)(position.intX() + radius), (double)this.world.getHeight(), (double)(position.intZ() + radius));
|
|
||||||
return this.regions.add(new FlagRegion(this, name, new Region3(minVec, maxVec)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlagRegion getRegion(String name) {
|
|
||||||
Iterator i$ = this.regions.iterator();
|
|
||||||
|
|
||||||
FlagRegion region;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
region = (FlagRegion)i$.next();
|
|
||||||
} while(!region.name.equals(name));
|
|
||||||
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List getRegions(Vector3 position) {
|
|
||||||
ArrayList returnRegions = new ArrayList();
|
|
||||||
Iterator i$ = this.regions.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
FlagRegion region = (FlagRegion)i$.next();
|
|
||||||
if(region.region.isIn(position)) {
|
|
||||||
returnRegions.add(region);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnRegions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeRegion(String name) {
|
|
||||||
Iterator i$ = this.regions.iterator();
|
|
||||||
|
|
||||||
FlagRegion region;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
region = (FlagRegion)i$.next();
|
|
||||||
} while(!region.name.equals(name));
|
|
||||||
|
|
||||||
this.regions.remove(region);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FlagRegion> getRegions() {
|
|
||||||
Iterator it = this.regions.iterator();
|
|
||||||
|
|
||||||
while(it.hasNext()) {
|
|
||||||
FlagRegion region = (FlagRegion)it.next();
|
|
||||||
if(region == null) {
|
|
||||||
it.remove();
|
|
||||||
} else if(region.name == null || region.name == "") {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.regions;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.WorldServer;
|
|
||||||
import net.minecraftforge.common.DimensionManager;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class ModFlag extends FlagBase {
|
|
||||||
|
|
||||||
private final List<FlagWorld> flagWorlds = new ArrayList();
|
|
||||||
|
|
||||||
|
|
||||||
public ModFlag(NBTTagCompound nbt) {
|
|
||||||
this.readFromNBT(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
|
||||||
if(nbt != null) {
|
|
||||||
for (String key : (Set<String>) nbt.func_150296_c()) {
|
|
||||||
NBTTagCompound dimensionCompound = nbt.getCompoundTag(key);
|
|
||||||
int e = Integer.parseInt(key.replace("dim_", ""));
|
|
||||||
WorldServer world = DimensionManager.getWorld(e);
|
|
||||||
FlagWorld flagWorld = new FlagWorld(world);
|
|
||||||
flagWorld.readFromNBT(dimensionCompound);
|
|
||||||
this.flagWorlds.add(flagWorld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
|
||||||
if(nbt != null) {
|
|
||||||
Iterator i$ = this.flagWorlds.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
FlagWorld worldData = (FlagWorld)i$.next();
|
|
||||||
|
|
||||||
try {
|
|
||||||
nbt.setTag("dim_" + worldData.world.provider.dimensionId, worldData.getNBT());
|
|
||||||
} catch (Exception var5) {
|
|
||||||
System.out.println("Mod Flag: Failed to save world flag data: " + worldData.world);
|
|
||||||
var5.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlagWorld getFlagWorld(World world) {
|
|
||||||
FlagWorld worldData = null;
|
|
||||||
if(world != null) {
|
|
||||||
Iterator i$ = this.flagWorlds.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
FlagWorld data = (FlagWorld)i$.next();
|
|
||||||
if(data.world != null && data.world.provider != null && data.world.provider.dimensionId == world.provider.dimensionId) {
|
|
||||||
worldData = data;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(worldData == null) {
|
|
||||||
worldData = new FlagWorld(world);
|
|
||||||
this.flagWorlds.add(worldData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return worldData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsValue(World world, String flagName, String checkValue, Vector3 position) {
|
|
||||||
return this.getFlagWorld(world).containsValue(flagName, checkValue, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FlagWorld> getFlagWorlds() {
|
|
||||||
return this.flagWorlds;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
package universalelectricity.prefab.flag;
|
|
||||||
|
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
|
|
||||||
public class NBTFileLoader {
|
|
||||||
|
|
||||||
public static boolean saveData(File saveDirectory, String filename, NBTTagCompound data) {
|
|
||||||
try {
|
|
||||||
File e = new File(saveDirectory, filename + "_tmp.dat");
|
|
||||||
File file = new File(saveDirectory, filename + ".dat");
|
|
||||||
CompressedStreamTools.writeCompressed(data, new FileOutputStream(e));
|
|
||||||
if(file.exists()) {
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
e.renameTo(file);
|
|
||||||
FMLLog.fine("Saved " + filename + " NBT data file successfully.", new Object[0]);
|
|
||||||
return true;
|
|
||||||
} catch (Exception var5) {
|
|
||||||
System.out.println("Failed to save " + filename + ".dat!");
|
|
||||||
var5.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean saveData(String filename, NBTTagCompound data) {
|
|
||||||
return saveData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NBTTagCompound loadData(File saveDirectory, String filename) {
|
|
||||||
try {
|
|
||||||
File e = new File(saveDirectory, filename + ".dat");
|
|
||||||
if(e.exists()) {
|
|
||||||
FMLLog.fine("Loaded " + filename + " data.", new Object[0]);
|
|
||||||
return CompressedStreamTools.readCompressed(new FileInputStream(e));
|
|
||||||
} else {
|
|
||||||
FMLLog.fine("Created new " + filename + " data.", new Object[0]);
|
|
||||||
return new NBTTagCompound();
|
|
||||||
}
|
|
||||||
} catch (Exception var3) {
|
|
||||||
System.out.println("Failed to load " + filename + ".dat!");
|
|
||||||
var3.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NBTTagCompound loadData(String filename) {
|
|
||||||
return loadData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getSaveDirectory(String worldName) {
|
|
||||||
File parent = getBaseDirectory();
|
|
||||||
if(FMLCommonHandler.instance().getSide().isClient()) {
|
|
||||||
parent = new File(getBaseDirectory(), "saves" + File.separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new File(parent, worldName + File.separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getBaseDirectory() {
|
|
||||||
if(FMLCommonHandler.instance().getSide().isClient()) {
|
|
||||||
FMLClientHandler.instance().getClient();
|
|
||||||
return Minecraft.getMinecraft().mcDataDir;
|
|
||||||
} else {
|
|
||||||
return new File(".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package universalelectricity.prefab.implement;
|
|
||||||
|
|
||||||
|
|
||||||
public interface IDisableable {
|
|
||||||
|
|
||||||
void onDisable(int var1);
|
|
||||||
|
|
||||||
boolean isDisabled();
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package universalelectricity.prefab.implement;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IRedstoneProvider {
|
|
||||||
|
|
||||||
boolean isPoweringTo(ForgeDirection var1);
|
|
||||||
|
|
||||||
boolean isIndirectlyPoweringTo(ForgeDirection var1);
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package universalelectricity.prefab.implement;
|
|
||||||
|
|
||||||
|
|
||||||
public interface IRedstoneReceptor {
|
|
||||||
|
|
||||||
void onPowerOn();
|
|
||||||
|
|
||||||
void onPowerOff();
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package universalelectricity.prefab.implement;
|
|
||||||
|
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IRotatable {
|
|
||||||
|
|
||||||
ForgeDirection getDirection(IBlockAccess var1, int var2, int var3, int var4);
|
|
||||||
|
|
||||||
void setDirection(World var1, int var2, int var3, int var4, ForgeDirection var5);
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package universalelectricity.prefab.implement;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ITier {
|
|
||||||
|
|
||||||
int getTier();
|
|
||||||
|
|
||||||
void setTier(int var1);
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package universalelectricity.prefab.implement;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
|
|
||||||
public interface IToolConfigurator {
|
|
||||||
|
|
||||||
boolean canWrench(EntityPlayer var1, int var2, int var3, int var4);
|
|
||||||
|
|
||||||
void wrenchUsed(EntityPlayer var1, int var2, int var3, int var4);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package universalelectricity.prefab.modifier;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public interface IModifier
|
|
||||||
{
|
|
||||||
String getType(final ItemStack p0);
|
|
||||||
|
|
||||||
double getEffectiveness(final ItemStack p0);
|
|
||||||
|
|
||||||
int getTier(final ItemStack p0);
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package universalelectricity.prefab.modifier;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.inventory.Slot;
|
|
||||||
|
|
||||||
public class SlotModifier extends Slot
|
|
||||||
{
|
|
||||||
public SlotModifier(final IInventory par2IInventory, final int par3, final int par4, final int par5) {
|
|
||||||
super(par2IInventory, par3, par4, par5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isItemValid(final ItemStack par1ItemStack) {
|
|
||||||
return par1ItemStack.getItem() instanceof IModifier;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,117 +0,0 @@
|
||||||
package universalelectricity.prefab.multiblock;
|
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
||||||
import java.util.Random;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockContainer;
|
|
||||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class BlockMulti extends BlockContainer {
|
|
||||||
|
|
||||||
public String textureName = null;
|
|
||||||
public String channel = "";
|
|
||||||
|
|
||||||
|
|
||||||
public BlockMulti() {
|
|
||||||
super(UniversalElectricity.machine);
|
|
||||||
this.setHardness(0.8F);
|
|
||||||
this.setBlockName("multiBlock");
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockMulti setChannel(String channel) {
|
|
||||||
this.channel = channel;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockMulti setTextureName(String name) {
|
|
||||||
this.textureName = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock) {
|
|
||||||
worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this);
|
|
||||||
TileEntity tile = position.getTileEntity(worldObj);
|
|
||||||
if (tile instanceof TileEntityMulti) {
|
|
||||||
((TileEntityMulti)tile).setMainBlock(mainBlock);
|
|
||||||
} else {
|
|
||||||
TileEntityMulti newTile = (TileEntityMulti)createNewTileEntity(worldObj, 0);
|
|
||||||
worldObj.setTileEntity(position.intX(), position.intY(), position.intZ(), newTile);
|
|
||||||
newTile.setMainBlock(mainBlock);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
@Override
|
|
||||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
|
||||||
if(this.textureName != null) {
|
|
||||||
this.blockIcon = iconRegister.registerIcon(this.textureName);
|
|
||||||
} else {
|
|
||||||
super.registerBlockIcons(iconRegister);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
||||||
if(tileEntity instanceof TileEntityMulti) {
|
|
||||||
((TileEntityMulti)tileEntity).onBlockRemoval();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.breakBlock(world, x, y, z, par5, par6);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
|
|
||||||
TileEntityMulti tileEntity = (TileEntityMulti)par1World.getTileEntity(x, y, z);
|
|
||||||
return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int quantityDropped(Random par1Random) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRenderType() {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOpaqueCube() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean renderAsNormalBlock() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity createNewTileEntity(World var1, int meta) {
|
|
||||||
return new TileEntityMulti(this.channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z) {
|
|
||||||
TileEntity tileEntity = par1World.getTileEntity(x, y, z);
|
|
||||||
Vector3 mainBlockPosition = ((TileEntityMulti)tileEntity).mainBlockPosition;
|
|
||||||
if(mainBlockPosition != null) {
|
|
||||||
Block mainBlockID = par1World.getBlock(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
|
|
||||||
if(mainBlockID != Blocks.air) {
|
|
||||||
return mainBlockID.getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package universalelectricity.prefab.multiblock;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
|
|
||||||
public interface IBlockActivate {
|
|
||||||
|
|
||||||
boolean onActivated(EntityPlayer var1);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package universalelectricity.prefab.multiblock;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.prefab.multiblock.IBlockActivate;
|
|
||||||
|
|
||||||
public interface IMultiBlock extends IBlockActivate {
|
|
||||||
|
|
||||||
void onCreate(Vector3 var1);
|
|
||||||
|
|
||||||
void onDestroy(TileEntity var1);
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
package universalelectricity.prefab.multiblock;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.Packet;
|
|
||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class TileEntityMulti extends TileEntity {
|
|
||||||
|
|
||||||
public Vector3 mainBlockPosition;
|
|
||||||
public String channel;
|
|
||||||
|
|
||||||
|
|
||||||
public TileEntityMulti() {}
|
|
||||||
|
|
||||||
public TileEntityMulti(String channel) {
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMainBlock(Vector3 mainBlock) {
|
|
||||||
this.mainBlockPosition = mainBlock;
|
|
||||||
if(!this.worldObj.isRemote) {
|
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Packet getDescriptionPacket() {
|
|
||||||
if(this.mainBlockPosition == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
NBTTagCompound nbt = this.mainBlockPosition.writeToNBT(new NBTTagCompound());
|
|
||||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(),nbt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBlockRemoval() {
|
|
||||||
if(this.mainBlockPosition != null) {
|
|
||||||
TileEntity tileEntity = this.worldObj.getTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
|
|
||||||
if(tileEntity != null && tileEntity instanceof IMultiBlock) {
|
|
||||||
IMultiBlock mainBlock = (IMultiBlock)tileEntity;
|
|
||||||
if(mainBlock != null) {
|
|
||||||
mainBlock.onDestroy(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer) {
|
|
||||||
if(this.mainBlockPosition != null) {
|
|
||||||
TileEntity tileEntity = this.worldObj.getTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
|
|
||||||
if(tileEntity != null && tileEntity instanceof IMultiBlock) {
|
|
||||||
return ((IMultiBlock)tileEntity).onActivated(par5EntityPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
|
||||||
super.readFromNBT(nbt);
|
|
||||||
this.mainBlockPosition = Vector3.readFromNBT(nbt.getCompoundTag("mainBlockPosition"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
|
||||||
super.writeToNBT(nbt);
|
|
||||||
if(this.mainBlockPosition != null) {
|
|
||||||
nbt.setTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canUpdate() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
|
||||||
NBTTagCompound nbt = pkt.func_148857_g();
|
|
||||||
this.mainBlockPosition = Vector3.readFromNBT(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package universalelectricity.prefab.ore;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
|
||||||
import java.util.Random;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.chunk.IChunkProvider;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
public abstract class OreGenBase {
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
public String oreDictionaryName;
|
|
||||||
public boolean shouldGenerate = false;
|
|
||||||
public int blockIndexTexture;
|
|
||||||
public ItemStack oreStack;
|
|
||||||
public Block oreID;
|
|
||||||
public int oreMeta;
|
|
||||||
public int harvestLevel;
|
|
||||||
public String harvestTool;
|
|
||||||
|
|
||||||
|
|
||||||
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 = Block.getBlockFromItem(stack.getItem());
|
|
||||||
this.oreMeta = stack.getItemDamage();
|
|
||||||
OreDictionary.registerOre(this.oreDictionaryName, stack);
|
|
||||||
oreID.setHarvestLevel(harvestTool, harvestLevel, stack.getItemDamage());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
FMLLog.severe("ItemStack is null while registering ore generation!", new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public OreGenBase enable(Configuration config) {
|
|
||||||
this.shouldGenerate = shouldGenerateOre(config, this.name);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 var1, Random var2, int var3, int var4);
|
|
||||||
|
|
||||||
public abstract boolean isOreGeneratedInWorld(World var1, IChunkProvider var2);
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
package universalelectricity.prefab.ore;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class OreGenReplace extends OreGenBase {
|
|
||||||
|
|
||||||
public int minGenerateLevel;
|
|
||||||
public int maxGenerateLevel;
|
|
||||||
public int amountPerChunk;
|
|
||||||
public int amountPerBranch;
|
|
||||||
public Block replaceID;
|
|
||||||
public boolean ignoreSurface = false;
|
|
||||||
public boolean ignoreNether = true;
|
|
||||||
public boolean ignoreEnd = true;
|
|
||||||
|
|
||||||
|
|
||||||
public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, Block replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) {
|
|
||||||
super(name, oreDiectionaryName, stack, harvestTool, harvestLevel);
|
|
||||||
this.minGenerateLevel = minGenerateLevel;
|
|
||||||
this.maxGenerateLevel = maxGenerateLevel;
|
|
||||||
this.amountPerChunk = amountPerChunk;
|
|
||||||
this.amountPerBranch = amountPerBranch;
|
|
||||||
this.replaceID = replaceID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generate(World world, Random random, int varX, int varZ) {
|
|
||||||
try {
|
|
||||||
for(int e = 0; e < this.amountPerChunk; ++e) {
|
|
||||||
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 var9) {
|
|
||||||
System.out.println("Error generating ore: " + super.name);
|
|
||||||
var9.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5) {
|
|
||||||
float var6 = par2Random.nextFloat() * 3.1415927F;
|
|
||||||
double var7 = (double)((float)(par3 + 8) + MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F);
|
|
||||||
double var9 = (double)((float)(par3 + 8) - MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F);
|
|
||||||
double var11 = (double)((float)(par5 + 8) + MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F);
|
|
||||||
double var13 = (double)((float)(par5 + 8) - MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F);
|
|
||||||
double var15 = (double)(par4 + par2Random.nextInt(3) - 2);
|
|
||||||
double var17 = (double)(par4 + par2Random.nextInt(3) - 2);
|
|
||||||
|
|
||||||
for(int var19 = 0; var19 <= this.amountPerBranch; ++var19) {
|
|
||||||
double var20 = var7 + (var9 - var7) * (double)var19 / (double)this.amountPerBranch;
|
|
||||||
double var22 = var15 + (var17 - var15) * (double)var19 / (double)this.amountPerBranch;
|
|
||||||
double var24 = var11 + (var13 - var11) * (double)var19 / (double)this.amountPerBranch;
|
|
||||||
double var26 = par2Random.nextDouble() * (double)this.amountPerBranch / 16.0D;
|
|
||||||
double var28 = (double)(MathHelper.sin((float)var19 * 3.1415927F / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
|
||||||
double var30 = (double)(MathHelper.sin((float)var19 * 3.1415927F / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
|
||||||
int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
|
|
||||||
int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
|
|
||||||
int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
|
|
||||||
int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
|
|
||||||
int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
|
|
||||||
int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);
|
|
||||||
|
|
||||||
for(int var38 = var32; var38 <= var35; ++var38) {
|
|
||||||
double var39 = ((double)var38 + 0.5D - var20) / (var28 / 2.0D);
|
|
||||||
if(var39 * var39 < 1.0D) {
|
|
||||||
for(int var41 = var33; var41 <= var36; ++var41) {
|
|
||||||
double var42 = ((double)var41 + 0.5D - var22) / (var30 / 2.0D);
|
|
||||||
if(var39 * var39 + var42 * var42 < 1.0D) {
|
|
||||||
for(int var44 = var34; var44 <= var37; ++var44) {
|
|
||||||
double var45 = ((double)var44 + 0.5D - var24) / (var28 / 2.0D);
|
|
||||||
Block block = par1World.getBlock(var38, var41, var44);
|
|
||||||
if(var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == Blocks.air || block == this.replaceID)) {
|
|
||||||
par1World.setBlock(var38, var41, var44, super.oreID, super.oreMeta, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator) {
|
|
||||||
return !super.shouldGenerate?false:(this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate?false:(this.ignoreNether && chunkGenerator instanceof ChunkProviderHell?false:!this.ignoreEnd || !(chunkGenerator instanceof ChunkProviderEnd)));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package universalelectricity.prefab.ore;
|
|
||||||
|
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import universalelectricity.prefab.ore.OreGenReplace;
|
|
||||||
|
|
||||||
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, Blocks.stone, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,60 +0,0 @@
|
||||||
package universalelectricity.prefab.ore;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.IWorldGenerator;
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.chunk.IChunkProvider;
|
|
||||||
import universalelectricity.prefab.ore.OreGenBase;
|
|
||||||
|
|
||||||
public class OreGenerator implements IWorldGenerator {
|
|
||||||
|
|
||||||
public static boolean isInitiated = false;
|
|
||||||
private static final List ORES_TO_GENERATE = new ArrayList();
|
|
||||||
|
|
||||||
|
|
||||||
public static void addOre(OreGenBase data) {
|
|
||||||
if(!isInitiated) {
|
|
||||||
GameRegistry.registerWorldGenerator(new OreGenerator(), 10); //TODO figure out the right value instead of 10
|
|
||||||
}
|
|
||||||
|
|
||||||
ORES_TO_GENERATE.add(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean oreExists(String oreName) {
|
|
||||||
Iterator i$ = ORES_TO_GENERATE.iterator();
|
|
||||||
|
|
||||||
OreGenBase ore;
|
|
||||||
do {
|
|
||||||
if(!i$.hasNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ore = (OreGenBase)i$.next();
|
|
||||||
} while(ore.oreDictionaryName != oreName);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeOre(OreGenBase data) {
|
|
||||||
ORES_TO_GENERATE.remove(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
|
|
||||||
chunkX <<= 4;
|
|
||||||
chunkZ <<= 4;
|
|
||||||
Iterator i$ = ORES_TO_GENERATE.iterator();
|
|
||||||
|
|
||||||
while(i$.hasNext()) {
|
|
||||||
OreGenBase oreData = (OreGenBase)i$.next();
|
|
||||||
if(oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator)) {
|
|
||||||
oreData.generate(world, rand, chunkX, chunkZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package universalelectricity.prefab.potion;
|
|
||||||
|
|
||||||
import net.minecraft.potion.Potion;
|
|
||||||
|
|
||||||
public abstract class CustomPotion extends Potion {
|
|
||||||
|
|
||||||
public CustomPotion(int id, boolean isBadEffect, int color, String name) {
|
|
||||||
super(id, isBadEffect, color);
|
|
||||||
this.setPotionName("potion." + name);
|
|
||||||
Potion.potionTypes[this.getId()] = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Potion setIconIndex(int par1, int par2) {
|
|
||||||
super.setIconIndex(par1, par2);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Potion setEffectiveness(double par1) {
|
|
||||||
super.setEffectiveness(par1);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomPotionEffect(int potionID, int duration, int amplifier, List<ItemStack> curativeItems) {
|
|
||||||
super(potionID, duration, amplifier);
|
|
||||||
if(curativeItems == null) {
|
|
||||||
this.setCurativeItems(new ArrayList());
|
|
||||||
} else {
|
|
||||||
this.setCurativeItems(curativeItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,107 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.api.CompatibilityModule;
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class ElectricTileDriver {
|
|
||||||
|
|
||||||
TileEntity handler;
|
|
||||||
|
|
||||||
public ElectricTileDriver(TileEntity handler) {
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void invalidate() {
|
|
||||||
ElectricityNetworkHelper.invalidate(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean tick() {
|
|
||||||
if (handler.isInvalid()) return false;
|
|
||||||
Map<ForgeDirection, IElectricityNetwork> networks = getNetworks();
|
|
||||||
Set<ForgeDirection> inputSides = new HashSet<>();
|
|
||||||
if (CompatibilityModule.canReceive(handler, ForgeDirection.UNKNOWN)) {
|
|
||||||
inputSides = consume(networks);
|
|
||||||
}
|
|
||||||
if (CompatibilityModule.canExtract(handler, ForgeDirection.UNKNOWN)) {
|
|
||||||
produce(networks, inputSides);
|
|
||||||
}
|
|
||||||
return networks.size() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<ForgeDirection> consume(Map<ForgeDirection, IElectricityNetwork> networks) {
|
|
||||||
Set<ForgeDirection> inputSides = new HashSet<>();
|
|
||||||
|
|
||||||
if (networks.size() > 0) {
|
|
||||||
double demand = CompatibilityModule.getDemandedJoules(handler);
|
|
||||||
double voltage = CompatibilityModule.getInputVoltage(handler);
|
|
||||||
double wattsPerSide = demand / networks.size();
|
|
||||||
for (ForgeDirection side : networks.keySet()) {
|
|
||||||
IElectricityNetwork net = networks.get(side);
|
|
||||||
if (CompatibilityModule.canReceive(handler, side) && wattsPerSide > 0 && demand > 0) {
|
|
||||||
inputSides.add(side);
|
|
||||||
net.startRequesting(handler, wattsPerSide / voltage, voltage);
|
|
||||||
ElectricityPack receivedPack = net.consumeElectricity(handler);
|
|
||||||
if (receivedPack.voltage > voltage && UniversalElectricity.isVoltageSensitive) {
|
|
||||||
handler.getWorldObj().createExplosion(null, handler.xCoord, handler.yCoord, handler.zCoord, 1, true);
|
|
||||||
return EnumSet.allOf(ForgeDirection.class);
|
|
||||||
}
|
|
||||||
CompatibilityModule.receiveEnergy(handler, side, receivedPack.getWatts(), true);
|
|
||||||
} else {
|
|
||||||
net.stopRequesting(handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return inputSides;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void produce(Map<ForgeDirection, IElectricityNetwork> networks, Set<ForgeDirection> inputSides) {
|
|
||||||
if ((networks.size() - inputSides.size()) > 0) {
|
|
||||||
double provided = CompatibilityModule.getProvidedJoules(handler);
|
|
||||||
double voltage = CompatibilityModule.getOutputVoltage(handler);
|
|
||||||
double wattsPerSide = provided / (networks.size() - inputSides.size());
|
|
||||||
for (ForgeDirection side : networks.keySet()) {
|
|
||||||
IElectricityNetwork net = networks.get(side);
|
|
||||||
if (!inputSides.contains(side) && CompatibilityModule.canExtract(handler, side) && wattsPerSide > 0 && provided > 0) {
|
|
||||||
double amperes = Math.min(wattsPerSide / voltage, net.getRequest(new TileEntity[]{handler}).amperes);
|
|
||||||
net.startProducing(handler, amperes, voltage);
|
|
||||||
CompatibilityModule.extractEnergy(handler, side, new ElectricityPack(amperes, voltage).getWatts(), true);
|
|
||||||
} else {
|
|
||||||
net.stopProducing(handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<ForgeDirection, IElectricityNetwork> getNetworks() {
|
|
||||||
Map<ForgeDirection, IElectricityNetwork> networks = new HashMap<>();
|
|
||||||
|
|
||||||
for(ForgeDirection dir : ForgeDirection.values()) {
|
|
||||||
if (CompatibilityModule.canReceive(handler, dir) || CompatibilityModule.canExtract(handler, dir)) {
|
|
||||||
Vector3 position = new Vector3(handler);
|
|
||||||
position.modifyPositionFromSide(dir);
|
|
||||||
TileEntity outputConductor = position.getTileEntity(handler.getWorldObj());
|
|
||||||
IElectricityNetwork electricityNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputConductor, dir);
|
|
||||||
if(electricityNetwork != null && !networks.containsValue(electricityNetwork)) {
|
|
||||||
networks.put(dir, electricityNetwork);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return networks;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
|
|
||||||
public abstract class TileEntityAdvanced extends TileEntity {
|
|
||||||
|
|
||||||
protected long ticks = 0L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
if(this.ticks == 0L) {
|
|
||||||
this.initiate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.ticks >= Long.MAX_VALUE) {
|
|
||||||
this.ticks = 1L;
|
|
||||||
}
|
|
||||||
|
|
||||||
++this.ticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.blockType;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,143 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.Packet;
|
|
||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.compat.CompatHandler;
|
|
||||||
import universalelectricity.core.block.IConductor;
|
|
||||||
import universalelectricity.core.block.INetworkProvider;
|
|
||||||
import universalelectricity.core.block.ISelfDriven;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetwork;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
|
||||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.core.vector.VectorHelper;
|
|
||||||
|
|
||||||
public abstract class TileEntityConductor extends TileEntityAdvanced implements IConductor {
|
|
||||||
|
|
||||||
private IElectricityNetwork network;
|
|
||||||
public boolean[] visuallyConnected = new boolean[]{false, false, false, false, false, false};
|
|
||||||
public TileEntity[] connectedBlocks = new TileEntity[]{null, null, null, null, null, null};
|
|
||||||
protected String channel = "";
|
|
||||||
|
|
||||||
|
|
||||||
public void updateConnection(TileEntity tileEntity, ForgeDirection side) {
|
|
||||||
if(!this.worldObj.isRemote) {
|
|
||||||
if(ElectricityNetworkHelper.canConnect(tileEntity, side.getOpposite(), this)) {
|
|
||||||
this.connectedBlocks[side.ordinal()] = tileEntity;
|
|
||||||
this.visuallyConnected[side.ordinal()] = true;
|
|
||||||
if(tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider) {
|
|
||||||
this.getNetwork().mergeConnection(((INetworkProvider)tileEntity).getNetwork());
|
|
||||||
} else if (!(tileEntity instanceof ISelfDriven)) {
|
|
||||||
CompatHandler.registerTile(tileEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.connectedBlocks[side.ordinal()] != null) {
|
|
||||||
this.getNetwork().stopProducing(this.connectedBlocks[side.ordinal()]);
|
|
||||||
this.getNetwork().stopRequesting(this.connectedBlocks[side.ordinal()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connectedBlocks[side.ordinal()] = null;
|
|
||||||
this.visuallyConnected[side.ordinal()] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
|
||||||
if(this.worldObj.isRemote) {
|
|
||||||
NBTTagCompound nbt = pkt.func_148857_g();
|
|
||||||
this.visuallyConnected[0] = nbt.getBoolean("bottom");
|
|
||||||
this.visuallyConnected[1] = nbt.getBoolean("top");
|
|
||||||
this.visuallyConnected[2] = nbt.getBoolean("back");
|
|
||||||
this.visuallyConnected[3] = nbt.getBoolean("front");
|
|
||||||
this.visuallyConnected[4] = nbt.getBoolean("left");
|
|
||||||
this.visuallyConnected[5] = nbt.getBoolean("right");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initiate() {
|
|
||||||
this.updateAdjacentConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidate() {
|
|
||||||
if(!this.worldObj.isRemote) {
|
|
||||||
this.getNetwork().splitNetwork(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
if(!this.worldObj.isRemote && super.ticks % 300L == 0L) {
|
|
||||||
this.updateAdjacentConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAdjacentConnections() {
|
|
||||||
if(this.worldObj != null && !this.worldObj.isRemote) {
|
|
||||||
boolean[] previousConnections = (boolean[])this.visuallyConnected.clone();
|
|
||||||
|
|
||||||
for(byte i = 0; i < 6; ++i) {
|
|
||||||
this.updateConnection(VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Arrays.equals(previousConnections, this.visuallyConnected)) {
|
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Packet getDescriptionPacket() {
|
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
|
||||||
nbt.setBoolean("bottom", this.visuallyConnected[0]);
|
|
||||||
nbt.setBoolean("top", this.visuallyConnected[1]);
|
|
||||||
nbt.setBoolean("back", this.visuallyConnected[2]);
|
|
||||||
nbt.setBoolean("front", this.visuallyConnected[3]);
|
|
||||||
nbt.setBoolean("left", this.visuallyConnected[4]);
|
|
||||||
nbt.setBoolean("right", this.visuallyConnected[5]);
|
|
||||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata(), nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IElectricityNetwork getNetwork() {
|
|
||||||
if(this.network == null) {
|
|
||||||
this.setNetwork(new ElectricityNetwork(new IConductor[]{this}));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.network;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNetwork(IElectricityNetwork network) {
|
|
||||||
this.network = network;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEntity[] getAdjacentConnections() {
|
|
||||||
return this.connectedBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canConnect(ForgeDirection direction) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public AxisAlignedBB getRenderBoundingBox() {
|
|
||||||
return AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import universalelectricity.prefab.implement.IDisableable;
|
|
||||||
|
|
||||||
public abstract class TileEntityDisableable extends TileEntityAdvanced implements IDisableable {
|
|
||||||
|
|
||||||
protected int disabledTicks = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
if(this.disabledTicks > 0) {
|
|
||||||
--this.disabledTicks;
|
|
||||||
this.whileDisable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void whileDisable() {}
|
|
||||||
|
|
||||||
public void onDisable(int duration) {
|
|
||||||
this.disabledTicks = duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDisabled() {
|
|
||||||
return this.disabledTicks > 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
import universalelectricity.core.block.IVoltage;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
|
||||||
import universalelectricity.prefab.tile.TileEntityDisableable;
|
|
||||||
|
|
||||||
public abstract class TileEntityElectrical extends TileEntityDisableable implements IConnector, IVoltage {
|
|
||||||
|
|
||||||
public double getVoltage() {
|
|
||||||
return 120.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidate() {
|
|
||||||
ElectricityNetworkHelper.invalidate(this);
|
|
||||||
super.invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
|
|
||||||
public abstract class TileEntityElectricityRunnable extends TileEntityElectrical {
|
|
||||||
|
|
||||||
public double prevWatts;
|
|
||||||
public double wattsReceived = 0.0D;
|
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public void initiate() {
|
|
||||||
super.initiate();
|
|
||||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidate() {
|
|
||||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
|
||||||
super.invalidate();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
this.prevWatts = this.wattsReceived;
|
|
||||||
if(!this.worldObj.isRemote) {
|
|
||||||
if(!this.isDisabled()) {
|
|
||||||
ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest());
|
|
||||||
this.onReceive(electricityPack);
|
|
||||||
} else {
|
|
||||||
ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EnumSet<ForgeDirection> getConsumingSides() {
|
|
||||||
return ElectricityNetworkHelper.getDirections(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getRequest() {
|
|
||||||
return new ElectricityPack();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onReceive(ElectricityPack electricityPack) {
|
|
||||||
if(UniversalElectricity.isVoltageSensitive && electricityPack.voltage > this.getVoltage()) {
|
|
||||||
this.worldObj.createExplosion((Entity)null, (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, 1.5F, true);
|
|
||||||
} else {
|
|
||||||
this.wattsReceived = Math.min(this.wattsReceived + electricityPack.getWatts(), this.getWattBuffer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getWattBuffer() {
|
|
||||||
return this.getRequest().getWatts() * 2.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
//IC2 START
|
|
||||||
|
|
||||||
/* @Override
|
|
||||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
|
|
||||||
return getConsumingSides().contains(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getDemandedEnergy() {
|
|
||||||
return Math.ceil(this.getRequest().getWatts() * UniversalElectricity.TO_IC2_RATIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSinkTier() {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double injectEnergy(ForgeDirection direction, double i, double voltage) {
|
|
||||||
double givenElectricity = (double)i * UniversalElectricity.IC2_RATIO;
|
|
||||||
double rejects = 0.0;
|
|
||||||
if (givenElectricity > this.getWattBuffer()) {
|
|
||||||
rejects = givenElectricity - this.getRequest().getWatts();
|
|
||||||
}
|
|
||||||
this.onReceive(new ElectricityPack(givenElectricity / this.getVoltage(), this.getVoltage()));
|
|
||||||
return (rejects * UniversalElectricity.TO_IC2_RATIO);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
|
||||||
import universalelectricity.core.block.IElectricityStorage;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
|
||||||
|
|
||||||
public abstract class TileEntityElectricityStorage extends TileEntityElectrical implements IElectricityStorage, IStrictEnergyAcceptor {
|
|
||||||
|
|
||||||
private double joules = 0.0D;
|
|
||||||
public double prevJoules = 0.0D;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
this.prevJoules = this.joules;
|
|
||||||
if(!this.worldObj.isRemote) {
|
|
||||||
if(!this.isDisabled()) {
|
|
||||||
ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest());
|
|
||||||
this.onReceive(electricityPack);
|
|
||||||
} else {
|
|
||||||
ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EnumSet<ForgeDirection> getConsumingSides() {
|
|
||||||
return ElectricityNetworkHelper.getDirections(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElectricityPack getRequest() {
|
|
||||||
return new ElectricityPack((this.getMaxJoules() - this.getJoules()) / this.getVoltage(), this.getVoltage());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onReceive(ElectricityPack electricityPack) {
|
|
||||||
if(UniversalElectricity.isVoltageSensitive && electricityPack.voltage > this.getVoltage()) {
|
|
||||||
this.worldObj.createExplosion((Entity)null, (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, 1.5F, true);
|
|
||||||
} else {
|
|
||||||
this.setJoules(this.getJoules() + electricityPack.getWatts());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
|
|
||||||
super.readFromNBT(par1NBTTagCompound);
|
|
||||||
this.joules = par1NBTTagCompound.getDouble("joules");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
|
|
||||||
super.writeToNBT(par1NBTTagCompound);
|
|
||||||
par1NBTTagCompound.setDouble("joules", this.joules);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getJoules() {
|
|
||||||
return this.joules;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setJoules(double joules) {
|
|
||||||
this.joules = Math.max(Math.min(joules, this.getMaxJoules()), 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double transferEnergyToAcceptor(ForgeDirection side, double amount) {
|
|
||||||
if (!canReceiveEnergy(side)) return 0;
|
|
||||||
double toUse = Math.min(getMaxEnergy()-getEnergy(), amount);
|
|
||||||
setEnergy(toUse + getEnergy());
|
|
||||||
return toUse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canReceiveEnergy(ForgeDirection side) {
|
|
||||||
return getConsumingSides().contains(side);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,27 +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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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:false;
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue