Compare commits
4 commits
f5f664f02e
...
1c50f43014
Author | SHA1 | Date | |
---|---|---|---|
|
1c50f43014 | ||
|
1a532aa4dd | ||
|
95d0145266 | ||
|
7913f44840 |
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'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,9 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiBatteryBox extends GuiContainer {
|
public class GuiBatteryBox extends GuiContainer {
|
||||||
|
@ -27,8 +28,8 @@ public class GuiBatteryBox extends GuiContainer {
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||||
this.fontRendererObj.drawString(this.tileEntity.getInventoryName(), 65, 6, 4210752);
|
this.fontRendererObj.drawString(this.tileEntity.getInventoryName(), 65, 6, 4210752);
|
||||||
String displayJoules = ElectricityDisplay.getDisplayShort(this.tileEntity.getJoules(), ElectricityDisplay.ElectricUnit.JOULES);
|
String displayJoules = UnitDisplay.getDisplayShort(this.tileEntity.getJoules(), UnitDisplay.Unit.JOULES);
|
||||||
String displayMaxJoules = ElectricityDisplay.getDisplay(this.tileEntity.getMaxJoules(), ElectricityDisplay.ElectricUnit.JOULES);
|
String displayMaxJoules = UnitDisplay.getDisplay(this.tileEntity.getMaxJoules(), UnitDisplay.Unit.JOULES);
|
||||||
if(this.tileEntity.isDisabled()) {
|
if(this.tileEntity.isDisabled()) {
|
||||||
displayMaxJoules = "Disabled";
|
displayMaxJoules = "Disabled";
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiCoalGenerator extends GuiContainer {
|
public class GuiCoalGenerator extends GuiContainer {
|
||||||
|
@ -36,7 +37,7 @@ public class GuiCoalGenerator extends GuiContainer {
|
||||||
} else if(this.tileEntity.generateWatts < 100.0D) {
|
} else if(this.tileEntity.generateWatts < 100.0D) {
|
||||||
displayText = "Hull Heat: " + (int)(this.tileEntity.generateWatts / 100.0D * 100.0D) + "%";
|
displayText = "Hull Heat: " + (int)(this.tileEntity.generateWatts / 100.0D * 100.0D) + "%";
|
||||||
} else {
|
} else {
|
||||||
displayText = ElectricityDisplay.getDisplay(this.tileEntity.generateWatts, ElectricityDisplay.ElectricUnit.WATT);
|
displayText = UnitDisplay.getDisplay(this.tileEntity.generateWatts, UnitDisplay.Unit.WATT);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fontRendererObj.drawString(displayText, (int)(100.0D - (double)displayText.length() * 1.25D), 45, 4210752);
|
this.fontRendererObj.drawString(displayText, (int)(100.0D - (double)displayText.length() * 1.25D), 45, 4210752);
|
||||||
|
|
|
@ -8,8 +8,9 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiElectricFurnace extends GuiContainer {
|
public class GuiElectricFurnace extends GuiContainer {
|
||||||
|
@ -39,8 +40,8 @@ public class GuiElectricFurnace extends GuiContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fontRendererObj.drawString("Status: " + displayText, 82, 45, 4210752);
|
this.fontRendererObj.drawString("Status: " + displayText, 82, 45, 4210752);
|
||||||
this.fontRendererObj.drawString(ElectricityDisplay.getDisplay(10000.0D, ElectricityDisplay.ElectricUnit.WATT), 82, 56, 4210752);
|
this.fontRendererObj.drawString(UnitDisplay.getDisplay(10000.0D, UnitDisplay.Unit.WATT), 82, 56, 4210752);
|
||||||
this.fontRendererObj.drawString(ElectricityDisplay.getDisplay(this.tileEntity.getVoltage(), ElectricityDisplay.ElectricUnit.VOLTAGE), 82, 68, 4210752);
|
this.fontRendererObj.drawString(UnitDisplay.getDisplay(this.tileEntity.getVoltage(), UnitDisplay.Unit.VOLTAGE), 82, 68, 4210752);
|
||||||
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
|
|
||||||
public class ItemBlockCopperWire extends ItemBlock {
|
public class ItemBlockCopperWire extends ItemBlock {
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class ItemBlockCopperWire extends ItemBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||||
par3List.add("Resistance: " + ElectricityDisplay.getDisplay(TileEntityCopperWire.RESISTANCE, ElectricityDisplay.ElectricUnit.RESISTANCE));
|
par3List.add("Resistance: " + UnitDisplay.getDisplay(TileEntityCopperWire.RESISTANCE, UnitDisplay.Unit.RESISTANCE));
|
||||||
par3List.add("Max Amps: " + ElectricityDisplay.getDisplay(TileEntityCopperWire.MAX_AMPS, ElectricityDisplay.ElectricUnit.AMPERE));
|
par3List.add("Max Amps: " + UnitDisplay.getDisplay(TileEntityCopperWire.MAX_AMPS, UnitDisplay.Unit.AMPERE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,53 +0,0 @@
|
||||||
package universalelectricity.compat;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
|
||||||
import cpw.mods.fml.common.Loader;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.compat.ic2.EventHandler;
|
|
||||||
import universalelectricity.compat.ic2.IC2CompatModule;
|
|
||||||
import universalelectricity.compat.ic2.TickHandler;
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
|
|
||||||
public class CompatHandler {
|
|
||||||
|
|
||||||
private static List<CompatiblityModule> modules;
|
|
||||||
|
|
||||||
public static void initCompatHandlers() {
|
|
||||||
modules = new ArrayList<>();
|
|
||||||
if (Loader.isModLoaded("IC2")) {
|
|
||||||
modules.add(new IC2CompatModule());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
|
||||||
FMLCommonHandler.instance().bus().register(new TickHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerModule(CompatiblityModule module) {
|
|
||||||
if (modules != null)
|
|
||||||
modules.add(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side) {
|
|
||||||
if (tileEntity == null) return false;
|
|
||||||
if (tileEntity instanceof IConnector) return ((IConnector)tileEntity).canConnect(side);
|
|
||||||
for (CompatiblityModule module : modules) {
|
|
||||||
if (module.canConnect(tileEntity, side)) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IElectricityTileHandler getHandler(TileEntity tileEntity) {
|
|
||||||
if (tileEntity instanceof IConnector || tileEntity == null) return null;
|
|
||||||
for (CompatiblityModule module : modules) {
|
|
||||||
if (module.isHandledBy(tileEntity)) {
|
|
||||||
return module.getHandler(tileEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package universalelectricity.compat;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public abstract class CompatiblityModule {
|
|
||||||
|
|
||||||
public abstract boolean isHandledBy(TileEntity tile);
|
|
||||||
|
|
||||||
public abstract boolean canConnect(TileEntity tile, ForgeDirection side);
|
|
||||||
|
|
||||||
public abstract IElectricityTileHandler getHandler(TileEntity tileEntity);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package universalelectricity.compat;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
|
|
||||||
public interface IElectricityTileHandler {
|
|
||||||
|
|
||||||
boolean canInsert();
|
|
||||||
|
|
||||||
boolean canExtract();
|
|
||||||
|
|
||||||
boolean canInsertOn(ForgeDirection side);
|
|
||||||
|
|
||||||
boolean canExtractOn(ForgeDirection side);
|
|
||||||
|
|
||||||
void insert(ElectricityPack pack, ForgeDirection side);
|
|
||||||
|
|
||||||
void extract(ElectricityPack pack, ForgeDirection side);
|
|
||||||
|
|
||||||
ElectricityPack getDemandedJoules();
|
|
||||||
|
|
||||||
ElectricityPack getProvidedJoules();
|
|
||||||
|
|
||||||
TileEntity getTile();
|
|
||||||
|
|
||||||
double getVoltage();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
|
||||||
import ic2.api.energy.tile.IEnergySource;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.compat.IElectricityTileHandler;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
|
|
||||||
public class ElectricityTileWrapper implements IElectricityTileHandler {
|
|
||||||
|
|
||||||
TileEntity baseTile;
|
|
||||||
|
|
||||||
public ElectricityTileWrapper(TileEntity baseTile) {
|
|
||||||
this.baseTile = baseTile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInsert() {
|
|
||||||
return baseTile instanceof IEnergySink;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExtract() {
|
|
||||||
return baseTile instanceof IEnergySource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInsertOn(ForgeDirection side) {
|
|
||||||
return baseTile instanceof IEnergySink && ((IEnergySink) baseTile).acceptsEnergyFrom(null, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExtractOn(ForgeDirection side) {
|
|
||||||
return baseTile instanceof IEnergySource && ((IEnergySource) baseTile).emitsEnergyTo(null, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insert(ElectricityPack pack, ForgeDirection side) {
|
|
||||||
if (baseTile instanceof IEnergySink) {
|
|
||||||
IEnergySink sink = (IEnergySink) baseTile;
|
|
||||||
sink.injectEnergy(side, IC2CompatHelper.joulesToEU(pack.getWatts()), IC2CompatHelper.voltToTier(pack.voltage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void extract(ElectricityPack pack, ForgeDirection side) {
|
|
||||||
if (baseTile instanceof IEnergySource) {
|
|
||||||
IEnergySource source = (IEnergySource) baseTile;
|
|
||||||
source.drawEnergy(IC2CompatHelper.joulesToEU(pack.getWatts()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ElectricityPack getDemandedJoules() {
|
|
||||||
if (baseTile instanceof IEnergySink) {
|
|
||||||
IEnergySink sink = (IEnergySink) baseTile;
|
|
||||||
double voltage = IC2CompatHelper.tierToVolt(sink.getSinkTier());
|
|
||||||
return new ElectricityPack(IC2CompatHelper.EUToJoules(sink.getDemandedEnergy()) / voltage, voltage);
|
|
||||||
}
|
|
||||||
return new ElectricityPack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ElectricityPack getProvidedJoules() {
|
|
||||||
if (baseTile instanceof IEnergySource) {
|
|
||||||
IEnergySource source = (IEnergySource) baseTile;
|
|
||||||
double voltage = IC2CompatHelper.tierToVolt(source.getSourceTier());
|
|
||||||
return new ElectricityPack(IC2CompatHelper.EUToJoules(source.getOfferedEnergy()) / voltage, voltage);
|
|
||||||
}
|
|
||||||
return new ElectricityPack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity getTile() {
|
|
||||||
return baseTile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getVoltage() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.core.Pair;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.prefab.tile.ElectricTileDriver;
|
|
||||||
|
|
||||||
public class EnergyNetCache {
|
|
||||||
|
|
||||||
private static Map<Pair<World, Vector3>, ElectricTileDriver> tiles = new HashMap<>();
|
|
||||||
|
|
||||||
public static Pair<World, Vector3> toKey(TileEntity tile) {
|
|
||||||
return new Pair<World, Vector3>(tile.getWorldObj(), new Vector3(tile));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load(TileEntity tile) {
|
|
||||||
tiles.put(toKey(tile), new ElectricTileDriver(new ElectricityTileWrapper(tile)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unload(TileEntity tile) {
|
|
||||||
ElectricTileDriver handler = tiles.get(toKey(tile));
|
|
||||||
if (handler != null) handler.invalidate();
|
|
||||||
tiles.remove(toKey(tile));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canConnect(Pair<World, Vector3> pos, ForgeDirection side) {
|
|
||||||
ElectricTileDriver handler = tiles.get(pos);
|
|
||||||
return handler == null ? false : handler.canConnect(side);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tickAll() {
|
|
||||||
for (ElectricTileDriver handler : tiles.values()) {
|
|
||||||
handler.tick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean contains(TileEntity tile) {
|
|
||||||
return tiles.containsKey(toKey(tile));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent;
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
|
||||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
|
||||||
import ic2.api.energy.tile.IEnergySource;
|
|
||||||
import mekanism.api.energy.ICableOutputter;
|
|
||||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
|
|
||||||
public class EventHandler {
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onLoadTile(EnergyTileLoadEvent event) {
|
|
||||||
TileEntity te = (TileEntity) event.energyTile;
|
|
||||||
if (te instanceof IConnector || te instanceof IStrictEnergyAcceptor || te instanceof ICableOutputter) return;
|
|
||||||
if (te instanceof IEnergySink || te instanceof IEnergySource) EnergyNetCache.load(te);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onUnloadTile(EnergyTileUnloadEvent event) {
|
|
||||||
TileEntity te = (TileEntity) event.energyTile;
|
|
||||||
EnergyNetCache.unload(te);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
import universalelectricity.core.UniversalElectricity;
|
|
||||||
|
|
||||||
public class IC2CompatHelper {
|
|
||||||
|
|
||||||
public static double EUToJoules(double eu) {
|
|
||||||
return eu * UniversalElectricity.UE_IC2_RATIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double joulesToEU(double joules) {
|
|
||||||
return joules / UniversalElectricity.UE_IC2_RATIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,25 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import universalelectricity.compat.CompatiblityModule;
|
|
||||||
import universalelectricity.compat.IElectricityTileHandler;
|
|
||||||
|
|
||||||
public class IC2CompatModule extends CompatiblityModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isHandledBy(TileEntity tile) {
|
|
||||||
return EnergyNetCache.contains(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canConnect(TileEntity tile, ForgeDirection side) {
|
|
||||||
return EnergyNetCache.canConnect(EnergyNetCache.toKey(tile), side);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IElectricityTileHandler getHandler(TileEntity tileEntity) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package universalelectricity.compat.ic2;
|
|
||||||
|
|
||||||
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 TickHandler {
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onTick(ServerTickEvent event) {
|
|
||||||
if (event.phase == Phase.END) {
|
|
||||||
EnergyNetCache.tickAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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,30 +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;
|
|
||||||
|
|
||||||
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 = 10.0D;
|
|
||||||
public static double UE_RF_RATIO = 2.5D;
|
|
||||||
public static boolean isVoltageSensitive = false;
|
|
||||||
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,11 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import universalelectricity.core.block.IConnectionProvider;
|
|
||||||
import universalelectricity.core.block.INetworkProvider;
|
|
||||||
|
|
||||||
public interface IConductor extends INetworkProvider, IConnectionProvider {
|
|
||||||
|
|
||||||
double getResistance();
|
|
||||||
|
|
||||||
double getCurrentCapcity();
|
|
||||||
}
|
|
|
@ -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,8 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IConnector {
|
|
||||||
|
|
||||||
boolean canConnect(ForgeDirection var1);
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import mekanism.api.energy.IStrictEnergyStorage;
|
|
||||||
|
|
||||||
public interface IElectricityStorage extends IStrictEnergyStorage {
|
|
||||||
|
|
||||||
double getJoules();
|
|
||||||
|
|
||||||
void setJoules(double var1);
|
|
||||||
|
|
||||||
double getMaxJoules();
|
|
||||||
|
|
||||||
default double getEnergy() {
|
|
||||||
return getJoules();
|
|
||||||
}
|
|
||||||
|
|
||||||
default void setEnergy(double energy) {
|
|
||||||
setJoules(energy);
|
|
||||||
}
|
|
||||||
|
|
||||||
default double getMaxEnergy() {
|
|
||||||
return getMaxJoules();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
|
||||||
|
|
||||||
public interface INetworkProvider {
|
|
||||||
|
|
||||||
IElectricityNetwork getNetwork();
|
|
||||||
|
|
||||||
void setNetwork(IElectricityNetwork var1);
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package universalelectricity.core.block;
|
|
||||||
|
|
||||||
|
|
||||||
public interface IVoltage {
|
|
||||||
|
|
||||||
double getVoltage();
|
|
||||||
}
|
|
|
@ -1,92 +0,0 @@
|
||||||
package universalelectricity.core.electricity;
|
|
||||||
|
|
||||||
|
|
||||||
public class ElectricityDisplay {
|
|
||||||
|
|
||||||
public static String getDisplay(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces, boolean isShort) {
|
|
||||||
String unitName = unit.name;
|
|
||||||
if(isShort) {
|
|
||||||
unitName = unit.symbol;
|
|
||||||
} else if(value > 1.0D) {
|
|
||||||
unitName = unit.getPlural();
|
|
||||||
}
|
|
||||||
|
|
||||||
return value == 0.0D?value + " " + unitName:(value <= ElectricityDisplay.MeasurementUnit.MILLI.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MICRO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MICRO.getName(isShort) + unitName:(value < 1.0D?roundDecimals(ElectricityDisplay.MeasurementUnit.MILLI.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MILLI.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.MEGA.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MEGA.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MEGA.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.KILO.value?roundDecimals(ElectricityDisplay.MeasurementUnit.KILO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.KILO.getName(isShort) + unitName:roundDecimals(value, decimalPlaces) + " " + unitName))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplay(double value, ElectricityDisplay.ElectricUnit unit) {
|
|
||||||
return getDisplay(value, unit, 2, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplayShort(double value, ElectricityDisplay.ElectricUnit unit) {
|
|
||||||
return getDisplay(value, unit, 2, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplayShort(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces) {
|
|
||||||
return getDisplay(value, unit, decimalPlaces, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplaySimple(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces) {
|
|
||||||
return value > 1.0D?(decimalPlaces < 1?(int)value + " " + unit.getPlural():roundDecimals(value, decimalPlaces) + " " + unit.getPlural()):(decimalPlaces < 1?(int)value + " " + unit.name:roundDecimals(value, decimalPlaces) + " " + unit.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double roundDecimals(double d, int decimalPlaces) {
|
|
||||||
int j = (int)(d * Math.pow(10.0D, (double)decimalPlaces));
|
|
||||||
return (double)j / Math.pow(10.0D, (double)decimalPlaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double roundDecimals(double d) {
|
|
||||||
return roundDecimals(d, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum ElectricUnit {
|
|
||||||
|
|
||||||
AMPERE("Amp", "I"),
|
|
||||||
AMP_HOUR("Amp Hour", "Ah"),
|
|
||||||
VOLTAGE("Volt", "V"),
|
|
||||||
WATT("Watt", "W"),
|
|
||||||
WATT_HOUR("Watt Hour", "Wh"),
|
|
||||||
RESISTANCE("Ohm", "R"),
|
|
||||||
CONDUCTANCE("Siemen", "S"),
|
|
||||||
JOULES("Joule", "J");
|
|
||||||
public String name;
|
|
||||||
public String symbol;
|
|
||||||
|
|
||||||
private ElectricUnit(String name, String symbol) {
|
|
||||||
this.name = name;
|
|
||||||
this.symbol = symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlural() {
|
|
||||||
return this.name + "s";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum MeasurementUnit {
|
|
||||||
|
|
||||||
MICRO("Micro", "mi", 1.0E-6D),
|
|
||||||
MILLI("Milli", "m", 0.001D),
|
|
||||||
KILO("Kilo", "k", 1000.0D),
|
|
||||||
MEGA("Mega", "M", 1000000.0D);
|
|
||||||
public String name;
|
|
||||||
public String symbol;
|
|
||||||
public double value;
|
|
||||||
|
|
||||||
|
|
||||||
private MeasurementUnit(String name, String symbol, double value) {
|
|
||||||
this.name = name;
|
|
||||||
this.symbol = symbol;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName(boolean isSymbol) {
|
|
||||||
return isSymbol?this.symbol:this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double process(double value) {
|
|
||||||
return value / this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,339 +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 boolean isInactive() {
|
|
||||||
return conductors.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,139 +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.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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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,62 +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.core.block.IConductor;
|
|
||||||
import universalelectricity.core.block.IConnectionProvider;
|
|
||||||
|
|
||||||
public interface IElectricityNetwork {
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
boolean isInactive();
|
|
||||||
|
|
||||||
void tick();
|
|
||||||
|
|
||||||
}
|
|
|
@ -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,8 +0,0 @@
|
||||||
package universalelectricity.core.item;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public interface IItemVoltage {
|
|
||||||
|
|
||||||
double getVoltage(ItemStack var1);
|
|
||||||
}
|
|
|
@ -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.core.electricity.ElectricityDisplay;
|
|
||||||
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 + ElectricityDisplay.getDisplay(joules, ElectricityDisplay.ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplay(this.getMaxJoules(itemStack), ElectricityDisplay.ElectricUnit.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,43 +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.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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,106 +0,0 @@
|
||||||
package universalelectricity.prefab.tile;
|
|
||||||
|
|
||||||
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 scala.languageFeature.reflectiveCalls;
|
|
||||||
import universalelectricity.compat.IElectricityTileHandler;
|
|
||||||
import universalelectricity.core.block.IConnector;
|
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
|
||||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
|
|
||||||
public class ElectricTileDriver implements IConnector {
|
|
||||||
|
|
||||||
IElectricityTileHandler handler;
|
|
||||||
|
|
||||||
public ElectricTileDriver(IElectricityTileHandler handler) {
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canConnect(ForgeDirection side) {
|
|
||||||
return handler.canInsertOn(side) || handler.canExtractOn(side);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void invalidate() {
|
|
||||||
ElectricityNetworkHelper.invalidate(handler.getTile());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
Map<ForgeDirection, IElectricityNetwork> networks = getNetworks();
|
|
||||||
Set<ForgeDirection> inputSides = new HashSet<>();
|
|
||||||
if (handler.canInsert()) {
|
|
||||||
inputSides = consume(networks);
|
|
||||||
}
|
|
||||||
if (handler.canExtract()) {
|
|
||||||
produce(networks, inputSides);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<ForgeDirection> consume(Map<ForgeDirection, IElectricityNetwork> networks) {
|
|
||||||
Set<ForgeDirection> inputSides = new HashSet<>();
|
|
||||||
|
|
||||||
if (networks.size() > 0) {
|
|
||||||
ElectricityPack demand = handler.getDemandedJoules();
|
|
||||||
double voltage = demand.voltage;
|
|
||||||
double wattsPerSide = demand.getWatts() / networks.size();
|
|
||||||
for (ForgeDirection side : networks.keySet()) {
|
|
||||||
IElectricityNetwork net = networks.get(side);
|
|
||||||
if (handler.canInsertOn(side) && wattsPerSide > 0 && demand.getWatts() > 0) {
|
|
||||||
inputSides.add(side);
|
|
||||||
net.startRequesting(handler.getTile(), wattsPerSide / voltage, voltage);
|
|
||||||
ElectricityPack receivedPack = net.consumeElectricity(handler.getTile());
|
|
||||||
handler.insert(receivedPack, side);
|
|
||||||
} else {
|
|
||||||
net.stopRequesting(handler.getTile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return inputSides;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void produce(Map<ForgeDirection, IElectricityNetwork> networks, Set<ForgeDirection> inputSides) {
|
|
||||||
if ((networks.size() - inputSides.size()) > 0) {
|
|
||||||
ElectricityPack provided = handler.getProvidedJoules();
|
|
||||||
double voltage = provided.voltage;
|
|
||||||
double wattsPerSide = provided.getWatts() / (networks.size() - inputSides.size());
|
|
||||||
for (ForgeDirection side : networks.keySet()) {
|
|
||||||
IElectricityNetwork net = networks.get(side);
|
|
||||||
if (!inputSides.contains(side) && handler.canExtractOn(side) && wattsPerSide > 0 && provided.getWatts() > 0) {
|
|
||||||
double amperes = Math.min(wattsPerSide / voltage, net.getRequest(new TileEntity[]{handler.getTile()}).amperes);
|
|
||||||
net.startProducing(handler.getTile(), amperes, voltage);
|
|
||||||
handler.extract(new ElectricityPack(amperes, voltage), side);
|
|
||||||
} else {
|
|
||||||
net.stopProducing(handler.getTile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<ForgeDirection, IElectricityNetwork> getNetworks() {
|
|
||||||
Map<ForgeDirection, IElectricityNetwork> networks = new HashMap<>();
|
|
||||||
|
|
||||||
for(ForgeDirection dir : ForgeDirection.values()) {
|
|
||||||
if (canConnect(dir)) {
|
|
||||||
Vector3 position = new Vector3(handler.getTile());
|
|
||||||
position.modifyPositionFromSide(dir);
|
|
||||||
TileEntity outputConductor = position.getTileEntity(handler.getTile().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,140 +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.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(CompatHandler.canConnect(tileEntity, side.getOpposite())) {
|
|
||||||
this.connectedBlocks[side.ordinal()] = tileEntity;
|
|
||||||
this.visuallyConnected[side.ordinal()] = true;
|
|
||||||
if(tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider) {
|
|
||||||
this.getNetwork().mergeConnection(((INetworkProvider)tileEntity).getNetwork());
|
|
||||||
}
|
|
||||||
|
|
||||||
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,49 +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 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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
package universalelectricity.prefab.vector;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
|
||||||
import universalelectricity.prefab.vector.Region2;
|
|
||||||
|
|
||||||
public class Region3 {
|
|
||||||
|
|
||||||
public Vector3 min;
|
|
||||||
public Vector3 max;
|
|
||||||
|
|
||||||
|
|
||||||
public Region3() {
|
|
||||||
this(new Vector3(), new Vector3());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region3(Vector3 min, Vector3 max) {
|
|
||||||
this.min = min;
|
|
||||||
this.max = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region3(AxisAlignedBB aabb) {
|
|
||||||
this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ);
|
|
||||||
this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AxisAlignedBB toAABB() {
|
|
||||||
return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region2 toRegion2() {
|
|
||||||
return new Region2(this.min.toVector2(), this.max.toVector2());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIn(Vector3 point) {
|
|
||||||
return point.x > this.min.x && point.x < this.max.x && point.y > this.min.y && point.y < this.max.y && point.z > this.min.z && point.z < this.max.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIn(Region3 region) {
|
|
||||||
return region.max.x > this.min.x && region.min.x < this.max.x?(region.max.y > this.min.y && region.min.y < this.max.y?region.max.z > this.min.z && region.min.z < this.max.z:false):false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void expand(Vector3 difference) {
|
|
||||||
this.min.subtract(difference);
|
|
||||||
this.max.add(difference);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Vector3> getVectors() {
|
|
||||||
ArrayList vectors = new ArrayList();
|
|
||||||
|
|
||||||
for(int x = this.min.intX(); x < this.max.intX(); ++x) {
|
|
||||||
for(int y = this.min.intY(); x < this.max.intY(); ++y) {
|
|
||||||
for(int z = this.min.intZ(); x < this.max.intZ(); ++z) {
|
|
||||||
vectors.add(new Vector3((double)x, (double)y, (double)z));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return vectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Vector3> getVectors(Vector3 center, int radius) {
|
|
||||||
ArrayList vectors = new ArrayList();
|
|
||||||
|
|
||||||
for(int x = this.min.intX(); x < this.max.intX(); ++x) {
|
|
||||||
for(int y = this.min.intY(); x < this.max.intY(); ++y) {
|
|
||||||
for(int z = this.min.intZ(); x < this.max.intZ(); ++z) {
|
|
||||||
Vector3 vector3 = new Vector3((double)x, (double)y, (double)z);
|
|
||||||
if(center.distanceTo(vector3) <= (double)radius) {
|
|
||||||
vectors.add(vector3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return vectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Entity> getEntities(World world, Class<? extends Entity> entityClass) {
|
|
||||||
return world.getEntitiesWithinAABB(entityClass, this.toAABB());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Entity> getEntitiesExlude(World world, Entity entity) {
|
|
||||||
return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Entity> getEntities(World world) {
|
|
||||||
return this.getEntities(world, Entity.class);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue