From 5781a9c01f82e0d23a9e1766a74bb4eae24138d7 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Wed, 7 May 2014 20:29:11 +0300 Subject: [PATCH 01/20] In library set player even when shift clicked Was quite an annoying small bug. Was trying to put some blueprints in blueprint library, but they well wouldn't simply appear in the list. Came out the uploading and downloading player is only set when the slot is clicked. --- .../gui/ContainerBlueprintLibrary.java | 5 ++- .../core/gui/slots/SlotBlueprintLibrary.java | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java diff --git a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java index 95876762..5c7fda76 100644 --- a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java @@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack; import buildcraft.builders.TileBlueprintLibrary; import buildcraft.core.gui.BuildCraftContainer; +import buildcraft.core.gui.slots.SlotBlueprintLibrary; import buildcraft.core.gui.slots.SlotOutput; public class ContainerBlueprintLibrary extends BuildCraftContainer { @@ -30,10 +31,10 @@ public class ContainerBlueprintLibrary extends BuildCraftContainer { this.playerInventory = player.inventory; this.library = library; - addSlotToContainer(new Slot(library, 0, 211, 61)); + addSlotToContainer(new SlotBlueprintLibrary(library, player, 0, 211, 61)); addSlotToContainer(new SlotOutput(library, 1, 167, 61)); - addSlotToContainer(new Slot(library, 2, 167, 79)); + addSlotToContainer(new SlotBlueprintLibrary(library, player, 2, 167, 79)); addSlotToContainer(new SlotOutput(library, 3, 211, 79)); // Player inventory diff --git a/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java new file mode 100644 index 00000000..1199f1bc --- /dev/null +++ b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core.gui.slots; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; + +import buildcraft.builders.TileBlueprintLibrary; + +public class SlotBlueprintLibrary extends SlotBase { + private TileBlueprintLibrary library; + private EntityPlayer player; + private int slot; + + public SlotBlueprintLibrary(IInventory iinventory, EntityPlayer player, int slotIndex, int posX, int posY) { + super(iinventory, slotIndex, posX, posY); + this.library = (TileBlueprintLibrary) iinventory; + this.slot = slotIndex; + this.player = player; + } + + public void onSlotChanged() { + if (slot == 0) { + library.uploadingPlayer = player; + } else if (slot == 2) { + library.downloadingPlayer = player; + } + + this.inventory.markDirty(); + } +} \ No newline at end of file From f63a16bd95e80259fbda5d8ceb793d339daa3a0a Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Wed, 7 May 2014 19:58:21 +0200 Subject: [PATCH 02/20] removed useless override to slotClick --- .../gui/ContainerBlueprintLibrary.java | 18 ------------------ .../core/gui/slots/SlotBlueprintLibrary.java | 7 +++++++ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java index 5c7fda76..d058617e 100644 --- a/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/ContainerBlueprintLibrary.java @@ -12,7 +12,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; import buildcraft.builders.TileBlueprintLibrary; import buildcraft.core.gui.BuildCraftContainer; @@ -49,23 +48,6 @@ public class ContainerBlueprintLibrary extends BuildCraftContainer { } } - @Override - public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPlayer player) { - // When downloading or uploading a blueprint, the server needs to know - // who requested it. The way to do it so far is by recording the last - // player that clicks on the slots. To be improved if the method is - // not robust enough (e.g. what if the player is not logged anymore? - // is that robust against race conditions? etc.) - - if (slotNum == 0) { - library.uploadingPlayer = player; - } else if (slotNum == 2) { - library.downloadingPlayer = player; - } - - return super.slotClick(slotNum, mouseButton, modifier, player); - } - @Override public void detectAndSendChanges() { super.detectAndSendChanges(); diff --git a/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java index 1199f1bc..3ccfc902 100644 --- a/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java +++ b/common/buildcraft/core/gui/slots/SlotBlueprintLibrary.java @@ -25,7 +25,14 @@ public class SlotBlueprintLibrary extends SlotBase { this.player = player; } + @Override public void onSlotChanged() { + // When downloading or uploading a blueprint, the server needs to know + // who requested it. The way to do it so far is by recording the last + // player that clicks on the slots. To be improved if the method is + // not robust enough (e.g. what if the player is not logged anymore? + // is that robust against race conditions? etc.) + if (slot == 0) { library.uploadingPlayer = player; } else if (slot == 2) { From 4585c15e83f6904f291cdb617ddd35f81a7a1f02 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Wed, 7 May 2014 20:07:42 +0200 Subject: [PATCH 03/20] added double plant to the list of ignored blocks, close #1729 --- common/buildcraft/BuildCraftBuilders.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index c21aa51a..284e0eba 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -247,6 +247,7 @@ public class BuildCraftBuilders extends BuildCraftMod { SchematicRegistry.registerSchematicBlock(Blocks.snow, SchematicIgnore.class); SchematicRegistry.registerSchematicBlock(Blocks.tallgrass, SchematicIgnore.class); + SchematicRegistry.registerSchematicBlock(Blocks.double_plant, SchematicIgnore.class); SchematicRegistry.registerSchematicBlock(Blocks.ice, SchematicIgnore.class); SchematicRegistry.registerSchematicBlock(Blocks.piston_head, SchematicIgnore.class); From 646c694f802d88355b324a12b7822d64756b90c4 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Wed, 7 May 2014 20:11:19 +0200 Subject: [PATCH 04/20] removed redundant handling of custom items, for #1730 --- common/buildcraft/transport/TravelingItem.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/common/buildcraft/transport/TravelingItem.java b/common/buildcraft/transport/TravelingItem.java index 0847b0d1..92ba360f 100644 --- a/common/buildcraft/transport/TravelingItem.java +++ b/common/buildcraft/transport/TravelingItem.java @@ -13,7 +13,6 @@ import java.util.Map; import com.google.common.collect.MapMaker; -import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -217,13 +216,6 @@ public class TravelingItem { ItemStack stack = getItemStack(); EntityItem entity = new EntityItem(container.getWorldObj(), xCoord, yCoord, zCoord, getItemStack()); - if (stack.getItem().hasCustomEntity(stack)) { - Entity e = stack.getItem().createEntity(container.getWorldObj(), entity, stack); - if (e instanceof EntityItem) { - entity = (EntityItem) e; - } - } - entity.lifespan = BuildCraftCore.itemLifespan; entity.delayBeforeCanPickup = 10; From 821ab3a9c3177efb3915564791d7c03e136746ac Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Wed, 7 May 2014 21:35:13 +0300 Subject: [PATCH 05/20] Enable/disable delete button when selected or not --- .../builders/gui/GuiBlueprintLibrary.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/buildcraft/builders/gui/GuiBlueprintLibrary.java b/common/buildcraft/builders/gui/GuiBlueprintLibrary.java index 61be75e8..d3625af6 100644 --- a/common/buildcraft/builders/gui/GuiBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/GuiBlueprintLibrary.java @@ -59,6 +59,8 @@ public class GuiBlueprintLibrary extends GuiBuildCraft { deleteButton = new GuiButton(2, j + 158, k + 114, 25, 20, StringUtils.localize("gui.del")); buttonList.add(deleteButton); + + checkDelete(); } @Override @@ -141,5 +143,16 @@ public class GuiBlueprintLibrary extends GuiBuildCraft { } } } + + checkDelete(); + } + + protected void checkDelete() { + if (library.selected != -1) { + deleteButton.enabled = true; + } + else { + deleteButton.enabled = false; + } } } From 990e07f8cda72a42330b98175e530e52e8591131 Mon Sep 17 00:00:00 2001 From: ninehous Date: Wed, 7 May 2014 23:09:54 +0300 Subject: [PATCH 06/20] Update GuiBlueprintLibrary.java Fixed a formatting error. --- common/buildcraft/builders/gui/GuiBlueprintLibrary.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/builders/gui/GuiBlueprintLibrary.java b/common/buildcraft/builders/gui/GuiBlueprintLibrary.java index d3625af6..2ba7cd1f 100644 --- a/common/buildcraft/builders/gui/GuiBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/GuiBlueprintLibrary.java @@ -150,8 +150,8 @@ public class GuiBlueprintLibrary extends GuiBuildCraft { protected void checkDelete() { if (library.selected != -1) { deleteButton.enabled = true; - } - else { + + } else { deleteButton.enabled = false; } } From 2f7ae5a3f2df30deccd4c44b01957af239e3c3ea Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Thu, 8 May 2014 08:16:01 +0300 Subject: [PATCH 07/20] Disable/enable page buttons in blueprint library --- .../builders/TileBlueprintLibrary.java | 2 +- .../builders/gui/GuiBlueprintLibrary.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/builders/TileBlueprintLibrary.java b/common/buildcraft/builders/TileBlueprintLibrary.java index 1bae7fbb..1279cf48 100644 --- a/common/buildcraft/builders/TileBlueprintLibrary.java +++ b/common/buildcraft/builders/TileBlueprintLibrary.java @@ -51,7 +51,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory { public EntityPlayer uploadingPlayer = null; public EntityPlayer downloadingPlayer = null; - private int pageId = 0; + public int pageId = 0; public TileBlueprintLibrary() { diff --git a/common/buildcraft/builders/gui/GuiBlueprintLibrary.java b/common/buildcraft/builders/gui/GuiBlueprintLibrary.java index 2ba7cd1f..d39d0e34 100644 --- a/common/buildcraft/builders/gui/GuiBlueprintLibrary.java +++ b/common/buildcraft/builders/gui/GuiBlueprintLibrary.java @@ -61,6 +61,7 @@ public class GuiBlueprintLibrary extends GuiBuildCraft { buttonList.add(deleteButton); checkDelete(); + checkPages(); } @Override @@ -145,14 +146,28 @@ public class GuiBlueprintLibrary extends GuiBuildCraft { } checkDelete(); + checkPages(); } protected void checkDelete() { if (library.selected != -1) { deleteButton.enabled = true; - } else { deleteButton.enabled = false; } } + + protected void checkPages() { + if (library.pageId != 0) { + prevPageButton.enabled = true; + } else { + prevPageButton.enabled = false; + } + + if (library.pageId < BuildCraftBuilders.clientDB.getPageNumber() - 1) { + nextPageButton.enabled = true; + } else { + nextPageButton.enabled = false; + } + } } From bfc6f0250533eb223ee26b16ad30576a63910290 Mon Sep 17 00:00:00 2001 From: Prototik Date: Thu, 8 May 2014 13:19:25 +0800 Subject: [PATCH 08/20] Fix server crash while drop items in stripes pipe too --- common/buildcraft/transport/pipes/PipeItemsStripes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/transport/pipes/PipeItemsStripes.java b/common/buildcraft/transport/pipes/PipeItemsStripes.java index a0698e18..0b53555b 100755 --- a/common/buildcraft/transport/pipes/PipeItemsStripes.java +++ b/common/buildcraft/transport/pipes/PipeItemsStripes.java @@ -128,9 +128,9 @@ public class PipeItemsStripes extends Pipe { entityArrow.setPosition(p.x + 0.5d, p.y + 0.5d, p.z + 0.5d); entityArrow.setDamage(3); entityArrow.setKnockbackStrength(1); - entityArrow.setVelocity(direction.offsetX * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D, - direction.offsetY * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D, - direction.offsetZ * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D); + entityArrow.motionX = direction.offsetX * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D; + entityArrow.motionY = direction.offsetY * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D; + entityArrow.motionZ = direction.offsetZ * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D; getWorld().spawnEntityInWorld(entityArrow); } else if ((stack.getItem() == Items.potionitem && ItemPotion.isSplash(stack.getItemDamage())) || stack.getItem() == Items.egg From fe2a5e6559a7e959efaadeb71c0dd10a5bbc07c8 Mon Sep 17 00:00:00 2001 From: Prototik Date: Thu, 8 May 2014 18:52:28 +0800 Subject: [PATCH 09/20] Fix read/write nbt in builders --- common/buildcraft/builders/TileAbstractBuilder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/builders/TileAbstractBuilder.java b/common/buildcraft/builders/TileAbstractBuilder.java index 6b642885..ac865b8f 100755 --- a/common/buildcraft/builders/TileAbstractBuilder.java +++ b/common/buildcraft/builders/TileAbstractBuilder.java @@ -139,14 +139,15 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - mjStored = nbttagcompound.getDouble("mjStored"); + nbttagcompound.setDouble("mjStored", mjStored); } @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - nbttagcompound.setDouble("mjStored", mjStored); + mjStored = nbttagcompound.getDouble("mjStored"); + mjPrev = mjStored; mjUnchangedCycles = 0; } From 246375c5ac7b09f72d36694999bf14a2fca431da Mon Sep 17 00:00:00 2001 From: Prototik Date: Thu, 8 May 2014 17:56:15 +0800 Subject: [PATCH 10/20] Update MjAPI (implementation and docs) --- api/buildcraft/api/mj/MjAPI.java | 141 ++++++++++++++------- api/buildcraft/api/mj/MjBattery.java | 17 ++- api/buildcraft/api/power/PowerHandler.java | 3 +- 3 files changed, 108 insertions(+), 53 deletions(-) diff --git a/api/buildcraft/api/mj/MjAPI.java b/api/buildcraft/api/mj/MjAPI.java index b9314d74..11aa4114 100755 --- a/api/buildcraft/api/mj/MjAPI.java +++ b/api/buildcraft/api/mj/MjAPI.java @@ -14,39 +14,71 @@ import java.util.HashMap; import java.util.Map; import buildcraft.api.core.JavaTools; -import buildcraft.api.power.PowerHandler; public final class MjAPI { - - static Map MjBatteries = new HashMap(); + private static Map MjBatteries = new HashMap(); private enum BatteryKind { Value, Container } private static class BatteryField { - public Field field; - public MjBattery battery; - public BatteryKind kind; + Field field; + MjBattery battery; + BatteryKind kind; + } + + public interface IBatteryProvider { + BatteryObject getMjBattery(); } public static class BatteryObject { - Field f; - Object o; - MjBattery b; + private Field f; + private Object o; + private MjBattery b; + /** + * @return Current energy requirement for keeping machine state + */ public double getEnergyRequested() { try { double contained = f.getDouble(o); + double max = b.maxCapacity(); + return Math.max(Math.min(max - contained, b.maxReceivedPerCycle()), b.minimumConsumption()); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return 0; + } - double left = contained + b.maxReceivedPerCycle() > b - .maxCapacity() ? b.maxCapacity() - contained : b - .maxReceivedPerCycle(); + /** + * Add energy to this battery + * + * @param mj Energy amount + * @return Used energy + */ + public double addEnergy(double mj) { + return addEnergy(mj, false); + } - if (left > 0) { - return left; - } else { - return b.minimumConsumption(); + /** + * Add energy to this battery + * + * @param mj Energy amount + * @param ignoreCycleLimit Force add all energy even if "maxReceivedPerCycle" limit is reached + * @return Used energy + */ + public double addEnergy(double mj, boolean ignoreCycleLimit) { + try { + double contained = f.getDouble(o); + double maxAccepted = b.maxCapacity() - contained + b.minimumConsumption(); + if (!ignoreCycleLimit && maxAccepted > b.maxReceivedPerCycle()) { + maxAccepted = b.maxReceivedPerCycle(); + } + double used = Math.min(maxAccepted, mj); + if (used > 0) { + f.setDouble(o, Math.min(contained + used, b.maxCapacity())); + return used; } } catch (IllegalAccessException e) { e.printStackTrace(); @@ -55,23 +87,9 @@ public final class MjAPI { return 0; } - public double addEnergy(double watts) { - try { - double e = f.getDouble(o); - double max = b.maxCapacity(); - - double used = e + watts <= max ? watts : max - e; - - f.setDouble(o, e + used); - - return used; - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - return 0; - } - + /** + * @return Current stored energy amount in this battery + */ public double getEnergyStored() { try { return f.getDouble(o); @@ -81,26 +99,56 @@ public final class MjAPI { } } - public void setEnergyStored(double watts) { + /** + * Set current stored energy amount. + * Doesn't use it for your machines! Decrease your battery field directly. + * + * @param mj New energy amount + */ + public void setEnergyStored(double mj) { try { - f.setDouble(o, watts); + f.setDouble(o, mj); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } + /** + * Can be overrided via {@link #reconfigure(double, double, double)} + * + * @return Maximal energy amount for this battery. + */ public double maxCapacity() { return b.maxCapacity(); } + /** + * Can be overrided via {@link #reconfigure(double, double, double)} + * + * @return Minimal energy amount for keep your machine in active state + */ public double minimumConsumption() { return b.minimumConsumption(); } + /** + * Can be overrided via {@link #reconfigure(double, double, double)} + * + * @return Maximal energy received per one tick + */ public double maxReceivedPerCycle() { return b.maxReceivedPerCycle(); } + /** + * Allow to dynamically reconfigure your battery. + * Usually it's not very good change battery parameters for already present machines, but if you want... + * + * @param maxCapacity {@link #maxCapacity()} + * @param maxReceivedPerCycle {@link #maxReceivedPerCycle()} + * @param minimumConsumption {@link #minimumConsumption()} + * @return Current battery object instance + */ public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) { b = new MjBattery() { @Override @@ -138,11 +186,14 @@ public final class MjAPI { return null; } - if (o.getClass() == PowerHandler.class) { - return ((PowerHandler) o).getMjBattery(); + if (o instanceof IBatteryProvider) { + BatteryObject battery = ((IBatteryProvider) o).getMjBattery(); + if (battery != null) { + return battery; + } } - BatteryField f = getMjBattery(o.getClass()); + BatteryField f = getMjBatteryField(o.getClass()); if (f == null) { return null; @@ -151,7 +202,6 @@ public final class MjAPI { obj.o = o; obj.f = f.field; obj.b = f.battery; - return obj; } else { try { @@ -163,14 +213,15 @@ public final class MjAPI { } } - private static BatteryField getMjBattery(Class c) { - if (!MjBatteries.containsKey(c)) { + private static BatteryField getMjBatteryField(Class c) { + BatteryField bField = MjBatteries.get(c); + if (bField == null) { for (Field f : JavaTools.getAllFields(c)) { MjBattery battery = f.getAnnotation(MjBattery.class); if (battery != null) { f.setAccessible(true); - BatteryField bField = new BatteryField(); + bField = new BatteryField(); bField.field = f; bField.battery = battery; @@ -188,13 +239,9 @@ public final class MjAPI { return bField; } } - MjBatteries.put(c, null); - - return null; - } else { - return MjBatteries.get(c); } + return bField; } } diff --git a/api/buildcraft/api/mj/MjBattery.java b/api/buildcraft/api/mj/MjBattery.java index 1c0ad5c4..af4e97c7 100755 --- a/api/buildcraft/api/mj/MjBattery.java +++ b/api/buildcraft/api/mj/MjBattery.java @@ -17,12 +17,12 @@ import java.lang.annotation.Target; /** * This annotation is used for tiles that need to interface with BuildCraft * energy framework, a.k.a MinecraftJoule or MJ. In order to receive power, - * tiles, need to declare a *public* double field, with the annotation + * tiles, need to declare a double field, with the annotation * MjBattery. BuildCraft machines able to provide power will then connect to - * these tiles, and feed energy up to max capacity. It's the responsibilty + * these tiles, and feed energy up to max capacity. It's the responsibility * of the implementer to manually decrease the value of the energy, as he * simulates energy consumption. On each cycle, per power input, machines can - * receive up to "maxReceivedPerCyle" units of energy. As an optional behavior, + * receive up to "maxReceivedPerCycle" units of energy. As an optional behavior, * the system can have a minimum amount of energy consumed even if the system * is at max capacity, modelized by the "minimumConsumption" value. * @@ -34,11 +34,18 @@ import java.lang.annotation.Target; @Target(ElementType.FIELD) @Inherited public @interface MjBattery { - + /** + * @return Max energy capacity of battery + */ double maxCapacity() default 100.0; + /** + * @return Max energy received per one tick + */ double maxReceivedPerCycle() default 10.0; + /** + * @return Minimal energy for keep machine is active + */ double minimumConsumption() default 0.1; - } \ No newline at end of file diff --git a/api/buildcraft/api/power/PowerHandler.java b/api/buildcraft/api/power/PowerHandler.java index f1d63562..b10dfa55 100644 --- a/api/buildcraft/api/power/PowerHandler.java +++ b/api/buildcraft/api/power/PowerHandler.java @@ -32,7 +32,7 @@ import buildcraft.api.mj.MjBattery; * @see IPowerReceptor * @see IPowerEmitter */ -public final class PowerHandler { +public final class PowerHandler implements MjAPI.IBatteryProvider { public static enum Type { @@ -181,6 +181,7 @@ public final class PowerHandler { return battery.getEnergyStored(); } + @Override public MjAPI.BatteryObject getMjBattery() { return battery; } From 31ac41aae61c0180bd816a7b4b8e3e8941842f81 Mon Sep 17 00:00:00 2001 From: Prototik Date: Thu, 8 May 2014 20:22:30 +0800 Subject: [PATCH 11/20] Fix comparator requirements for builder --- common/buildcraft/BuildCraftBuilders.java | 8 ++++---- .../builders/schematics/SchematicRedstoneDiode.java | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index 284e0eba..c1637741 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -312,10 +312,10 @@ public class BuildCraftBuilders extends BuildCraftMod { SchematicRegistry.registerSchematicBlock(Blocks.melon_stem, SchematicCustomStack.class, new ItemStack(Items.melon_seeds)); SchematicRegistry.registerSchematicBlock(Blocks.glowstone, SchematicCustomStack.class, new ItemStack(Blocks.glowstone)); - SchematicRegistry.registerSchematicBlock(Blocks.powered_repeater, SchematicRedstoneDiode.class); - SchematicRegistry.registerSchematicBlock(Blocks.unpowered_repeater, SchematicRedstoneDiode.class); - SchematicRegistry.registerSchematicBlock(Blocks.powered_comparator, SchematicRedstoneDiode.class); - SchematicRegistry.registerSchematicBlock(Blocks.unpowered_comparator, SchematicRedstoneDiode.class); + SchematicRegistry.registerSchematicBlock(Blocks.powered_repeater, SchematicRedstoneDiode.class, Items.repeater); + SchematicRegistry.registerSchematicBlock(Blocks.unpowered_repeater, SchematicRedstoneDiode.class, Items.repeater); + SchematicRegistry.registerSchematicBlock(Blocks.powered_comparator, SchematicRedstoneDiode.class, Items.comparator); + SchematicRegistry.registerSchematicBlock(Blocks.unpowered_comparator, SchematicRedstoneDiode.class, Items.comparator); SchematicRegistry.registerSchematicBlock(Blocks.water, SchematicFluid.class, new ItemStack(Items.water_bucket)); SchematicRegistry.registerSchematicBlock(Blocks.flowing_water, SchematicFluid.class, new ItemStack(Items.water_bucket)); diff --git a/common/buildcraft/builders/schematics/SchematicRedstoneDiode.java b/common/buildcraft/builders/schematics/SchematicRedstoneDiode.java index 9d3ebdd1..cf989f89 100644 --- a/common/buildcraft/builders/schematics/SchematicRedstoneDiode.java +++ b/common/buildcraft/builders/schematics/SchematicRedstoneDiode.java @@ -10,17 +10,22 @@ package buildcraft.builders.schematics; import java.util.LinkedList; -import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.IBuilderContext; import buildcraft.api.blueprints.SchematicBlock; public class SchematicRedstoneDiode extends SchematicBlock { + private Item baseItem; + + public SchematicRedstoneDiode(Item baseItem) { + this.baseItem = baseItem; + } @Override public void writeRequirementsToBuilder(IBuilderContext context, LinkedList requirements) { - requirements.add(new ItemStack(Items.repeater)); + requirements.add(new ItemStack(baseItem)); } @Override From 1c17929fa5206450d080e9f2ad72ca759ddb3f5b Mon Sep 17 00:00:00 2001 From: Prototik Date: Thu, 8 May 2014 22:22:26 +0800 Subject: [PATCH 12/20] Drop blueprint if no space available in builder --- common/buildcraft/builders/TileBuilder.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 1e3da21b..ad7c492b 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -40,6 +40,7 @@ import buildcraft.core.blueprints.BptBuilderBase; import buildcraft.core.blueprints.BptBuilderBlueprint; import buildcraft.core.blueprints.BptBuilderTemplate; import buildcraft.core.blueprints.BptContext; +import buildcraft.core.inventory.InvUtils; import buildcraft.core.network.RPC; import buildcraft.core.network.RPCHandler; import buildcraft.core.network.RPCSide; @@ -397,12 +398,17 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { } if (done) { + boolean dropBlueprint = true; for (int i = 1; i < items.length; ++i) { if (items[i] == null) { items[i] = items[0]; + dropBlueprint = false; break; } } + if (dropBlueprint) { + InvUtils.dropItems(getWorld(), items[0], xCoord, yCoord, zCoord); + } items[0] = null; box.reset(); @@ -732,4 +738,4 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { } } -} \ No newline at end of file +} From 27d095a00c45fa864d1f471a1265f082fcdea4b6 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Thu, 8 May 2014 17:50:31 +0300 Subject: [PATCH 13/20] Fix shift-clicking in architect table, fix #1740 --- common/buildcraft/builders/GuiHandler.java | 4 +-- .../builders/gui/ContainerArchitect.java | 23 ++++-------- .../buildcraft/builders/gui/GuiArchitect.java | 7 ++-- .../core/gui/slots/SlotArchitect.java | 35 +++++++++++++++++++ 4 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 common/buildcraft/core/gui/slots/SlotArchitect.java diff --git a/common/buildcraft/builders/GuiHandler.java b/common/buildcraft/builders/GuiHandler.java index 59d3d59d..31b77ba0 100644 --- a/common/buildcraft/builders/GuiHandler.java +++ b/common/buildcraft/builders/GuiHandler.java @@ -43,7 +43,7 @@ public class GuiHandler implements IGuiHandler { if (!(tile instanceof TileArchitect)) { return null; } - return new GuiArchitect(player.inventory, (TileArchitect) tile); + return new GuiArchitect(player, (TileArchitect) tile); case GuiIds.BLUEPRINT_LIBRARY: if (!(tile instanceof TileBlueprintLibrary)) { @@ -91,7 +91,7 @@ public class GuiHandler implements IGuiHandler { if (!(tile instanceof TileArchitect)) { return null; } - return new ContainerArchitect(player.inventory, (TileArchitect) tile); + return new ContainerArchitect(player, (TileArchitect) tile); case GuiIds.BLUEPRINT_LIBRARY: if (!(tile instanceof TileBlueprintLibrary)) { diff --git a/common/buildcraft/builders/gui/ContainerArchitect.java b/common/buildcraft/builders/gui/ContainerArchitect.java index bf115a7f..23682ab5 100644 --- a/common/buildcraft/builders/gui/ContainerArchitect.java +++ b/common/buildcraft/builders/gui/ContainerArchitect.java @@ -12,9 +12,10 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; + import buildcraft.builders.TileArchitect; import buildcraft.core.gui.BuildCraftContainer; +import buildcraft.core.gui.slots.SlotArchitect; import buildcraft.core.gui.slots.SlotOutput; public class ContainerArchitect extends BuildCraftContainer { @@ -23,23 +24,23 @@ public class ContainerArchitect extends BuildCraftContainer { protected TileArchitect architect; protected int computingTime = 0; - public ContainerArchitect(IInventory playerInventory, TileArchitect template) { + public ContainerArchitect(EntityPlayer player, TileArchitect template) { super(template.getSizeInventory()); - this.playerIInventory = playerInventory; + this.playerIInventory = player.inventory; this.architect = template; - addSlotToContainer(new Slot(template, 0, 135, 35)); + addSlotToContainer(new SlotArchitect(template, player, 0, 135, 35)); addSlotToContainer(new SlotOutput(template, 1, 194, 35)); for (int l = 0; l < 3; l++) { for (int k1 = 0; k1 < 9; k1++) { - addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 88 + k1 * 18, 84 + l * 18)); + addSlotToContainer(new Slot(player.inventory, k1 + l * 9 + 9, 88 + k1 * 18, 84 + l * 18)); } } for (int i1 = 0; i1 < 9; i1++) { - addSlotToContainer(new Slot(playerInventory, i1, 88 + i1 * 18, 142)); + addSlotToContainer(new Slot(player.inventory, i1, 88 + i1 * 18, 142)); } } @@ -77,14 +78,4 @@ public class ContainerArchitect extends BuildCraftContainer { public boolean canInteractWith(EntityPlayer entityplayer) { return architect.isUseableByPlayer(entityplayer); } - - @Override - public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPlayer player) { - if (slotNum == 0) { - architect.currentAuthorName = player.getDisplayName(); - } - - return super.slotClick(slotNum, mouseButton, modifier, player); - } - } diff --git a/common/buildcraft/builders/gui/GuiArchitect.java b/common/buildcraft/builders/gui/GuiArchitect.java index 01af297e..a7c93f07 100644 --- a/common/buildcraft/builders/gui/GuiArchitect.java +++ b/common/buildcraft/builders/gui/GuiArchitect.java @@ -13,6 +13,7 @@ import org.lwjgl.opengl.GL11; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.util.ResourceLocation; @@ -45,9 +46,9 @@ public class GuiArchitect extends GuiBuildCraft { private GuiTextField textField; - public GuiArchitect(IInventory playerInventory, TileArchitect architect) { - super(new ContainerArchitect(playerInventory, architect), architect, TEXTURE); - this.playerInventory = playerInventory; + public GuiArchitect(EntityPlayer player, TileArchitect architect) { + super(new ContainerArchitect(player, architect), architect, TEXTURE); + this.playerInventory = player.inventory; this.architect = architect; xSize = 256; ySize = 166; diff --git a/common/buildcraft/core/gui/slots/SlotArchitect.java b/common/buildcraft/core/gui/slots/SlotArchitect.java new file mode 100644 index 00000000..e955d322 --- /dev/null +++ b/common/buildcraft/core/gui/slots/SlotArchitect.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core.gui.slots; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import buildcraft.builders.TileArchitect; + +public class SlotArchitect extends SlotBase { + private TileArchitect architect; + private EntityPlayer player; + private int slot; + + public SlotArchitect(IInventory iinventory, EntityPlayer player, int slotIndex, int posX, int posY) { + super(iinventory, slotIndex, posX, posY); + this.architect = (TileArchitect) iinventory; + this.slot = slotIndex; + this.player = player; + } + + @Override + public void onSlotChanged() { + if (slot == 0) { + architect.currentAuthorName = player.getDisplayName(); + } + + this.inventory.markDirty(); + } +} \ No newline at end of file From 7ca9e6987d360e5475182d667606f4174416607d Mon Sep 17 00:00:00 2001 From: Prototik Date: Thu, 8 May 2014 23:54:02 +0800 Subject: [PATCH 14/20] Draw only half of indicator for AND gates when not all triggers active --- .../transport/gui/GuiGateInterface.java | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/common/buildcraft/transport/gui/GuiGateInterface.java b/common/buildcraft/transport/gui/GuiGateInterface.java index d6584468..973df076 100644 --- a/common/buildcraft/transport/gui/GuiGateInterface.java +++ b/common/buildcraft/transport/gui/GuiGateInterface.java @@ -29,6 +29,7 @@ import buildcraft.core.gui.GuiAdvancedInterface; import buildcraft.core.triggers.BCAction; import buildcraft.core.utils.StringUtils; import buildcraft.transport.Pipe; +import buildcraft.transport.gates.GateDefinition; public class GuiGateInterface extends GuiAdvancedInterface { @@ -36,6 +37,8 @@ public class GuiGateInterface extends GuiAdvancedInterface { private final ContainerGateInterface container; private final Pipe pipe; private int numSlots; + private TriggerSlot[] triggerSlots; + private TriggerParameterSlot[] triggerParameterSlots; class TriggerSlot extends AdvancedSlot { @@ -189,20 +192,27 @@ public class GuiGateInterface extends GuiAdvancedInterface { if (numSlots == 1) { slots = new AdvancedSlot[2]; - slots[0] = new TriggerSlot(62, 26, pipe, 0); + triggerSlots = new TriggerSlot[1]; + triggerParameterSlots = new TriggerParameterSlot[0]; + + slots[0] = triggerSlots[0] = new TriggerSlot(62, 26, pipe, 0); slots[1] = new ActionSlot(98, 26, pipe, 0); } else if (numSlots == 2) { slots = new AdvancedSlot[4]; + triggerSlots = new TriggerSlot[2]; + triggerParameterSlots = new TriggerParameterSlot[0]; - slots[0] = new TriggerSlot(62, 26, pipe, 0); - slots[1] = new TriggerSlot(62, 44, pipe, 1); + slots[0] = triggerSlots[0] = new TriggerSlot(62, 26, pipe, 0); + slots[1] = triggerSlots[1] = new TriggerSlot(62, 44, pipe, 1); slots[2] = new ActionSlot(98, 26, pipe, 0); slots[3] = new ActionSlot(98, 44, pipe, 1); } else if (numSlots == 4) { slots = new AdvancedSlot[12]; + triggerSlots = new TriggerSlot[4]; + triggerParameterSlots = new TriggerParameterSlot[4]; for (int k = 0; k < 4; ++k) { - slots[position] = new TriggerSlot(53, 26 + 18 * k, pipe, position); + slots[position] = triggerSlots[position] = new TriggerSlot(53, 26 + 18 * k, pipe, position); position++; } @@ -212,17 +222,19 @@ public class GuiGateInterface extends GuiAdvancedInterface { } for (int k = 0; k < 4; ++k) { - slots[position] = new TriggerParameterSlot(71, 26 + 18 * k, pipe, position - 8); + slots[position] = triggerParameterSlots[position - 8] = new TriggerParameterSlot(71, 26 + 18 * k, pipe, position - 8); position++; } } else if (numSlots == 8) { slots = new AdvancedSlot[24]; + triggerSlots = new TriggerSlot[8]; + triggerParameterSlots = new TriggerParameterSlot[8]; for (int k = 0; k < 4; ++k) { - slots[position] = new TriggerSlot(8, 26 + 18 * k, pipe, position); + slots[position] = triggerSlots[position] = new TriggerSlot(8, 26 + 18 * k, pipe, position); position++; - slots[position] = new TriggerSlot(98, 26 + 18 * k, pipe, position); + slots[position] = triggerSlots[position] = new TriggerSlot(98, 26 + 18 * k, pipe, position); position++; } @@ -234,9 +246,9 @@ public class GuiGateInterface extends GuiAdvancedInterface { } for (int k = 0; k < 4; ++k) { - slots[position] = new TriggerParameterSlot(26, 26 + 18 * k, pipe, position - 16); + slots[position] = triggerParameterSlots[position - 16] = new TriggerParameterSlot(26, 26 + 18 * k, pipe, position - 16); position++; - slots[position] = new TriggerParameterSlot(116, 26 + 18 * k, pipe, position - 16); + slots[position] = triggerParameterSlots[position - 16] = new TriggerParameterSlot(116, 26 + 18 * k, pipe, position - 16); position++; } } @@ -273,13 +285,14 @@ public class GuiGateInterface extends GuiAdvancedInterface { if (slot instanceof TriggerSlot) { ITrigger trigger = ((TriggerSlot) slot).getTrigger(); + boolean halfWidth = pipe.gate.logic == GateDefinition.GateLogic.AND && !isAllTriggersActive(); if (pipe.gate.material.hasParameterSlot) { if (container.triggerState[triggerTracker++]) { mc.renderEngine.bindTexture(texture); - drawTexturedModalRect(cornerX + slot.x + 35, cornerY + slot.y + 6, 176, 18, 18, 4); + drawTexturedModalRect(cornerX + slot.x + 35, cornerY + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4); } if (trigger == null || !trigger.hasParameter()) { @@ -290,7 +303,7 @@ public class GuiGateInterface extends GuiAdvancedInterface { } else if (container.triggerState[triggerTracker++]) { mc.renderEngine.bindTexture(texture); - drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y + 6, 176, 18, 18, 4); + drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4); } } else if (slot instanceof TriggerParameterSlot) { TriggerParameterSlot paramSlot = (TriggerParameterSlot) slot; @@ -309,6 +322,18 @@ public class GuiGateInterface extends GuiAdvancedInterface { drawBackgroundSlots(); } + private boolean isAllTriggersActive() { + for (int i = 0; i < triggerSlots.length; i++) { + TriggerSlot slot = triggerSlots[i]; + ITrigger trigger = slot.getTrigger(); + ITriggerParameter parameter = triggerParameterSlots.length > i ? triggerParameterSlots[i].getTriggerParameter() : null; + if (trigger != null && !container.isNearbyTriggerActive(trigger, parameter)) { + return false; + } + } + return true; + } + @Override protected void mouseClicked(int i, int j, int k) { super.mouseClicked(i, j, k); From f91b9033fa281f7eb39a0572635e056a4acca5b0 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Thu, 8 May 2014 21:57:05 +0200 Subject: [PATCH 15/20] Whitelisted to Applied Energetics spacial API all blocks that don't rely on absolute positions. Close #1753 --- common/buildcraft/BuildCraftBuilders.java | 18 ++++++++++++++++++ common/buildcraft/BuildCraftCore.java | 1 - common/buildcraft/BuildCraftEnergy.java | 7 +++++++ common/buildcraft/BuildCraftFactory.java | 20 ++++++++++++++++++++ common/buildcraft/BuildCraftSilicon.java | 12 ++++++++++++ common/buildcraft/BuildCraftTransport.java | 11 +++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index c1637741..db279f1a 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -124,6 +124,8 @@ import buildcraft.core.InterModComms; import buildcraft.core.Version; import buildcraft.core.blueprints.RealBlueprintDeployer; import buildcraft.core.proxy.CoreProxy; +import buildcraft.transport.TileFilteredBuffer; +import buildcraft.transport.TileGenericPipe; @Mod(name = "BuildCraft Builders", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Builders", dependencies = DefaultProps.DEPENDENCY_CORE) public class BuildCraftBuilders extends BuildCraftMod { @@ -529,4 +531,20 @@ public class BuildCraftBuilders extends BuildCraftMod { UrbanistToolsIconProvider.INSTANCE.registerIcons(event.map); } } + + @Mod.EventHandler + public void whiteListAppliedEnergetics(FMLInitializationEvent event) { + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TileMarker.class.getCanonicalName()); + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TileFiller.class.getCanonicalName()); + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TileBuilder.class.getCanonicalName()); + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TileArchitect.class.getCanonicalName()); + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TilePathMarker.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileBlueprintLibrary.class.getCanonicalName()); + } } diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index b2ae22e3..221f8420 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -480,5 +480,4 @@ public class BuildCraftCore extends BuildCraftMod { BuildcraftAchievements = new AchievementPage("Buildcraft", woodenGearAchievement, stoneGearAchievement, ironGearAchievement, goldGearAchievement, diamondGearAchievement, wrenchAchievement, engineAchievement1, engineAchievement2, engineAchievement3, aLotOfCraftingAchievement, straightDownAchievement, chunkDestroyerAchievement, fasterFillingAchievement, timeForSomeLogicAchievement, refineAndRedefineAchievement, tinglyLaserAchievement, architectAchievement, builderAchievement, blueprintAchievement, templateAchievement, libraryAchievement); AchievementPage.registerAchievementPage(BuildcraftAchievements); } - } diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 5743daaa..6ed9a015 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -69,6 +69,7 @@ import buildcraft.energy.SchematicEngine; import buildcraft.energy.TileEnergyConverter; import buildcraft.energy.TileEnergyEmitter; import buildcraft.energy.TileEnergyReceiver; +import buildcraft.energy.TileEngine; import buildcraft.energy.TileEngine.EnergyStage; import buildcraft.energy.triggers.TriggerEngineHeat; import buildcraft.energy.worldgen.BiomeGenOilDesert; @@ -397,4 +398,10 @@ public class BuildCraftEnergy extends BuildCraftMod { public void processIMCRequests(FMLInterModComms.IMCEvent event) { InterModComms.processIMC(event); } + + @Mod.EventHandler + public void whiteListAppliedEnergetics(FMLInitializationEvent event) { + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileEngine.class.getCanonicalName()); + } } diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index b109d843..d60f32ff 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -333,4 +333,24 @@ public class BuildCraftFactory extends BuildCraftMod { FactoryProxyClient.drillHeadTexture = terrainTextures.registerIcon("buildcraft:blockDrillHeadTexture"); } } + + @Mod.EventHandler + public void whiteListAppliedEnergetics(FMLInitializationEvent event) { + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TileQuarry.class.getCanonicalName()); + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TileMiningWell.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileAutoWorkbench.class.getCanonicalName()); + //FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + // TilePump.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileFloodGate.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileTank.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileRefinery.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileHopper.class.getCanonicalName()); + } } diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index c0df346f..45ccf40c 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -192,4 +192,16 @@ public class BuildCraftSilicon extends BuildCraftMod { public void processIMCRequests(FMLInterModComms.IMCEvent event) { InterModComms.processIMC(event); } + + @Mod.EventHandler + public void whiteListAppliedEnergetics(FMLInitializationEvent event) { + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileLaser.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileAssemblyTable.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileAdvancedCraftingTable.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileIntegrationTable.class.getCanonicalName()); + } } diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index b6387554..cda2bd58 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -20,6 +20,7 @@ import net.minecraft.world.World; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @@ -60,6 +61,8 @@ import buildcraft.transport.ItemRobotStation; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTriggerProvider; +import buildcraft.transport.TileFilteredBuffer; +import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TransportProxy; import buildcraft.transport.WireIconProvider; import buildcraft.transport.blueprints.BptItemPipeFilters; @@ -527,4 +530,12 @@ public class BuildCraftTransport extends BuildCraftMod { return res; } + @Mod.EventHandler + public void whiteListAppliedEnergetics(FMLInitializationEvent event) { + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileGenericPipe.class.getCanonicalName()); + FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial", + TileFilteredBuffer.class.getCanonicalName()); + } + } From 6ffd45f3d7a657261a0c6026947bed277223c32d Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Fri, 9 May 2014 00:32:43 +0200 Subject: [PATCH 16/20] fixed style --- common/buildcraft/BuildCraftBuilders.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index db279f1a..c0182450 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -124,8 +124,6 @@ import buildcraft.core.InterModComms; import buildcraft.core.Version; import buildcraft.core.blueprints.RealBlueprintDeployer; import buildcraft.core.proxy.CoreProxy; -import buildcraft.transport.TileFilteredBuffer; -import buildcraft.transport.TileGenericPipe; @Mod(name = "BuildCraft Builders", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Builders", dependencies = DefaultProps.DEPENDENCY_CORE) public class BuildCraftBuilders extends BuildCraftMod { From bed9b59b0e893ad78ddc0609df9d06d7d1cfbb93 Mon Sep 17 00:00:00 2001 From: Prototik Date: Fri, 9 May 2014 13:59:57 +0800 Subject: [PATCH 17/20] Extract battery interface into IBatteryObject --- api/buildcraft/api/core/JavaTools.java | 3 + api/buildcraft/api/mj/IBatteryObject.java | 78 +++++++++++++++++++ api/buildcraft/api/mj/IBatteryProvider.java | 13 ++++ api/buildcraft/api/mj/MjAPI.java | 63 ++++++--------- api/buildcraft/api/mj/MjAPILegacy.java | 8 +- api/buildcraft/api/power/PowerHandler.java | 10 ++- .../energy/TileEnergyConverter.java | 3 +- .../buildcraft/energy/TileEnergyReceiver.java | 4 +- common/buildcraft/energy/TileEngine.java | 4 +- .../transport/PipeTransportPower.java | 6 +- .../transport/gates/GateExpansionPulsar.java | 4 +- 11 files changed, 137 insertions(+), 59 deletions(-) create mode 100644 api/buildcraft/api/mj/IBatteryObject.java create mode 100644 api/buildcraft/api/mj/IBatteryProvider.java diff --git a/api/buildcraft/api/core/JavaTools.java b/api/buildcraft/api/core/JavaTools.java index 4123033a..bf2214b9 100755 --- a/api/buildcraft/api/core/JavaTools.java +++ b/api/buildcraft/api/core/JavaTools.java @@ -16,6 +16,9 @@ import java.util.Arrays; import java.util.List; public class JavaTools { + public static double bounds(double value, double min, double max) { + return Math.max(min, Math.min(value, max)); + } public static T[] concat(T[] first, T[] second) { T[] result = Arrays.copyOf(first, first.length + second.length); diff --git a/api/buildcraft/api/mj/IBatteryObject.java b/api/buildcraft/api/mj/IBatteryObject.java new file mode 100644 index 00000000..b7d27f8e --- /dev/null +++ b/api/buildcraft/api/mj/IBatteryObject.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +public interface IBatteryObject { + /** + * @return Current energy requirement for keeping machine state + */ + double getEnergyRequested(); + + /** + * Add energy to this battery + * + * @param mj Energy amount + * @return Used energy + */ + double addEnergy(double mj); + + /** + * Add energy to this battery + * + * @param mj Energy amount + * @param ignoreCycleLimit Force add all energy even if "maxReceivedPerCycle" limit is reached + * @return Used energy + */ + double addEnergy(double mj, boolean ignoreCycleLimit); + + /** + * @return Current stored energy amount in this battery + */ + double getEnergyStored(); + + /** + * Set current stored energy amount. + * Doesn't use it for your machines! Decrease your battery field directly. + * + * @param mj New energy amount + */ + void setEnergyStored(double mj); + + /** + * Can be overrided via {@link #reconfigure(double, double, double)} + * + * @return Maximal energy amount for this battery. + */ + double maxCapacity(); + + /** + * Can be overrided via {@link #reconfigure(double, double, double)} + * + * @return Minimal energy amount for keep your machine in active state + */ + double minimumConsumption(); + + /** + * Can be overrided via {@link #reconfigure(double, double, double)} + * + * @return Maximal energy received per one tick + */ + double maxReceivedPerCycle(); + + /** + * Allow to dynamically reconfigure your battery. + * Usually it's not very good change battery parameters for already present machines, but if you want... + * + * @param maxCapacity {@link #maxCapacity()} + * @param maxReceivedPerCycle {@link #maxReceivedPerCycle()} + * @param minimumConsumption {@link #minimumConsumption()} + * @return Current battery object instance + */ + IBatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption); +} diff --git a/api/buildcraft/api/mj/IBatteryProvider.java b/api/buildcraft/api/mj/IBatteryProvider.java new file mode 100644 index 00000000..4b4f9d6b --- /dev/null +++ b/api/buildcraft/api/mj/IBatteryProvider.java @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +public interface IBatteryProvider { + IBatteryObject getMjBattery(); +} \ No newline at end of file diff --git a/api/buildcraft/api/mj/MjAPI.java b/api/buildcraft/api/mj/MjAPI.java index 11aa4114..0d5e3ea8 100755 --- a/api/buildcraft/api/mj/MjAPI.java +++ b/api/buildcraft/api/mj/MjAPI.java @@ -28,23 +28,18 @@ public final class MjAPI { BatteryKind kind; } - public interface IBatteryProvider { - BatteryObject getMjBattery(); - } - - public static class BatteryObject { + public static class BatteryObject implements IBatteryObject { private Field f; private Object o; private MjBattery b; /** - * @return Current energy requirement for keeping machine state + * {@inheritDoc} */ + @Override public double getEnergyRequested() { try { - double contained = f.getDouble(o); - double max = b.maxCapacity(); - return Math.max(Math.min(max - contained, b.maxReceivedPerCycle()), b.minimumConsumption()); + return JavaTools.bounds(b.maxCapacity() - f.getDouble(o), b.minimumConsumption(), b.maxReceivedPerCycle()); } catch (IllegalAccessException e) { e.printStackTrace(); } @@ -52,22 +47,17 @@ public final class MjAPI { } /** - * Add energy to this battery - * - * @param mj Energy amount - * @return Used energy + * {@inheritDoc} */ + @Override public double addEnergy(double mj) { return addEnergy(mj, false); } /** - * Add energy to this battery - * - * @param mj Energy amount - * @param ignoreCycleLimit Force add all energy even if "maxReceivedPerCycle" limit is reached - * @return Used energy + * {@inheritDoc} */ + @Override public double addEnergy(double mj, boolean ignoreCycleLimit) { try { double contained = f.getDouble(o); @@ -88,8 +78,9 @@ public final class MjAPI { } /** - * @return Current stored energy amount in this battery + * {@inheritDoc} */ + @Override public double getEnergyStored() { try { return f.getDouble(o); @@ -100,11 +91,9 @@ public final class MjAPI { } /** - * Set current stored energy amount. - * Doesn't use it for your machines! Decrease your battery field directly. - * - * @param mj New energy amount + * {@inheritDoc} */ + @Override public void setEnergyStored(double mj) { try { f.setDouble(o, mj); @@ -114,41 +103,33 @@ public final class MjAPI { } /** - * Can be overrided via {@link #reconfigure(double, double, double)} - * - * @return Maximal energy amount for this battery. + * {@inheritDoc} */ + @Override public double maxCapacity() { return b.maxCapacity(); } /** - * Can be overrided via {@link #reconfigure(double, double, double)} - * - * @return Minimal energy amount for keep your machine in active state + * {@inheritDoc} */ + @Override public double minimumConsumption() { return b.minimumConsumption(); } /** - * Can be overrided via {@link #reconfigure(double, double, double)} - * - * @return Maximal energy received per one tick + * {@inheritDoc} */ + @Override public double maxReceivedPerCycle() { return b.maxReceivedPerCycle(); } /** - * Allow to dynamically reconfigure your battery. - * Usually it's not very good change battery parameters for already present machines, but if you want... - * - * @param maxCapacity {@link #maxCapacity()} - * @param maxReceivedPerCycle {@link #maxReceivedPerCycle()} - * @param minimumConsumption {@link #minimumConsumption()} - * @return Current battery object instance + * {@inheritDoc} */ + @Override public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) { b = new MjBattery() { @Override @@ -181,13 +162,13 @@ public final class MjAPI { private MjAPI() { } - public static BatteryObject getMjBattery(Object o) { + public static IBatteryObject getMjBattery(Object o) { if (o == null) { return null; } if (o instanceof IBatteryProvider) { - BatteryObject battery = ((IBatteryProvider) o).getMjBattery(); + IBatteryObject battery = ((IBatteryProvider) o).getMjBattery(); if (battery != null) { return battery; } diff --git a/api/buildcraft/api/mj/MjAPILegacy.java b/api/buildcraft/api/mj/MjAPILegacy.java index 9d125399..fb0cf05f 100644 --- a/api/buildcraft/api/mj/MjAPILegacy.java +++ b/api/buildcraft/api/mj/MjAPILegacy.java @@ -20,7 +20,7 @@ public class MjAPILegacy implements IPowerReceptor { private final PowerHandler powerHandler; private final World world; - protected MjAPILegacy(World world, MjAPI.BatteryObject battery, PowerHandler.Type type) { + protected MjAPILegacy(World world, IBatteryObject battery, PowerHandler.Type type) { if (battery == null) { throw new NullPointerException(); } @@ -28,7 +28,7 @@ public class MjAPILegacy implements IPowerReceptor { this.powerHandler = new PowerHandler(this, type, battery); } - public static MjAPILegacy from(World world, MjAPI.BatteryObject battery, PowerHandler.Type type) { + public static MjAPILegacy from(World world, IBatteryObject battery, PowerHandler.Type type) { return new MjAPILegacy(world, battery, type); } @@ -40,8 +40,8 @@ public class MjAPILegacy implements IPowerReceptor { return new MjAPILegacy(tileEntity.getWorldObj(), battery(tileEntity), type); } - private static MjAPI.BatteryObject battery(Object object) { - MjAPI.BatteryObject battery = MjAPI.getMjBattery(object); + private static IBatteryObject battery(Object object) { + IBatteryObject battery = MjAPI.getMjBattery(object); if (battery == null) { throw new IllegalArgumentException(String.format("Object %s not using MjAPI, can't create legacy wrapper", object)); } diff --git a/api/buildcraft/api/power/PowerHandler.java b/api/buildcraft/api/power/PowerHandler.java index b10dfa55..f774359c 100644 --- a/api/buildcraft/api/power/PowerHandler.java +++ b/api/buildcraft/api/power/PowerHandler.java @@ -13,6 +13,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; +import buildcraft.api.mj.IBatteryObject; +import buildcraft.api.mj.IBatteryProvider; import buildcraft.api.mj.MjAPI; import buildcraft.api.mj.MjBattery; @@ -32,7 +34,7 @@ import buildcraft.api.mj.MjBattery; * @see IPowerReceptor * @see IPowerEmitter */ -public final class PowerHandler implements MjAPI.IBatteryProvider { +public final class PowerHandler implements IBatteryProvider { public static enum Type { @@ -132,7 +134,7 @@ public final class PowerHandler implements MjAPI.IBatteryProvider { private PerditionCalculator perdition; private final PowerReceiver receiver; private final Type type; - private MjAPI.BatteryObject battery; + private IBatteryObject battery; // Tracking private double averageLostPower = 0; private double averageReceivedPower = 0; @@ -148,7 +150,7 @@ public final class PowerHandler implements MjAPI.IBatteryProvider { this.receiver = new PowerReceiver(); this.perdition = DEFAULT_PERDITION; - if (battery instanceof MjAPI.BatteryObject) { + if (battery instanceof IBatteryObject) { this.battery = (MjAPI.BatteryObject) battery; } else if (battery != null) { this.battery = MjAPI.getMjBattery(battery); @@ -182,7 +184,7 @@ public final class PowerHandler implements MjAPI.IBatteryProvider { } @Override - public MjAPI.BatteryObject getMjBattery() { + public IBatteryObject getMjBattery() { return battery; } diff --git a/common/buildcraft/energy/TileEnergyConverter.java b/common/buildcraft/energy/TileEnergyConverter.java index 3962630e..0bc900e6 100644 --- a/common/buildcraft/energy/TileEnergyConverter.java +++ b/common/buildcraft/energy/TileEnergyConverter.java @@ -18,6 +18,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.core.NetworkData; +import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.MjAPI; import buildcraft.api.mj.MjBattery; import buildcraft.api.power.IPowerReceptor; @@ -121,7 +122,7 @@ public class TileEnergyConverter extends TileBuildCraft implements IPowerRecepto if (tile instanceof TileEnergyConverter) { continue; } - MjAPI.BatteryObject object = MjAPI.getMjBattery(tile); + IBatteryObject object = MjAPI.getMjBattery(tile); if (object != null && mjStored > 0) { double wantToUse = Math.min(mjStored, object.getEnergyRequested()); object.addEnergy(wantToUse); diff --git a/common/buildcraft/energy/TileEnergyReceiver.java b/common/buildcraft/energy/TileEnergyReceiver.java index 3c1b51ff..7eedfa66 100755 --- a/common/buildcraft/energy/TileEnergyReceiver.java +++ b/common/buildcraft/energy/TileEnergyReceiver.java @@ -14,8 +14,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.MjAPI; -import buildcraft.api.mj.MjAPI.BatteryObject; import buildcraft.api.power.IPowerEmitter; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; @@ -74,7 +74,7 @@ public class TileEnergyReceiver extends TileBuildCraft implements IPipeConnectio energyStored = 0; } } else if (tile != null) { - BatteryObject battery = MjAPI.getMjBattery(tile); + IBatteryObject battery = MjAPI.getMjBattery(tile); if (battery != null) { battery.addEnergy(energyStored); diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 19736f01..c4c85315 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -22,8 +22,8 @@ import buildcraft.BuildCraftEnergy; import buildcraft.api.core.NetworkData; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; +import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.MjAPI; -import buildcraft.api.mj.MjAPI.BatteryObject; import buildcraft.api.power.IPowerEmitter; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; @@ -307,7 +307,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto extractEnergy(receptor.getMinEnergyReceived(), needed, true); } } else { - BatteryObject battery = MjAPI.getMjBattery(tile); + IBatteryObject battery = MjAPI.getMjBattery(tile); battery.addEnergy(extractEnergy(0, battery.maxReceivedPerCycle(), true)); diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 88fb6220..0be0e5f1 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -21,8 +21,8 @@ import buildcraft.BuildCraftCore; import buildcraft.BuildCraftTransport; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.ITrigger; +import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.MjAPI; -import buildcraft.api.mj.MjAPI.BatteryObject; import buildcraft.api.power.IPowerEmitter; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler.PowerReceiver; @@ -202,7 +202,7 @@ public class PipeTransportPower extends PipeTransport { internalPower[i] -= watts; } else if (tiles[j] != null) { // Look for the simplified power framework - BatteryObject battery = MjAPI.getMjBattery(tiles [j]); + IBatteryObject battery = MjAPI.getMjBattery(tiles [j]); if (battery != null) { watts = (internalPower[i] / totalPowerQuery) @@ -250,7 +250,7 @@ public class PipeTransportPower extends PipeTransport { } if (tile != null) { - BatteryObject battery = MjAPI.getMjBattery(tile); + IBatteryObject battery = MjAPI.getMjBattery(tile); if (battery != null) { requestEnergy(dir, battery.getEnergyRequested()); diff --git a/common/buildcraft/transport/gates/GateExpansionPulsar.java b/common/buildcraft/transport/gates/GateExpansionPulsar.java index cbaca907..a0b93881 100644 --- a/common/buildcraft/transport/gates/GateExpansionPulsar.java +++ b/common/buildcraft/transport/gates/GateExpansionPulsar.java @@ -17,8 +17,8 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.gates.GateExpansionController; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IGateExpansion; +import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.MjAPI; -import buildcraft.api.mj.MjAPI.BatteryObject; import buildcraft.transport.TileGenericPipe; import buildcraft.transport.triggers.ActionEnergyPulsar; import buildcraft.transport.triggers.ActionSingleEnergyPulse; @@ -97,7 +97,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement return; } - BatteryObject battery = MjAPI.getMjBattery(pipeTile); + IBatteryObject battery = MjAPI.getMjBattery(pipeTile); if (battery != null && (!singlePulse || !hasPulsed)) { ((TileGenericPipe) pipeTile).pipe.gate.setPulsing(true); From f299a7293bb1723b33d938a2e1eb2e272e7eee39 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Fri, 9 May 2014 08:09:50 +0200 Subject: [PATCH 18/20] extracted battery object to first-level class --- api/buildcraft/api/mj/BatteryObject.java | 134 +++++++++++++++++++++ api/buildcraft/api/mj/MjAPI.java | 129 -------------------- api/buildcraft/api/power/PowerHandler.java | 3 +- 3 files changed, 136 insertions(+), 130 deletions(-) create mode 100755 api/buildcraft/api/mj/BatteryObject.java diff --git a/api/buildcraft/api/mj/BatteryObject.java b/api/buildcraft/api/mj/BatteryObject.java new file mode 100755 index 00000000..26a35d61 --- /dev/null +++ b/api/buildcraft/api/mj/BatteryObject.java @@ -0,0 +1,134 @@ +package buildcraft.api.mj; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import buildcraft.api.core.JavaTools; + +public class BatteryObject implements IBatteryObject { + protected Field f; + protected Object o; + protected MjBattery b; + + /** + * {@inheritDoc} + */ + @Override + public double getEnergyRequested() { + try { + return JavaTools.bounds(b.maxCapacity() - f.getDouble(o), b.minimumConsumption(), b.maxReceivedPerCycle()); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return 0; + } + + /** + * {@inheritDoc} + */ + @Override + public double addEnergy(double mj) { + return addEnergy(mj, false); + } + + /** + * {@inheritDoc} + */ + @Override + public double addEnergy(double mj, boolean ignoreCycleLimit) { + try { + double contained = f.getDouble(o); + double maxAccepted = b.maxCapacity() - contained + b.minimumConsumption(); + if (!ignoreCycleLimit && maxAccepted > b.maxReceivedPerCycle()) { + maxAccepted = b.maxReceivedPerCycle(); + } + double used = Math.min(maxAccepted, mj); + if (used > 0) { + f.setDouble(o, Math.min(contained + used, b.maxCapacity())); + return used; + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return 0; + } + + /** + * {@inheritDoc} + */ + @Override + public double getEnergyStored() { + try { + return f.getDouble(o); + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 0; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setEnergyStored(double mj) { + try { + f.setDouble(o, mj); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public double maxCapacity() { + return b.maxCapacity(); + } + + /** + * {@inheritDoc} + */ + @Override + public double minimumConsumption() { + return b.minimumConsumption(); + } + + /** + * {@inheritDoc} + */ + @Override + public double maxReceivedPerCycle() { + return b.maxReceivedPerCycle(); + } + + /** + * {@inheritDoc} + */ + @Override + public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) { + b = new MjBattery() { + @Override + public double maxCapacity() { + return maxCapacity; + } + + @Override + public double maxReceivedPerCycle() { + return maxReceivedPerCycle; + } + + @Override + public double minimumConsumption() { + return minimumConsumption; + } + + @Override + public Class annotationType() { + return MjBattery.class; + } + }; + return this; + } +} \ No newline at end of file diff --git a/api/buildcraft/api/mj/MjAPI.java b/api/buildcraft/api/mj/MjAPI.java index 0d5e3ea8..5bbacf1f 100755 --- a/api/buildcraft/api/mj/MjAPI.java +++ b/api/buildcraft/api/mj/MjAPI.java @@ -8,7 +8,6 @@ */ package buildcraft.api.mj; -import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; @@ -28,134 +27,6 @@ public final class MjAPI { BatteryKind kind; } - public static class BatteryObject implements IBatteryObject { - private Field f; - private Object o; - private MjBattery b; - - /** - * {@inheritDoc} - */ - @Override - public double getEnergyRequested() { - try { - return JavaTools.bounds(b.maxCapacity() - f.getDouble(o), b.minimumConsumption(), b.maxReceivedPerCycle()); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - public double addEnergy(double mj) { - return addEnergy(mj, false); - } - - /** - * {@inheritDoc} - */ - @Override - public double addEnergy(double mj, boolean ignoreCycleLimit) { - try { - double contained = f.getDouble(o); - double maxAccepted = b.maxCapacity() - contained + b.minimumConsumption(); - if (!ignoreCycleLimit && maxAccepted > b.maxReceivedPerCycle()) { - maxAccepted = b.maxReceivedPerCycle(); - } - double used = Math.min(maxAccepted, mj); - if (used > 0) { - f.setDouble(o, Math.min(contained + used, b.maxCapacity())); - return used; - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - public double getEnergyStored() { - try { - return f.getDouble(o); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return 0; - } - } - - /** - * {@inheritDoc} - */ - @Override - public void setEnergyStored(double mj) { - try { - f.setDouble(o, mj); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - /** - * {@inheritDoc} - */ - @Override - public double maxCapacity() { - return b.maxCapacity(); - } - - /** - * {@inheritDoc} - */ - @Override - public double minimumConsumption() { - return b.minimumConsumption(); - } - - /** - * {@inheritDoc} - */ - @Override - public double maxReceivedPerCycle() { - return b.maxReceivedPerCycle(); - } - - /** - * {@inheritDoc} - */ - @Override - public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) { - b = new MjBattery() { - @Override - public double maxCapacity() { - return maxCapacity; - } - - @Override - public double maxReceivedPerCycle() { - return maxReceivedPerCycle; - } - - @Override - public double minimumConsumption() { - return minimumConsumption; - } - - @Override - public Class annotationType() { - return MjBattery.class; - } - }; - return this; - } - } - /** * Deactivate constructor */ diff --git a/api/buildcraft/api/power/PowerHandler.java b/api/buildcraft/api/power/PowerHandler.java index f774359c..a9a532e8 100644 --- a/api/buildcraft/api/power/PowerHandler.java +++ b/api/buildcraft/api/power/PowerHandler.java @@ -13,6 +13,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; +import buildcraft.api.mj.BatteryObject; import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.IBatteryProvider; import buildcraft.api.mj.MjAPI; @@ -151,7 +152,7 @@ public final class PowerHandler implements IBatteryProvider { this.perdition = DEFAULT_PERDITION; if (battery instanceof IBatteryObject) { - this.battery = (MjAPI.BatteryObject) battery; + this.battery = (BatteryObject) battery; } else if (battery != null) { this.battery = MjAPI.getMjBattery(battery); } else { From 1febf3c7148127e80495b06c1ef83bed2fb7415d Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Fri, 9 May 2014 18:13:02 +0200 Subject: [PATCH 19/20] updated energy framework to be openned to different channels, close #1756 --- api/buildcraft/api/mj/BatteryObject.java | 62 +++++++++---- api/buildcraft/api/mj/MjAPI.java | 105 +++++++++++++++++++---- api/buildcraft/api/mj/MjBattery.java | 7 ++ 3 files changed, 136 insertions(+), 38 deletions(-) diff --git a/api/buildcraft/api/mj/BatteryObject.java b/api/buildcraft/api/mj/BatteryObject.java index 26a35d61..0d060bf5 100755 --- a/api/buildcraft/api/mj/BatteryObject.java +++ b/api/buildcraft/api/mj/BatteryObject.java @@ -1,14 +1,29 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ package buildcraft.api.mj; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.util.logging.Level; +import buildcraft.api.core.BCLog; import buildcraft.api.core.JavaTools; +/** + * A battery object is a wrapper around a battery field in an object. This + * battery field is of type double, and is the only piece of data specific to + * this object. Others are class-wide. + */ public class BatteryObject implements IBatteryObject { - protected Field f; - protected Object o; - protected MjBattery b; + protected Field energyStored; + protected Object obj; + protected MjBattery batteryData; /** * {@inheritDoc} @@ -16,9 +31,10 @@ public class BatteryObject implements IBatteryObject { @Override public double getEnergyRequested() { try { - return JavaTools.bounds(b.maxCapacity() - f.getDouble(o), b.minimumConsumption(), b.maxReceivedPerCycle()); + return JavaTools.bounds(batteryData.maxCapacity() - energyStored.getDouble(obj), + batteryData.minimumConsumption(), batteryData.maxReceivedPerCycle()); } catch (IllegalAccessException e) { - e.printStackTrace(); + BCLog.logger.log(Level.WARNING, "can't get energy requested", e); } return 0; } @@ -37,18 +53,18 @@ public class BatteryObject implements IBatteryObject { @Override public double addEnergy(double mj, boolean ignoreCycleLimit) { try { - double contained = f.getDouble(o); - double maxAccepted = b.maxCapacity() - contained + b.minimumConsumption(); - if (!ignoreCycleLimit && maxAccepted > b.maxReceivedPerCycle()) { - maxAccepted = b.maxReceivedPerCycle(); + double contained = energyStored.getDouble(obj); + double maxAccepted = batteryData.maxCapacity() - contained + batteryData.minimumConsumption(); + if (!ignoreCycleLimit && maxAccepted > batteryData.maxReceivedPerCycle()) { + maxAccepted = batteryData.maxReceivedPerCycle(); } double used = Math.min(maxAccepted, mj); if (used > 0) { - f.setDouble(o, Math.min(contained + used, b.maxCapacity())); + energyStored.setDouble(obj, Math.min(contained + used, batteryData.maxCapacity())); return used; } } catch (IllegalAccessException e) { - e.printStackTrace(); + BCLog.logger.log(Level.WARNING, "can't add energy", e); } return 0; @@ -60,9 +76,9 @@ public class BatteryObject implements IBatteryObject { @Override public double getEnergyStored() { try { - return f.getDouble(o); + return energyStored.getDouble(obj); } catch (IllegalAccessException e) { - e.printStackTrace(); + BCLog.logger.log(Level.WARNING, "can't get return energy stored", e); return 0; } } @@ -73,8 +89,9 @@ public class BatteryObject implements IBatteryObject { @Override public void setEnergyStored(double mj) { try { - f.setDouble(o, mj); + energyStored.setDouble(obj, mj); } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't set energy stored", e); throw new RuntimeException(e); } } @@ -84,7 +101,7 @@ public class BatteryObject implements IBatteryObject { */ @Override public double maxCapacity() { - return b.maxCapacity(); + return batteryData.maxCapacity(); } /** @@ -92,7 +109,7 @@ public class BatteryObject implements IBatteryObject { */ @Override public double minimumConsumption() { - return b.minimumConsumption(); + return batteryData.minimumConsumption(); } /** @@ -100,15 +117,16 @@ public class BatteryObject implements IBatteryObject { */ @Override public double maxReceivedPerCycle() { - return b.maxReceivedPerCycle(); + return batteryData.maxReceivedPerCycle(); } /** * {@inheritDoc} */ @Override - public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) { - b = new MjBattery() { + public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, + final double minimumConsumption) { + batteryData = new MjBattery() { @Override public double maxCapacity() { return maxCapacity; @@ -128,7 +146,13 @@ public class BatteryObject implements IBatteryObject { public Class annotationType() { return MjBattery.class; } + + @Override + public String kind() { + return MjAPI.DEFAULT_POWER_FRAMEWORK; + } }; + return this; } } \ No newline at end of file diff --git a/api/buildcraft/api/mj/MjAPI.java b/api/buildcraft/api/mj/MjAPI.java index 5bbacf1f..40783541 100755 --- a/api/buildcraft/api/mj/MjAPI.java +++ b/api/buildcraft/api/mj/MjAPI.java @@ -11,21 +11,21 @@ package buildcraft.api.mj; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; +import buildcraft.api.core.BCLog; import buildcraft.api.core.JavaTools; +/** + * The class MjAPI provides services to the Minecraft Joules power framework. + * BuildCraft implements a default power model on top of this, the "kinesis" + * power model. Third party mods may provide they own version of Minecraft + * Joules batteries and provide different models. + */ public final class MjAPI { - private static Map MjBatteries = new HashMap(); - - private enum BatteryKind { - Value, Container - } - - private static class BatteryField { - Field field; - MjBattery battery; - BatteryKind kind; - } + public static final String DEFAULT_POWER_FRAMEWORK = "buildcraft.kinesis"; + private static Map mjBatteries = new HashMap(); + private static Map> mjBatteryKinds = new HashMap>(); /** * Deactivate constructor @@ -33,13 +33,28 @@ public final class MjAPI { private MjAPI() { } + /** + * Returns the default battery related to the object given in parameter. For + * performance optimization, it's good to cache this object in the providing + * power framework if possible. + */ public static IBatteryObject getMjBattery(Object o) { + return getMjBattery(o, DEFAULT_POWER_FRAMEWORK); + } + + /** + * Returns the battery related to the object given in parameter. For + * performance optimization, it's good to cache this object in the providing + * power framework if possible. + */ + public static IBatteryObject getMjBattery(Object o, String kind) { if (o == null) { return null; } if (o instanceof IBatteryProvider) { IBatteryObject battery = ((IBatteryProvider) o).getMjBattery(); + if (battery != null) { return battery; } @@ -49,12 +64,25 @@ public final class MjAPI { if (f == null) { return null; + } else if (!mjBatteryKinds.containsKey(kind)) { + return null; } else if (f.kind == BatteryKind.Value) { - BatteryObject obj = new BatteryObject(); - obj.o = o; - obj.f = f.field; - obj.b = f.battery; - return obj; + try { + BatteryObject obj = mjBatteryKinds.get(kind).newInstance(); + obj.obj = o; + obj.energyStored = f.field; + obj.batteryData = f.battery; + + return obj; + } catch (InstantiationException e) { + BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\""); + + return null; + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\""); + + return null; + } } else { try { return getMjBattery(f.field.get(o)); @@ -65,8 +93,41 @@ public final class MjAPI { } } + public static IBatteryObject[] getAllMjBatteries(Object o) { + IBatteryObject[] result = new IBatteryObject[mjBatteries.size()]; + + int id = 0; + + for (String kind : mjBatteryKinds.keySet()) { + result[id] = getMjBattery(o, kind); + id++; + } + + return result; + } + + public static void registerMJBatteryKind(String kind, Class clas) { + if (!mjBatteryKinds.containsKey(kind)) { + mjBatteryKinds.put(kind, clas); + } else { + BCLog.logger.log(Level.WARNING, + "energy kind \"" + kind + "\" already registered with " + clas.getCanonicalName()); + } + } + + private enum BatteryKind { + Value, Container + } + + private static class BatteryField { + public Field field; + public MjBattery battery; + public BatteryKind kind; + } + private static BatteryField getMjBatteryField(Class c) { - BatteryField bField = MjBatteries.get(c); + BatteryField bField = mjBatteries.get(c); + if (bField == null) { for (Field f : JavaTools.getAllFields(c)) { MjBattery battery = f.getAnnotation(MjBattery.class); @@ -86,14 +147,20 @@ public final class MjAPI { bField.kind = BatteryKind.Container; } - MjBatteries.put(c, bField); + mjBatteries.put(c, bField); return bField; } } - MjBatteries.put(c, null); + + mjBatteries.put(c, null); } + return bField; } + static { + mjBatteryKinds.put(MjAPI.DEFAULT_POWER_FRAMEWORK, BatteryObject.class); + } + } diff --git a/api/buildcraft/api/mj/MjBattery.java b/api/buildcraft/api/mj/MjBattery.java index af4e97c7..f24e2219 100755 --- a/api/buildcraft/api/mj/MjBattery.java +++ b/api/buildcraft/api/mj/MjBattery.java @@ -48,4 +48,11 @@ public @interface MjBattery { * @return Minimal energy for keep machine is active */ double minimumConsumption() default 0.1; + + /** + * @return The kind of battery stored. Specific power systems can be created + * through this system, as several battery of different kind can + * coexist in the same tile. + */ + String kind() default MjAPI.DEFAULT_POWER_FRAMEWORK; } \ No newline at end of file From 8f75c806184f737a1c4bdbfe222e6ef5712ffe89 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Fri, 9 May 2014 18:13:15 +0200 Subject: [PATCH 20/20] added provision against NPE --- common/buildcraft/transport/BlockGenericPipe.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 756a27c6..de990f45 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -541,13 +541,11 @@ public class BlockGenericPipe extends BlockBuildCraft { } public static void removePipe(Pipe pipe) { - if (pipe == null) { + if (!isValid(pipe)) { return; } - if (isValid(pipe)) { - pipe.onBlockRemoval(); - } + pipe.onBlockRemoval(); World world = pipe.container.getWorldObj();