From b4cc4cc925b99511eecca0f67df9ec3e13f42af6 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 6 Aug 2013 18:47:34 -0400 Subject: [PATCH] Switched to UE Vector3 and IItemElectric --- Universal-Electricity | 2 +- src/org/modstats/IModstatsReporter.java | 5 +- src/org/modstats/ModVersionData.java | 157 +++--- src/org/modstats/ModsUpdateEvent.java | 48 +- src/org/modstats/ModstatInfo.java | 37 +- src/org/modstats/Modstats.java | 110 +++-- src/org/modstats/reporter/v1/Config.java | 66 +-- src/org/modstats/reporter/v1/DataSender.java | 450 +++++++++--------- src/org/modstats/reporter/v1/Reporter.java | 183 +++---- src/resonantinduction/ClientProxy.java | 2 +- src/resonantinduction/CommonProxy.java | 2 +- src/resonantinduction/ResonantInduction.java | 11 +- src/resonantinduction/api/IBattery.java | 27 -- src/resonantinduction/base/Vector3.java | 365 -------------- .../battery/BatteryManager.java | 4 +- .../battery/BatteryUpdateProtocol.java | 4 +- .../battery/BlockBattery.java | 4 +- .../battery/ContainerBattery.java | 4 +- .../battery/ItemCapacitor.java | 67 +-- .../battery/SynchronizedBatteryData.java | 6 +- .../battery/TileEntityBattery.java | 40 +- .../contractor/BlockEMContractor.java | 2 +- .../contractor/PathfinderEMContractor.java | 3 +- .../contractor/ThreadPathfinding.java | 2 +- .../contractor/TileEntityEMContractor.java | 2 +- .../entangler/ItemCoordLink.java | 2 +- .../entangler/ItemLinker.java | 2 +- .../entangler/ItemQuantumEntangler.java | 2 +- src/resonantinduction/fx/FXElectricBolt.java | 6 +- .../render/RenderBattery.java | 18 +- src/resonantinduction/tesla/BlockTesla.java | 2 +- .../tesla/TileEntityTesla.java | 2 +- 32 files changed, 597 insertions(+), 1040 deletions(-) delete mode 100644 src/resonantinduction/api/IBattery.java delete mode 100644 src/resonantinduction/base/Vector3.java diff --git a/Universal-Electricity b/Universal-Electricity index 21c943dc1..ca595286e 160000 --- a/Universal-Electricity +++ b/Universal-Electricity @@ -1 +1 @@ -Subproject commit 21c943dc1b2bbf864af208790338d68ca7912fea +Subproject commit ca595286ebfe50a12300ba8490266aadce44c86d diff --git a/src/org/modstats/IModstatsReporter.java b/src/org/modstats/IModstatsReporter.java index f275bf737..8fe62722b 100644 --- a/src/org/modstats/IModstatsReporter.java +++ b/src/org/modstats/IModstatsReporter.java @@ -29,7 +29,6 @@ package org.modstats; public interface IModstatsReporter { - public void registerMod(Object mod); - - public void doManualCheck(); + public void registerMod(Object mod); + public void doManualCheck(); } diff --git a/src/org/modstats/ModVersionData.java b/src/org/modstats/ModVersionData.java index 4139a1536..ab3fbcd09 100644 --- a/src/org/modstats/ModVersionData.java +++ b/src/org/modstats/ModVersionData.java @@ -32,86 +32,83 @@ import java.util.Map; public class ModVersionData { - public String prefix; - public String name; - public String version; - public String downloadUrl; - public String changeLogUrl; + public String prefix; + public String name; + public String version; + public String downloadUrl; + public String changeLogUrl; + + public Map extraFields; + + + public ModVersionData() + { + extraFields = new HashMap(); + } + + public ModVersionData(String prefix, String name, String version) + { + this.prefix = prefix; + this.name = name; + this.version = version; + extraFields = new HashMap(); + } - public Map extraFields; - - public ModVersionData() - { - extraFields = new HashMap(); - } - - public ModVersionData(String prefix, String name, String version) - { - this.prefix = prefix; - this.name = name; - this.version = version; - extraFields = new HashMap(); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((changeLogUrl == null) ? 0 : changeLogUrl.hashCode()); - result = prime * result + ((downloadUrl == null) ? 0 : downloadUrl.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); - result = prime * result + ((version == null) ? 0 : version.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ModVersionData other = (ModVersionData) obj; - if (changeLogUrl == null) - { - if (other.changeLogUrl != null) - return false; - } - else if (!changeLogUrl.equals(other.changeLogUrl)) - return false; - if (downloadUrl == null) - { - if (other.downloadUrl != null) - return false; - } - else if (!downloadUrl.equals(other.downloadUrl)) - return false; - if (name == null) - { - if (other.name != null) - return false; - } - else if (!name.equals(other.name)) - return false; - if (prefix == null) - { - if (other.prefix != null) - return false; - } - else if (!prefix.equals(other.prefix)) - return false; - if (version == null) - { - if (other.version != null) - return false; - } - else if (!version.equals(other.version)) - return false; - return true; - } + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((changeLogUrl == null) ? 0 : changeLogUrl.hashCode()); + result = prime * result + ((downloadUrl == null) ? 0 : downloadUrl.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ModVersionData other = (ModVersionData) obj; + if (changeLogUrl == null) + { + if (other.changeLogUrl != null) + return false; + } else if (!changeLogUrl.equals(other.changeLogUrl)) + return false; + if (downloadUrl == null) + { + if (other.downloadUrl != null) + return false; + } else if (!downloadUrl.equals(other.downloadUrl)) + return false; + if (name == null) + { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (prefix == null) + { + if (other.prefix != null) + return false; + } else if (!prefix.equals(other.prefix)) + return false; + if (version == null) + { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + } diff --git a/src/org/modstats/ModsUpdateEvent.java b/src/org/modstats/ModsUpdateEvent.java index 649ef1004..a29eb817c 100644 --- a/src/org/modstats/ModsUpdateEvent.java +++ b/src/org/modstats/ModsUpdateEvent.java @@ -37,28 +37,28 @@ import cpw.mods.fml.common.FMLLog; @Cancelable public class ModsUpdateEvent extends Event { - private List updatedMods; - - public ModsUpdateEvent() - { - updatedMods = new LinkedList(); - } - - public void add(ModVersionData data) - { - if (!updatedMods.contains(data)) - { - updatedMods.add(data); - } - else - { - FMLLog.info("ModsUpdateEvent shouldn't have same mods data", data); - } - } - - public List getUpdatedMods() - { - return updatedMods; - } - + private List updatedMods; + + public ModsUpdateEvent() + { + updatedMods = new LinkedList(); + } + + public void add(ModVersionData data) + { + if(!updatedMods.contains(data)) + { + updatedMods.add(data); + } + else + { + FMLLog.info("ModsUpdateEvent shouldn't have same mods data", data); + } + } + + public List getUpdatedMods() + { + return updatedMods; + } + } diff --git a/src/org/modstats/ModstatInfo.java b/src/org/modstats/ModstatInfo.java index 19da5d86f..1927e52f3 100644 --- a/src/org/modstats/ModstatInfo.java +++ b/src/org/modstats/ModstatInfo.java @@ -34,26 +34,23 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface ModstatInfo +public @interface ModstatInfo { - /** - * Modstats mod prefix. - * - * @return - */ - public String prefix(); + /** + * Modstats mod prefix. + * @return + */ + public String prefix(); + + /** + * Mod name. Use this if your mod doesn't have @Mod annotation + * @return + */ + public String name() default ""; - /** - * Mod name. Use this if your mod doesn't have @Mod annotation - * - * @return - */ - public String name() default ""; - - /** - * Mod version. Use this if your mod doesn't have @Mod annotation - * - * @return - */ - public String version() default ""; + /** + * Mod version. Use this if your mod doesn't have @Mod annotation + * @return + */ + public String version() default ""; } diff --git a/src/org/modstats/Modstats.java b/src/org/modstats/Modstats.java index 8527e853e..c9753e4d8 100644 --- a/src/org/modstats/Modstats.java +++ b/src/org/modstats/Modstats.java @@ -31,61 +31,59 @@ import cpw.mods.fml.common.FMLLog; public class Modstats { - private static final Modstats INSTANCE = new Modstats(); - private static final String CLASS_TEMPLATE = "org.modstats.reporter.v%d.Reporter"; - private IModstatsReporter reporter; - - private Modstats() - { - reporter = locateReporter(); - } - - public IModstatsReporter getReporter() - { - return reporter; - } - - private IModstatsReporter locateReporter() - { - int i = 1; - Class latest = null; - while (i < 100) - { - try - { - Class candidate = Class.forName(String.format(CLASS_TEMPLATE, i)); - if (IModstatsReporter.class.isAssignableFrom(candidate)) - { - latest = candidate; - } - } - catch (Exception e) - { - break; - } - i++; - } - if (latest == null) - { - FMLLog.warning("Modstats reporter class not found."); - } - else - { - try - { - return (IModstatsReporter) latest.newInstance(); - } - catch (Exception e) - { - FMLLog.warning("Modstats reporter class can't be instantiated."); - } - } - return null; - } - - public static Modstats instance() - { - return INSTANCE; - } + private static final Modstats INSTANCE = new Modstats(); + private static final String CLASS_TEMPLATE = "org.modstats.reporter.v%d.Reporter"; + private IModstatsReporter reporter; + private Modstats() + { + reporter = locateReporter(); + } + + public IModstatsReporter getReporter() + { + return reporter; + } + + private IModstatsReporter locateReporter() + { + int i=1; + Class latest = null; + while(i<100) + { + try + { + Class candidate = Class.forName(String.format(CLASS_TEMPLATE, i)); + if(IModstatsReporter.class.isAssignableFrom(candidate)) + { + latest = candidate; + } + } + catch (Exception e) { + break; + } + i++; + } + if(latest == null) + { + FMLLog.warning("Modstats reporter class not found."); + } + else + { + try + { + return (IModstatsReporter)latest.newInstance(); + } catch (Exception e) + { + FMLLog.warning("Modstats reporter class can't be instantiated."); + } + } + return null; + } + + public static Modstats instance() + { + return INSTANCE; + } + } diff --git a/src/org/modstats/reporter/v1/Config.java b/src/org/modstats/reporter/v1/Config.java index 61eff08aa..708e3a93e 100644 --- a/src/org/modstats/reporter/v1/Config.java +++ b/src/org/modstats/reporter/v1/Config.java @@ -36,38 +36,38 @@ import cpw.mods.fml.common.Loader; public class Config { - private static final String CONFIG_NAME = "modstats.cfg"; - - public boolean allowUpdates; - public boolean betaNotifications; - public boolean forCurrentMinecraftVersion; - public boolean logOnly; - - public Config() - { - File configLocation = new File(Loader.instance().getConfigDir(), CONFIG_NAME); - Configuration configuration = new Configuration(configLocation); - configuration.load(); - - Property prop = configuration.get("updates", "AllowUpdates", true); - prop.comment = "Allow to send current mod versions to the server and check for updates.\nIt allows to mod authors to see mod's popularity. Please don't disable it without necessity"; - allowUpdates = prop.getBoolean(true); - - prop = configuration.get("updates", "LogOnly", false); - prop.comment = "Don't display chat message, just add message to the log."; - logOnly = prop.getBoolean(false); - - prop = configuration.get("updates", "BetaNotifications", false); - prop.comment = "Set true to receive notifications about beta versions. Otherwise you will only receive information about stable versions"; - betaNotifications = prop.getBoolean(false); - - prop = configuration.get("updates", "ForCurrentMinecraftVersion", false); - prop.comment = "Check for updates only for current MC version.\nEx:if you have MC 1.4.2 and ForCurrentMinecraftVersion is true, then you wouldn't receive notifications about versions for MC 1.4.5"; - forCurrentMinecraftVersion = prop.getBoolean(false); - - configuration.save(); - - FMLLog.info("[Modstats] Config loaded. allowUpdates: %b, betaNotification: %b, strict: %b", allowUpdates, betaNotifications, forCurrentMinecraftVersion); - } + private static final String CONFIG_NAME = "modstats.cfg"; + + public boolean allowUpdates; + public boolean betaNotifications; + public boolean forCurrentMinecraftVersion; + public boolean logOnly; + + public Config() + { + File configLocation = new File(Loader.instance().getConfigDir(), CONFIG_NAME); + Configuration configuration = new Configuration(configLocation); + configuration.load(); + + Property prop = configuration.get("updates", "AllowUpdates", true); + prop.comment = "Allow to send current mod versions to the server and check for updates.\nIt allows to mod authors to see mod's popularity. Please don't disable it without necessity"; + allowUpdates = prop.getBoolean(true); + + prop = configuration.get("updates", "LogOnly", false); + prop.comment = "Don't display chat message, just add message to the log."; + logOnly = prop.getBoolean(false); + + prop = configuration.get("updates", "BetaNotifications", false); + prop.comment = "Set true to receive notifications about beta versions. Otherwise you will only receive information about stable versions"; + betaNotifications = prop.getBoolean(false); + + prop = configuration.get("updates", "ForCurrentMinecraftVersion", false); + prop.comment = "Check for updates only for current MC version.\nEx:if you have MC 1.4.2 and ForCurrentMinecraftVersion is true, then you wouldn't receive notifications about versions for MC 1.4.5"; + forCurrentMinecraftVersion = prop.getBoolean(false); + + configuration.save(); + + FMLLog.info("[Modstats] Config loaded. allowUpdates: %b, betaNotification: %b, strict: %b", allowUpdates, betaNotifications, forCurrentMinecraftVersion); + } } diff --git a/src/org/modstats/reporter/v1/DataSender.java b/src/org/modstats/reporter/v1/DataSender.java index 475359b66..5ca262b07 100644 --- a/src/org/modstats/reporter/v1/DataSender.java +++ b/src/org/modstats/reporter/v1/DataSender.java @@ -66,231 +66,229 @@ import cpw.mods.fml.common.versioning.ComparableVersion; class DataSender extends Thread { - private static final String urlAutoTemplate = "http://modstats.org/api/v1/report?mc=%s&user=%s&data=%s&sign=%s&beta=%b&strict=%b"; - private static final String urlManualTemplate = "http://modstats.org/api/v1/check?mc=%s&user=%s&data=%s&sign=%s&beta=%b&strict=%b"; + private static final String urlAutoTemplate = "http://modstats.org/api/v1/report?mc=%s&user=%s&data=%s&sign=%s&beta=%b&strict=%b"; + private static final String urlManualTemplate = "http://modstats.org/api/v1/check?mc=%s&user=%s&data=%s&sign=%s&beta=%b&strict=%b"; + + private final Reporter reporter; + public final boolean manual; + + public DataSender(Reporter reporter, boolean manual) + { + this.reporter = reporter; + this.manual = manual; + } + + private String toHexString(byte[] bytes) { + char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; + char[] hexChars = new char[bytes.length * 2]; + int v; + for ( int j = 0; j < bytes.length; j++ ) { + v = bytes[j] & 0xFF; + hexChars[j*2] = hexArray[v/16]; + hexChars[j*2 + 1] = hexArray[v%16]; + } + return new String(hexChars); + } + + private String getPlayerId() throws IOException + { + File statDir = new File(FMLClientHandler.instance().getClient().mcDataDir, "stats"); + if(!statDir.exists()) + { + statDir.mkdirs(); + } + String mac = ""; + try + { + InetAddress address = InetAddress.getLocalHost(); + NetworkInterface ni = NetworkInterface.getByInetAddress(address); + byte[] macArray = ni.getHardwareAddress(); + if(macArray != null) + { + mac = toHexString(macArray); + } + } + catch(Exception ex) + { + } + File uidFile = new File(statDir, "player.uid"); + if(uidFile.exists() && uidFile.canRead() && uidFile.length() == 32+mac.length()) + { + String data = Files.toString(uidFile, Charsets.US_ASCII); + String storedMac = data.substring(32); + if(storedMac.equalsIgnoreCase(mac)) + return data.substring(0, 32); + } + uidFile.createNewFile(); + if(uidFile.canWrite()) + { + String uid = UUID.randomUUID().toString().replace("-", ""); + FileOutputStream output = new FileOutputStream(uidFile); + output.write((uid+mac).getBytes()); + output.close(); + return uid; + } + return ""; + } + + private String getSignature(String data) + { + return Hashing.md5().hashString(data).toString(); + } + + private String getData() + { + StringBuilder b = new StringBuilder(); + for (Map.Entry item : reporter.registeredMods.entrySet()) + { + b.append(item.getKey()).append("+").append(item.getValue().version).append("$"); + } + return b.toString(); + } + + private boolean checkIsNewer(String current, String received) + { + return new ComparableVersion(received).compareTo(new ComparableVersion(current)) > 0; + } + + + private void parseResponse(String response) + { + try + { + JsonRootNode json = (new JdomParser()).parse(response); + //empty result + if(!json.isNode("mods")) + { + FMLLog.info("[Modstats] Empty result"); + return; + } + List modList = json.getArrayNode("mods"); + ModsUpdateEvent event = new ModsUpdateEvent(); + for (JsonNode modObject : modList) + { + String prefix = modObject.getStringValue("code"); + if(!reporter.registeredMods.containsKey(prefix)) + { + FMLLog.warning("[Modstats] Extra mod '%s' in service response", prefix); + continue; + } + String version = modObject.getStringValue("ver"); + if(version==null || version.equals(reporter.registeredMods.get(prefix).version)) + { + continue; + } + if(checkIsNewer(reporter.registeredMods.get(prefix).version, version)) + { + ModVersionData data = new ModVersionData(prefix, reporter.registeredMods.get(prefix).name, version); + Map fields = modObject.getFields(); + for (Map.Entry entry : fields.entrySet()) + { + String fieldName = entry.getKey().getText(); + if(fieldName.equals("code") || fieldName.equals("ver")) + continue; + if(!(entry.getValue() instanceof JsonStringNode)) + { + FMLLog.warning(String.format("[Modstats] Too complex data in response for field '%s'.", fieldName)); + continue; + } + String value = ((JsonStringNode)entry.getValue()).getText(); + if(fieldName.equals("chlog")) + { + data.changeLogUrl = value; + } + else if(fieldName.equals("link")) + { + data.downloadUrl = value; + } + else + { + data.extraFields.put(fieldName, value); + } + } + event.add(data); + } + + } + if(event.getUpdatedMods().size() > 0) + { + MinecraftForge.EVENT_BUS.post(event); + } + if(!event.isCanceled() && event.getUpdatedMods().size() > 0) + { + List updatedModsToOutput = event.getUpdatedMods(); + StringBuilder builder = new StringBuilder("Updates found: "); + Iterator iterator = updatedModsToOutput.iterator(); + while(iterator.hasNext()) + { + ModVersionData modVersionData = iterator.next(); + builder.append(modVersionData.name) + .append(" (") + .append(modVersionData.version) + .append(")") + .append(iterator.hasNext()?",":"."); + } + FMLLog.info("[Modstats] %s", builder.toString()); + if(!reporter.config.logOnly && FMLCommonHandler.instance().getSide().isClient()) + { + Minecraft mc = FMLClientHandler.instance().getClient(); + int maxTries = 30; + while(mc.thePlayer==null && maxTries>0) + { + try + { + sleep(1000); + } catch (InterruptedException e) + { + } + maxTries--; + } + if(mc.thePlayer != null) + { + mc.thePlayer.addChatMessage(builder.toString()); + } + } + } + + } catch (InvalidSyntaxException e) + { + FMLLog.warning("[Modstats] Can't parse response: '%s'.", e.getMessage()); + } + } - private final Reporter reporter; - public final boolean manual; - - public DataSender(Reporter reporter, boolean manual) - { - this.reporter = reporter; - this.manual = manual; - } - - private String toHexString(byte[] bytes) - { - char[] hexArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - char[] hexChars = new char[bytes.length * 2]; - int v; - for (int j = 0; j < bytes.length; j++) - { - v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v / 16]; - hexChars[j * 2 + 1] = hexArray[v % 16]; - } - return new String(hexChars); - } - - private String getPlayerId() throws IOException - { - File statDir = new File(FMLClientHandler.instance().getClient().mcDataDir, "stats"); - if (!statDir.exists()) - { - statDir.mkdirs(); - } - String mac = ""; - try - { - InetAddress address = InetAddress.getLocalHost(); - NetworkInterface ni = NetworkInterface.getByInetAddress(address); - byte[] macArray = ni.getHardwareAddress(); - if (macArray != null) - { - mac = toHexString(macArray); - } - } - catch (Exception ex) - { - } - File uidFile = new File(statDir, "player.uid"); - if (uidFile.exists() && uidFile.canRead() && uidFile.length() == 32 + mac.length()) - { - String data = Files.toString(uidFile, Charsets.US_ASCII); - String storedMac = data.substring(32); - if (storedMac.equalsIgnoreCase(mac)) - return data.substring(0, 32); - } - uidFile.createNewFile(); - if (uidFile.canWrite()) - { - String uid = UUID.randomUUID().toString().replace("-", ""); - FileOutputStream output = new FileOutputStream(uidFile); - output.write((uid + mac).getBytes()); - output.close(); - return uid; - } - return ""; - } - - private String getSignature(String data) - { - return Hashing.md5().hashString(data).toString(); - } - - private String getData() - { - StringBuilder b = new StringBuilder(); - for (Map.Entry item : reporter.registeredMods.entrySet()) - { - b.append(item.getKey()).append("+").append(item.getValue().version).append("$"); - } - return b.toString(); - } - - private boolean checkIsNewer(String current, String received) - { - return new ComparableVersion(received).compareTo(new ComparableVersion(current)) > 0; - } - - private void parseResponse(String response) - { - try - { - JsonRootNode json = (new JdomParser()).parse(response); - // empty result - if (!json.isNode("mods")) - { - FMLLog.info("[Modstats] Empty result"); - return; - } - List modList = json.getArrayNode("mods"); - ModsUpdateEvent event = new ModsUpdateEvent(); - for (JsonNode modObject : modList) - { - String prefix = modObject.getStringValue("code"); - if (!reporter.registeredMods.containsKey(prefix)) - { - FMLLog.warning("[Modstats] Extra mod '%s' in service response", prefix); - continue; - } - String version = modObject.getStringValue("ver"); - if (version == null || version.equals(reporter.registeredMods.get(prefix).version)) - { - continue; - } - if (checkIsNewer(reporter.registeredMods.get(prefix).version, version)) - { - ModVersionData data = new ModVersionData(prefix, reporter.registeredMods.get(prefix).name, version); - Map fields = modObject.getFields(); - for (Map.Entry entry : fields.entrySet()) - { - String fieldName = entry.getKey().getText(); - if (fieldName.equals("code") || fieldName.equals("ver")) - continue; - if (!(entry.getValue() instanceof JsonStringNode)) - { - FMLLog.warning(String.format("[Modstats] Too complex data in response for field '%s'.", fieldName)); - continue; - } - String value = ((JsonStringNode) entry.getValue()).getText(); - if (fieldName.equals("chlog")) - { - data.changeLogUrl = value; - } - else if (fieldName.equals("link")) - { - data.downloadUrl = value; - } - else - { - data.extraFields.put(fieldName, value); - } - } - event.add(data); - } - - } - if (event.getUpdatedMods().size() > 0) - { - MinecraftForge.EVENT_BUS.post(event); - } - if (!event.isCanceled() && event.getUpdatedMods().size() > 0) - { - List updatedModsToOutput = event.getUpdatedMods(); - StringBuilder builder = new StringBuilder("Updates found: "); - Iterator iterator = updatedModsToOutput.iterator(); - while (iterator.hasNext()) - { - ModVersionData modVersionData = iterator.next(); - builder.append(modVersionData.name).append(" (").append(modVersionData.version).append(")").append(iterator.hasNext() ? "," : "."); - } - FMLLog.info("[Modstats] %s", builder.toString()); - if (!reporter.config.logOnly && FMLCommonHandler.instance().getSide().isClient()) - { - Minecraft mc = FMLClientHandler.instance().getClient(); - int maxTries = 30; - while (mc.thePlayer == null && maxTries > 0) - { - try - { - sleep(1000); - } - catch (InterruptedException e) - { - } - maxTries--; - } - if (mc.thePlayer != null) - { - mc.thePlayer.addChatMessage(builder.toString()); - } - } - } - - } - catch (InvalidSyntaxException e) - { - FMLLog.warning("[Modstats] Can't parse response: '%s'.", e.getMessage()); - } - } - - @Override - public void run() - { - try - { - String data = getData(); - String playerId = getPlayerId(); - String hash = getSignature(playerId + "!" + data); - String template = manual ? urlManualTemplate : urlAutoTemplate; - String mcVersion = new CallableMinecraftVersion(null).minecraftVersion(); - URL url = new URL(String.format(template, mcVersion, playerId, data, hash, reporter.config.betaNotifications, reporter.config.forCurrentMinecraftVersion)); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setConnectTimeout(5000); - connection.setReadTimeout(5000); - BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String line; - String out = ""; - while ((line = reader.readLine()) != null) - { - // in most cases it will contain just one line - out += line; - } - reader.close(); - parseResponse(out); - } - catch (MalformedURLException e) - { - FMLLog.warning("[Modstats] Invalid stat report url"); - } - catch (IOException e) - { - FMLLog.info("[Modstats] Stat wasn't reported '" + e.getMessage() + "'"); - } - catch (Exception e) - { - FMLLog.warning("[Modstats] Something wrong: " + e.toString()); - } - } + + @Override + public void run() + { + try + { + String data = getData(); + String playerId = getPlayerId(); + String hash = getSignature(playerId+"!"+data); + String template = manual?urlManualTemplate:urlAutoTemplate; + String mcVersion = new CallableMinecraftVersion(null).minecraftVersion(); + URL url = new URL(String.format(template, mcVersion, playerId, data, hash, reporter.config.betaNotifications, reporter.config.forCurrentMinecraftVersion)); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + String out = ""; + while ((line = reader.readLine()) != null) { + //in most cases it will contain just one line + out += line; + } + reader.close(); + parseResponse(out); + } catch (MalformedURLException e) + { + FMLLog.warning("[Modstats] Invalid stat report url"); + } catch (IOException e) + { + FMLLog.info("[Modstats] Stat wasn't reported '"+e.getMessage()+"'"); + } catch(Exception e) + { + FMLLog.warning("[Modstats] Something wrong: "+e.toString()); + } + } } diff --git a/src/org/modstats/reporter/v1/Reporter.java b/src/org/modstats/reporter/v1/Reporter.java index 06b4b079d..2744b6d79 100644 --- a/src/org/modstats/reporter/v1/Reporter.java +++ b/src/org/modstats/reporter/v1/Reporter.java @@ -42,101 +42,104 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Mod; + public class Reporter implements IModstatsReporter { - public Map registeredMods; - private DataSender sender; - public Config config; + public Map registeredMods; + private DataSender sender; + public Config config; + + /** + * At least one auto check was completed successfully + */ + private boolean checkedAuto; - /** - * At least one auto check was completed successfully - */ - private boolean checkedAuto; + public Reporter() + { + checkedAuto = false; + registeredMods = new ConcurrentHashMap(2, 0.9f, 1); + MinecraftForge.EVENT_BUS.register(this); + config = new Config(); + } + + + private void startCheck(boolean manual) + { + if(!config.allowUpdates) + return; + //only manual check is allowed on servers + if(!FMLCommonHandler.instance().getSide().isClient() && !manual) + return; + if(registeredMods.isEmpty()) + return; + DataSender currentSender = sender; + if(!manual && checkedAuto) + return; + if(currentSender!=null && (currentSender.manual == false || manual)) + return; + currentSender = new DataSender(this, manual); + currentSender.start(); + sender = currentSender; + + } + + @ForgeSubscribe + public void worldLoad(WorldEvent.Load event) + { + startCheck(false); + } - public Reporter() - { - checkedAuto = false; - registeredMods = new ConcurrentHashMap(2, 0.9f, 1); - MinecraftForge.EVENT_BUS.register(this); - config = new Config(); - } + + @Override + public void registerMod(Object mod) + { + if(!config.allowUpdates) + return; + if(mod == null) + { + FMLLog.warning("[Modstats] Can't register null mod."); + return; + } + ModstatInfo info = mod.getClass().getAnnotation(ModstatInfo.class); + if(info == null) + { + FMLLog.warning("[Modstats] ModstatsInfo annotation not found for given mod."); + return; + } + + if(info.prefix() == null || info.prefix().equals("")) + { + FMLLog.warning("[Modstats] Mod prefix can't be empty."); + return; + } + Mod modData = mod.getClass().getAnnotation(Mod.class); + ModVersionData data; + if(modData == null) + { + if(info.name() == null || info.name().equals("")) + { + FMLLog.warning("[Modstats] Mod name can't be empty."); + return; + } + if(info.version() == null || info.version().equals("")) + { + FMLLog.warning("[Modstats] Mod version can't be empty."); + return; + } + data = new ModVersionData(info.prefix(), info.name(), info.version()); + } + else + { + data = new ModVersionData(info.prefix(), modData.name(), modData.version()); + } + registeredMods.put(info.prefix(), data); + } - private void startCheck(boolean manual) - { - if (!config.allowUpdates) - return; - // only manual check is allowed on servers - if (!FMLCommonHandler.instance().getSide().isClient() && !manual) - return; - if (registeredMods.isEmpty()) - return; - DataSender currentSender = sender; - if (!manual && checkedAuto) - return; - if (currentSender != null && (currentSender.manual == false || manual)) - return; - currentSender = new DataSender(this, manual); - currentSender.start(); - sender = currentSender; - - } - - @ForgeSubscribe - public void worldLoad(WorldEvent.Load event) - { - startCheck(false); - } - - @Override - public void registerMod(Object mod) - { - if (!config.allowUpdates) - return; - if (mod == null) - { - FMLLog.warning("[Modstats] Can't register null mod."); - return; - } - ModstatInfo info = mod.getClass().getAnnotation(ModstatInfo.class); - if (info == null) - { - FMLLog.warning("[Modstats] ModstatsInfo annotation not found for given mod."); - return; - } - - if (info.prefix() == null || info.prefix().equals("")) - { - FMLLog.warning("[Modstats] Mod prefix can't be empty."); - return; - } - Mod modData = mod.getClass().getAnnotation(Mod.class); - ModVersionData data; - if (modData == null) - { - if (info.name() == null || info.name().equals("")) - { - FMLLog.warning("[Modstats] Mod name can't be empty."); - return; - } - if (info.version() == null || info.version().equals("")) - { - FMLLog.warning("[Modstats] Mod version can't be empty."); - return; - } - data = new ModVersionData(info.prefix(), info.name(), info.version()); - } - else - { - data = new ModVersionData(info.prefix(), modData.name(), modData.version()); - } - registeredMods.put(info.prefix(), data); - } - - @Override - public void doManualCheck() - { - startCheck(true); - } + @Override + public void doManualCheck() + { + startCheck(true); + } } diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 5e98c595b..1c2b2c3bc 100644 --- a/src/resonantinduction/ClientProxy.java +++ b/src/resonantinduction/ClientProxy.java @@ -5,7 +5,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; -import resonantinduction.base.Vector3; import resonantinduction.battery.TileEntityBattery; import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.fx.FXElectricBolt; @@ -18,6 +17,7 @@ import resonantinduction.render.RenderEMContractor; import resonantinduction.render.RenderMultimeter; import resonantinduction.render.RenderTesla; import resonantinduction.tesla.TileEntityTesla; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; diff --git a/src/resonantinduction/CommonProxy.java b/src/resonantinduction/CommonProxy.java index 357917d73..f4222e154 100644 --- a/src/resonantinduction/CommonProxy.java +++ b/src/resonantinduction/CommonProxy.java @@ -6,11 +6,11 @@ package resonantinduction; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import resonantinduction.base.Vector3; import resonantinduction.battery.ContainerBattery; import resonantinduction.battery.TileEntityBattery; import resonantinduction.multimeter.ContainerMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.common.network.IGuiHandler; /** diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 10df04bbb..b867659a9 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -4,15 +4,15 @@ import java.io.File; import java.util.Arrays; import java.util.logging.Logger; -import org.modstats.ModstatInfo; -import org.modstats.Modstats; - import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.Configuration; import net.minecraftforge.oredict.ShapedOreRecipe; -import resonantinduction.api.IBattery; + +import org.modstats.ModstatInfo; +import org.modstats.Modstats; + import resonantinduction.battery.BlockBattery; import resonantinduction.battery.ItemCapacitor; import resonantinduction.battery.TileEntityBattery; @@ -26,6 +26,7 @@ import resonantinduction.multimeter.ItemBlockMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; import resonantinduction.tesla.BlockTesla; import resonantinduction.tesla.TileEntityTesla; +import universalelectricity.core.item.IItemElectric; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; @@ -201,7 +202,7 @@ public class ResonantInduction * Recipes */ ItemStack emptyCapacitor = new ItemStack(itemCapacitor); - ((IBattery) itemCapacitor).setEnergyStored(emptyCapacitor, 0); + ((IItemElectric) itemCapacitor).setElectricity(emptyCapacitor, 0); /** Capacitor **/ GameRegistry.addRecipe(new ShapedOreRecipe(emptyCapacitor, "RRR", "RIR", "RRR", 'R', Item.redstone, 'I', Item.ingotIron)); diff --git a/src/resonantinduction/api/IBattery.java b/src/resonantinduction/api/IBattery.java deleted file mode 100644 index 9cdd0b6f4..000000000 --- a/src/resonantinduction/api/IBattery.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - */ -package resonantinduction.api; - -import net.minecraft.item.ItemStack; - -/** - * TODO: Use UE interface after ModJAm - * - * @author Calclavia - * - */ -public interface IBattery -{ - public float getEnergyStored(ItemStack itemStack); - - public float getMaxEnergyStored(ItemStack itemStack); - - public float getTransfer(ItemStack itemStack); - - /** - * @param itemStack - * @param amount - */ - public void setEnergyStored(ItemStack itemStack, float amount); -} diff --git a/src/resonantinduction/base/Vector3.java b/src/resonantinduction/base/Vector3.java deleted file mode 100644 index 2659ac336..000000000 --- a/src/resonantinduction/base/Vector3.java +++ /dev/null @@ -1,365 +0,0 @@ -/** - * - */ -package resonantinduction.base; - -import java.util.List; - -import net.minecraft.entity.Entity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeDirection; - -/** - * @author Calclavia - * - */ -public class Vector3 -{ - public double x, y, z; - - public Vector3(double x, double y, double z) - { - this.x = x; - this.y = y; - this.z = z; - } - - public Vector3() - { - this(0, 0, 0); - } - - public Vector3(double amount) - { - this(amount, amount, amount); - } - - public Vector3(Vector3 clone) - { - this(clone.x, clone.y, clone.z); - } - - public Vector3(TileEntity tileEntity) - { - this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); - } - - public Vector3(Entity entity) - { - this(entity.posX, entity.posY, entity.posZ); - } - - public Vector3(ForgeDirection direction) - { - this(direction.offsetX, direction.offsetY, direction.offsetZ); - } - - public Vector3 scale(double amount) - { - return this.scale(new Vector3(amount)); - } - - public Vector3 scale(Vector3 amount) - { - return new Vector3(this.x * amount.x, this.y * amount.y, this.z * amount.z); - } - - public Vector3 difference(Vector3 compare) - { - return new Vector3(this.x - compare.x, this.y - compare.y, this.z - compare.z); - } - - public double getMagnitudeSquared() - { - return this.x * this.x + this.y * this.y + this.z * this.z; - } - - public double getMagnitude() - { - return Math.sqrt(this.getMagnitudeSquared()); - } - - public double distance(Vector3 compare) - { - Vector3 difference = this.difference(compare); - return difference.getMagnitude(); - } - - /** - * Cross product functions - * - * @return The cross product between this vector and another. - */ - public Vector3 crossProduct(Vector3 compare) - { - return new Vector3(this.y * compare.z - this.z * compare.y, this.z * compare.x - this.x * compare.z, this.x * compare.y - this.y * compare.x); - } - - public Vector3 xCrossProduct() - { - return new Vector3(0.0D, this.z, -this.y); - } - - public Vector3 zCrossProduct() - { - return new Vector3(-this.y, this.x, 0.0D); - } - - public double dotProduct(Vector3 vec2) - { - return this.x * vec2.x + this.y * vec2.y + this.z * vec2.z; - } - - public Vector3 getFromSide(ForgeDirection side) - { - return new Vector3(x + side.offsetX, y + side.offsetY, z + side.offsetZ); - } - - /** - * @return The perpendicular vector. - */ - public Vector3 getPerpendicular() - { - if (this.z == 0.0F) - { - return this.zCrossProduct(); - } - - return this.xCrossProduct(); - } - - /** - * @return True if this Vector3 is zero. - */ - public boolean isZero() - { - return (this.x == 0.0F) && (this.y == 0.0F) && (this.z == 0.0F); - } - - public Vector3 translate(Vector3 offset) - { - return new Vector3(this.x + offset.x, this.y + offset.y, this.z + offset.z); - } - - public Vector3 translate(double offset) - { - return new Vector3(this.x + offset, this.y + offset, this.z + offset); - } - - public Vector3 normalize() - { - double d = getMagnitude(); - - if (d != 0) - { - return scale(1 / d); - } - - return this; - } - - /** - * Rotate by a this vector around an axis. - * - * @return The new Vector3 rotation. - */ - public Vector3 rotate(float angle, Vector3 axis) - { - return translateMatrix(getRotationMatrix(angle, axis), this.clone()); - } - - public double[] getRotationMatrix(float angle) - { - double[] matrix = new double[16]; - Vector3 axis = this.clone().normalize(); - double x = axis.x; - double y = axis.y; - double z = axis.z; - angle *= 0.0174532925D; - float cos = (float) Math.cos(angle); - float ocos = 1.0F - cos; - float sin = (float) Math.sin(angle); - matrix[0] = (x * x * ocos + cos); - matrix[1] = (y * x * ocos + z * sin); - matrix[2] = (x * z * ocos - y * sin); - matrix[4] = (x * y * ocos - z * sin); - matrix[5] = (y * y * ocos + cos); - matrix[6] = (y * z * ocos + x * sin); - matrix[8] = (x * z * ocos + y * sin); - matrix[9] = (y * z * ocos - x * sin); - matrix[10] = (z * z * ocos + cos); - matrix[15] = 1.0F; - return matrix; - } - - public static Vector3 translateMatrix(double[] matrix, Vector3 translation) - { - double x = translation.x * matrix[0] + translation.y * matrix[1] + translation.z * matrix[2] + matrix[3]; - double y = translation.x * matrix[4] + translation.y * matrix[5] + translation.z * matrix[6] + matrix[7]; - double z = translation.x * matrix[8] + translation.y * matrix[9] + translation.z * matrix[10] + matrix[11]; - translation.x = x; - translation.y = y; - translation.z = z; - return translation; - } - - public static double[] getRotationMatrix(float angle, Vector3 axis) - { - return axis.getRotationMatrix(angle); - } - - public static Vector3 getDeltaPositionFromRotation(double rotationYaw, double rotationPitch) - { - rotationYaw = rotationYaw + 90; - rotationPitch = -rotationPitch; - return new Vector3(Math.cos(Math.toRadians(rotationYaw)), Math.sin(Math.toRadians(rotationPitch)), Math.sin(Math.toRadians(rotationYaw))); - } - - public double[] getDeltaRotationFromPosition() - { - double rotationPitch = Math.toDegrees(Math.asin(this.y)); - double rotationYaw = Math.toDegrees(Math.atan2(this.z, this.x)); - rotationYaw = rotationYaw - 90; - rotationPitch = -rotationPitch; - return new double[] { MathHelper.wrapAngleTo180_double(rotationYaw), MathHelper.wrapAngleTo180_double(rotationPitch) }; - } - - public double getAngle(Vector3 vector) - { - return this.getAnglePreNorm(vector.clone().normalize()); - } - - public double getAnglePreNorm(Vector3 vector) - { - return Math.acos(this.dotProduct(vector)); - } - - public TileEntity getTileEntity(World world) - { - return world.getBlockTileEntity((int) this.x, (int) this.y, (int) this.z); - } - - public MovingObjectPosition rayTraceEntities(World world, Vector3 target) - { - MovingObjectPosition pickedEntity = null; - Vec3 startingPosition = this.toVec3(); - Vec3 look = target.clone().difference(this).normalize().toVec3(); - double reachDistance = this.distance(target); - Vec3 reachPoint = Vec3.createVectorHelper(startingPosition.xCoord + look.xCoord * reachDistance, startingPosition.yCoord + look.yCoord * reachDistance, startingPosition.zCoord + look.zCoord * reachDistance); - - double checkBorder = 1.1 * reachDistance; - AxisAlignedBB boxToScan = AxisAlignedBB.getAABBPool().getAABB(-checkBorder, -checkBorder, -checkBorder, checkBorder, checkBorder, checkBorder).offset(this.x, this.y, this.z); - - @SuppressWarnings("unchecked") - List entitiesHit = world.getEntitiesWithinAABBExcludingEntity(null, boxToScan); - double closestEntity = reachDistance; - - if (entitiesHit == null || entitiesHit.isEmpty()) - { - return null; - } - for (Entity entityHit : entitiesHit) - { - if (entityHit != null && entityHit.canBeCollidedWith() && entityHit.boundingBox != null) - { - float border = entityHit.getCollisionBorderSize(); - AxisAlignedBB aabb = entityHit.boundingBox.expand(border, border, border); - MovingObjectPosition hitMOP = aabb.calculateIntercept(startingPosition, reachPoint); - - if (hitMOP != null) - { - if (aabb.isVecInside(startingPosition)) - { - if (0.0D < closestEntity || closestEntity == 0.0D) - { - pickedEntity = new MovingObjectPosition(entityHit); - if (pickedEntity != null) - { - pickedEntity.hitVec = hitMOP.hitVec; - closestEntity = 0.0D; - } - } - } - else - { - double distance = startingPosition.distanceTo(hitMOP.hitVec); - - if (distance < closestEntity || closestEntity == 0.0D) - { - pickedEntity = new MovingObjectPosition(entityHit); - pickedEntity.hitVec = hitMOP.hitVec; - closestEntity = distance; - } - } - } - } - } - return pickedEntity; - } - - private Vec3 toVec3() - { - return Vec3.createVectorHelper(this.x, this.y, this.z); - } - - @Override - public Vector3 clone() - { - return new Vector3(this.x, this.y, this.z); - } - - @Override - public int hashCode() - { - int code = 1; - code = 31 * new Double(x).hashCode(); - code = 31 * new Double(y).hashCode(); - code = 31 * new Double(z).hashCode(); - return code; - } - - @Override - public boolean equals(Object o) - { - if (o instanceof Vector3) - { - Vector3 vector3 = (Vector3) o; - return this.x == vector3.x && this.y == vector3.y && this.z == vector3.z; - } - - return false; - } - - @Override - public String toString() - { - return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]"; - } - - /** - * @param world - * @return - */ - public int getBlockID(World world) - { - return world.getBlockId((int) this.x, (int) this.y, (int) this.z); - } - - public ForgeDirection toForgeDirection() - { - for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) - { - if (this.x == direction.offsetX && this.y == direction.offsetY && this.z == direction.offsetZ) - { - return direction; - } - } - - return ForgeDirection.UNKNOWN; - } -} diff --git a/src/resonantinduction/battery/BatteryManager.java b/src/resonantinduction/battery/BatteryManager.java index b3a5a3b35..cb1a6617f 100644 --- a/src/resonantinduction/battery/BatteryManager.java +++ b/src/resonantinduction/battery/BatteryManager.java @@ -3,7 +3,7 @@ package resonantinduction.battery; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import resonantinduction.api.IBattery; +import universalelectricity.core.item.IItemElectric; public class BatteryManager { @@ -33,7 +33,7 @@ public class BatteryManager @Override public boolean isItemValid(ItemStack itemstack) { - return itemstack.getItem() instanceof IBattery; + return itemstack.getItem() instanceof IItemElectric; } } } diff --git a/src/resonantinduction/battery/BatteryUpdateProtocol.java b/src/resonantinduction/battery/BatteryUpdateProtocol.java index e62a6e5df..e172721bd 100644 --- a/src/resonantinduction/battery/BatteryUpdateProtocol.java +++ b/src/resonantinduction/battery/BatteryUpdateProtocol.java @@ -11,7 +11,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.base.ListUtil; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; public class BatteryUpdateProtocol { @@ -179,7 +179,7 @@ public class BatteryUpdateProtocol for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - TileEntity tileEntity = new Vector3(tile).getFromSide(side).getTileEntity(tile.worldObj); + TileEntity tileEntity = new Vector3(tile).modifyPositionFromSide(side).getTileEntity(tile.worldObj); if (tileEntity instanceof TileEntityBattery) { diff --git a/src/resonantinduction/battery/BlockBattery.java b/src/resonantinduction/battery/BlockBattery.java index 9c5553fb7..e8fe76cef 100644 --- a/src/resonantinduction/battery/BlockBattery.java +++ b/src/resonantinduction/battery/BlockBattery.java @@ -12,10 +12,10 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; -import resonantinduction.api.IBattery; import resonantinduction.base.BlockBase; import resonantinduction.base.ListUtil; import resonantinduction.render.BlockRenderingHandler; +import universalelectricity.core.item.IItemElectric; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -63,7 +63,7 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider { if (entityPlayer.getCurrentEquippedItem() != null) { - if (entityPlayer.getCurrentEquippedItem().getItem() instanceof IBattery) + if (entityPlayer.getCurrentEquippedItem().getItem() instanceof IItemElectric) { if (side != 0 && side != 1) { diff --git a/src/resonantinduction/battery/ContainerBattery.java b/src/resonantinduction/battery/ContainerBattery.java index d45c499a7..559d5b1dd 100644 --- a/src/resonantinduction/battery/ContainerBattery.java +++ b/src/resonantinduction/battery/ContainerBattery.java @@ -6,9 +6,9 @@ import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import resonantinduction.api.IBattery; import resonantinduction.battery.BatteryManager.SlotBattery; import resonantinduction.battery.BatteryManager.SlotOut; +import universalelectricity.core.item.IItemElectric; public class ContainerBattery extends Container { @@ -100,7 +100,7 @@ public class ContainerBattery extends Container return null; } } - else if (slotStack.getItem() instanceof IBattery) + else if (slotStack.getItem() instanceof IItemElectric) { if (!mergeItemStack(slotStack, 0, 1, false)) { diff --git a/src/resonantinduction/battery/ItemCapacitor.java b/src/resonantinduction/battery/ItemCapacitor.java index fb285e0c2..1735bcba1 100644 --- a/src/resonantinduction/battery/ItemCapacitor.java +++ b/src/resonantinduction/battery/ItemCapacitor.java @@ -3,15 +3,13 @@ */ package resonantinduction.battery; -import java.util.List; - -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import resonantinduction.api.IBattery; -import resonantinduction.base.ItemBase; +import net.minecraftforge.common.Configuration; +import resonantinduction.ResonantInduction; +import resonantinduction.TabRI; +import universalelectricity.compatibility.ItemUniversalElectric; /** * Stores power. @@ -19,52 +17,22 @@ import resonantinduction.base.ItemBase; * @author Calclavia * */ -public class ItemCapacitor extends ItemBase implements IBattery +public class ItemCapacitor extends ItemUniversalElectric { public ItemCapacitor(int id) { - super("capacitor", id); + super(ResonantInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "capacitor", id).getInt(id)); + this.setCreativeTab(TabRI.INSTANCE); + this.setUnlocalizedName(ResonantInduction.PREFIX + "capacitor"); + this.func_111206_d(ResonantInduction.PREFIX + "capacitor"); this.setMaxStackSize(1); this.setMaxDamage(100); } - @Override - public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - double energyStored = this.getEnergyStored(itemStack); - par3List.add("Energy: " + (int) energyStored + "/" + (int) this.getMaxEnergyStored(itemStack) + " KJ"); - } - @Override public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { - this.setEnergyStored(par1ItemStack, 0); - } - - @Override - public void setEnergyStored(ItemStack itemStack, float amount) - { - if (itemStack.getTagCompound() == null) - { - itemStack.setTagCompound(new NBTTagCompound()); - } - - itemStack.getTagCompound().setFloat("energyStored", amount); - itemStack.setItemDamage((int) (100 - (amount / getMaxEnergyStored(itemStack)) * 100)); - } - - @Override - public float getEnergyStored(ItemStack itemStack) - { - if (itemStack.getTagCompound() == null) - { - itemStack.setTagCompound(new NBTTagCompound()); - } - - float amount = itemStack.getTagCompound().getFloat("energyStored"); - itemStack.setItemDamage((int) (100 - (amount / getMaxEnergyStored(itemStack)) * 100)); - - return amount; + this.setElectricity(par1ItemStack, 0); } @Override @@ -74,20 +42,9 @@ public class ItemCapacitor extends ItemBase implements IBattery } @Override - public float getMaxEnergyStored(ItemStack itemStack) + public float getMaxElectricityStored(ItemStack theItem) { - return 20; - } - - @Override - public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) - { - ItemStack chargedStack = new ItemStack(par1, 1, 0); - this.setEnergyStored(chargedStack, this.getMaxEnergyStored(chargedStack)); - par3List.add(chargedStack); - ItemStack unchargedStack = new ItemStack(par1, 1, 0); - this.setEnergyStored(unchargedStack, 0); - par3List.add(unchargedStack); + return 25; } } diff --git a/src/resonantinduction/battery/SynchronizedBatteryData.java b/src/resonantinduction/battery/SynchronizedBatteryData.java index ad1b2660d..782091968 100644 --- a/src/resonantinduction/battery/SynchronizedBatteryData.java +++ b/src/resonantinduction/battery/SynchronizedBatteryData.java @@ -6,9 +6,9 @@ import java.util.List; import java.util.Set; import net.minecraft.item.ItemStack; -import resonantinduction.api.IBattery; import resonantinduction.base.ListUtil; -import resonantinduction.base.Vector3; +import universalelectricity.core.item.IItemElectric; +import universalelectricity.core.vector.Vector3; public class SynchronizedBatteryData { @@ -65,7 +65,7 @@ public class SynchronizedBatteryData for (int i = 0; i < toSort.length - 1; i++) { - if (((IBattery) toSort[i].getItem()).getEnergyStored(toSort[i]) < ((IBattery) toSort[i + 1].getItem()).getEnergyStored(toSort[i + 1])) + if (((IItemElectric) toSort[i].getItem()).getElectricityStored(toSort[i]) < ((IItemElectric) toSort[i + 1].getItem()).getElectricityStored(toSort[i + 1])) { temp = toSort[i]; toSort[i] = toSort[i + 1]; diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index ca46a81da..5bb2a8437 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -13,13 +13,13 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import resonantinduction.PacketHandler; -import resonantinduction.api.IBattery; import resonantinduction.api.ITesla; import resonantinduction.base.IPacketReceiver; import resonantinduction.base.ListUtil; import resonantinduction.base.TileEntityBase; -import resonantinduction.base.Vector3; import resonantinduction.tesla.TeslaGrid; +import universalelectricity.core.item.IItemElectric; +import universalelectricity.core.vector.Vector3; import com.google.common.io.ByteArrayDataInput; @@ -69,25 +69,25 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver if (structure.visibleInventory[1] != null) { ItemStack itemStack = structure.visibleInventory[1]; - IBattery battery = (IBattery) itemStack.getItem(); + IItemElectric battery = (IItemElectric) itemStack.getItem(); float energyStored = getMaxEnergyStored(); - float batteryNeeded = battery.getMaxEnergyStored(itemStack) - battery.getEnergyStored(itemStack); + float batteryNeeded = battery.getMaxElectricityStored(itemStack) - battery.getElectricityStored(itemStack); float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded)); - battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + removeEnergy(toGive, true)); + battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) + removeEnergy(toGive, true)); } if (structure.visibleInventory[2] != null) { ItemStack itemStack = structure.visibleInventory[2]; - IBattery battery = (IBattery) itemStack.getItem(); + IItemElectric battery = (IItemElectric) itemStack.getItem(); float energyNeeded = getMaxEnergyStored() - getEnergyStored(); - float batteryStored = battery.getEnergyStored(itemStack); + float batteryStored = battery.getElectricityStored(itemStack); float toReceive = Math.min(energyNeeded, Math.min(battery.getTransfer(itemStack), batteryStored)); - battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - addEnergy(toReceive, true)); + battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) - addEnergy(toReceive, true)); } if (prevStructure != structure) @@ -265,16 +265,16 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver for (ItemStack itemStack : structure.inventory) { - if (itemStack.getItem() instanceof IBattery) + if (itemStack.getItem() instanceof IItemElectric) { - IBattery battery = (IBattery) itemStack.getItem(); + IItemElectric battery = (IItemElectric) itemStack.getItem(); float needed = amount - added; - float itemAdd = Math.min(battery.getMaxEnergyStored(itemStack) - battery.getEnergyStored(itemStack), needed); + float itemAdd = Math.min(battery.getMaxElectricityStored(itemStack) - battery.getElectricityStored(itemStack), needed); if (doAdd) { - battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + itemAdd); + battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) + itemAdd); } added += itemAdd; @@ -300,16 +300,16 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver for (ItemStack itemStack : inverse) { - if (itemStack.getItem() instanceof IBattery) + if (itemStack.getItem() instanceof IItemElectric) { - IBattery battery = (IBattery) itemStack.getItem(); + IItemElectric battery = (IItemElectric) itemStack.getItem(); float needed = amount - removed; - float itemRemove = Math.min(battery.getEnergyStored(itemStack), needed); + float itemRemove = Math.min(battery.getElectricityStored(itemStack), needed); if (doRemove) { - battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - itemRemove); + battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) - itemRemove); } removed += itemRemove; @@ -334,9 +334,9 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver { if (itemStack != null) { - if (itemStack.getItem() instanceof IBattery) + if (itemStack.getItem() instanceof IItemElectric) { - max += ((IBattery) itemStack.getItem()).getMaxEnergyStored(itemStack); + max += ((IItemElectric) itemStack.getItem()).getMaxElectricityStored(itemStack); } } } @@ -359,9 +359,9 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver { if (itemStack != null) { - if (itemStack.getItem() instanceof IBattery) + if (itemStack.getItem() instanceof IItemElectric) { - energy += ((IBattery) itemStack.getItem()).getEnergyStored(itemStack); + energy += ((IItemElectric) itemStack.getItem()).getElectricityStored(itemStack); } } } diff --git a/src/resonantinduction/contractor/BlockEMContractor.java b/src/resonantinduction/contractor/BlockEMContractor.java index 71ba68df6..d92a57144 100644 --- a/src/resonantinduction/contractor/BlockEMContractor.java +++ b/src/resonantinduction/contractor/BlockEMContractor.java @@ -9,9 +9,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; -import resonantinduction.base.Vector3; import resonantinduction.entangler.ItemCoordLink; import resonantinduction.render.BlockRenderingHandler; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/contractor/PathfinderEMContractor.java b/src/resonantinduction/contractor/PathfinderEMContractor.java index 86976e7fa..bbe62a1fe 100644 --- a/src/resonantinduction/contractor/PathfinderEMContractor.java +++ b/src/resonantinduction/contractor/PathfinderEMContractor.java @@ -4,7 +4,6 @@ package resonantinduction.contractor; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -12,7 +11,7 @@ import java.util.Set; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; /** * Uses the well known A* Pathfinding algorithm. diff --git a/src/resonantinduction/contractor/ThreadPathfinding.java b/src/resonantinduction/contractor/ThreadPathfinding.java index 5f95d122e..340747201 100644 --- a/src/resonantinduction/contractor/ThreadPathfinding.java +++ b/src/resonantinduction/contractor/ThreadPathfinding.java @@ -3,7 +3,7 @@ */ package resonantinduction.contractor; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; /** * @author Calclavia diff --git a/src/resonantinduction/contractor/TileEntityEMContractor.java b/src/resonantinduction/contractor/TileEntityEMContractor.java index 8fbbd59a5..95c57d2fe 100644 --- a/src/resonantinduction/contractor/TileEntityEMContractor.java +++ b/src/resonantinduction/contractor/TileEntityEMContractor.java @@ -23,8 +23,8 @@ import resonantinduction.ResonantInduction; import resonantinduction.base.IPacketReceiver; import resonantinduction.base.InventoryUtil; import resonantinduction.base.TileEntityBase; -import resonantinduction.base.Vector3; import resonantinduction.tesla.TileEntityTesla; +import universalelectricity.core.vector.Vector3; import com.google.common.io.ByteArrayDataInput; diff --git a/src/resonantinduction/entangler/ItemCoordLink.java b/src/resonantinduction/entangler/ItemCoordLink.java index 0b0cb5b58..ab2c99bb8 100644 --- a/src/resonantinduction/entangler/ItemCoordLink.java +++ b/src/resonantinduction/entangler/ItemCoordLink.java @@ -9,7 +9,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import resonantinduction.base.ItemBase; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/entangler/ItemLinker.java b/src/resonantinduction/entangler/ItemLinker.java index b61bb3ce9..85541e62c 100644 --- a/src/resonantinduction/entangler/ItemLinker.java +++ b/src/resonantinduction/entangler/ItemLinker.java @@ -6,7 +6,7 @@ package resonantinduction.entangler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; /** * @author Calclavia diff --git a/src/resonantinduction/entangler/ItemQuantumEntangler.java b/src/resonantinduction/entangler/ItemQuantumEntangler.java index 4648c0995..6099b135f 100644 --- a/src/resonantinduction/entangler/ItemQuantumEntangler.java +++ b/src/resonantinduction/entangler/ItemQuantumEntangler.java @@ -4,7 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; /** * diff --git a/src/resonantinduction/fx/FXElectricBolt.java b/src/resonantinduction/fx/FXElectricBolt.java index 5141c484f..30263c1ed 100644 --- a/src/resonantinduction/fx/FXElectricBolt.java +++ b/src/resonantinduction/fx/FXElectricBolt.java @@ -27,7 +27,7 @@ import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; -import resonantinduction.base.Vector3; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -425,7 +425,7 @@ public class FXElectricBolt extends EntityFX Vector3 prevDiffNorm = this.prev.difference.clone().normalize(); Vector3 diffNorm = this.difference.clone().normalize(); this.prevDiff = diffNorm.translate(prevDiffNorm).normalize(); - this.sinPrev = Math.sin(diffNorm.getAnglePreNorm(prevDiffNorm.scale(-1)) / 2); + this.sinPrev = Math.sin(diffNorm.anglePreNorm(prevDiffNorm.scale(-1)) / 2); } else { @@ -438,7 +438,7 @@ public class FXElectricBolt extends EntityFX Vector3 nextDiffNorm = this.next.difference.clone().normalize(); Vector3 diffNorm = this.difference.clone().normalize(); this.nextDiff = diffNorm.translate(nextDiffNorm).normalize(); - this.sinNext = Math.sin(diffNorm.getAnglePreNorm(nextDiffNorm.scale(-1)) / 2); + this.sinNext = Math.sin(diffNorm.anglePreNorm(nextDiffNorm.scale(-1)) / 2); } else { diff --git a/src/resonantinduction/render/RenderBattery.java b/src/resonantinduction/render/RenderBattery.java index 4ce06034b..1d93e829e 100644 --- a/src/resonantinduction/render/RenderBattery.java +++ b/src/resonantinduction/render/RenderBattery.java @@ -22,9 +22,9 @@ import net.minecraftforge.common.ForgeDirection; import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; -import resonantinduction.base.Vector3; import resonantinduction.battery.TileEntityBattery; import resonantinduction.model.ModelBattery; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -86,13 +86,13 @@ public class RenderBattery extends TileEntitySpecialRenderer for (int slot = 0; slot < 4; slot++) { - Vector3 sideVec = new Vector3(t).getFromSide(correctSide(direction)); - - if(!t.worldObj.isAirBlock((int)sideVec.x, (int)sideVec.y, (int)sideVec.z)) + Vector3 sideVec = new Vector3(t).modifyPositionFromSide(correctSide(direction)); + + if (!t.worldObj.isAirBlock((int) sideVec.x, (int) sideVec.y, (int) sideVec.z)) { continue; } - + GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5f, (float) y + 0.7f, (float) z + 0.5f); @@ -140,10 +140,10 @@ public class RenderBattery extends TileEntitySpecialRenderer } GL11.glScalef(0.5f, 0.5f, 0.5f); - + this.renderItemSimple(this.fakeBattery); GL11.glPopMatrix(); - + if (--renderAmount <= 0) { return; @@ -151,10 +151,10 @@ public class RenderBattery extends TileEntitySpecialRenderer } } } - + private ForgeDirection correctSide(ForgeDirection side) { - switch(side) + switch (side) { case NORTH: return ForgeDirection.WEST; diff --git a/src/resonantinduction/tesla/BlockTesla.java b/src/resonantinduction/tesla/BlockTesla.java index 78301fe47..53df070a3 100644 --- a/src/resonantinduction/tesla/BlockTesla.java +++ b/src/resonantinduction/tesla/BlockTesla.java @@ -11,9 +11,9 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; -import resonantinduction.base.Vector3; import resonantinduction.entangler.ItemCoordLink; import resonantinduction.render.BlockRenderingHandler; +import universalelectricity.core.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 32edac23e..d7e46272f 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -25,8 +25,8 @@ import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; import resonantinduction.base.IPacketReceiver; import resonantinduction.base.TileEntityBase; -import resonantinduction.base.Vector3; import resonantinduction.battery.TileEntityBattery; +import universalelectricity.core.vector.Vector3; import com.google.common.io.ByteArrayDataInput;