Fixed issue with IC2 integration causing console spam, fixes #218
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# Refined Storage Changelog
|
||||
|
||||
### 0.8.16
|
||||
**Bugfixes**
|
||||
- Fixed issue with IC2 integration causing console spam
|
||||
|
||||
### 0.8.15
|
||||
**Bugfixes**
|
||||
- Fixed server startup crash
|
||||
|
@@ -146,10 +146,6 @@ public final class RefinedStorage {
|
||||
return Loader.isModLoaded("JEI");
|
||||
}
|
||||
|
||||
public static boolean hasIC2() {
|
||||
return Loader.isModLoaded("IC2");
|
||||
}
|
||||
|
||||
public static boolean hasTesla() {
|
||||
return Loader.isModLoaded("Tesla");
|
||||
}
|
||||
|
@@ -6,16 +6,7 @@ import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
|
||||
// @TODO: Move this class to API
|
||||
// @TODO: Move IC2-specific stuff to special IC2 integration class, along with the IC2 wrapper class
|
||||
public final class NetworkUtils {
|
||||
public static int convertIC2ToRF(double amount) {
|
||||
return amount >= Double.POSITIVE_INFINITY ? Integer.MAX_VALUE : ((int) Math.floor(amount) * 4);
|
||||
}
|
||||
|
||||
public static double convertRFToIC2(int amount) {
|
||||
return Math.floor(amount / 4);
|
||||
}
|
||||
|
||||
public static ItemStack extractItem(INetworkMaster network, ItemStack stack, int size) {
|
||||
return network.extractItem(stack, size, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
||||
}
|
||||
|
40
src/main/java/refinedstorage/integration/ic2/IC2EnergyController.java
Executable file
40
src/main/java/refinedstorage/integration/ic2/IC2EnergyController.java
Executable file
@@ -0,0 +1,40 @@
|
||||
package refinedstorage.integration.ic2;
|
||||
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import refinedstorage.tile.controller.TileController;
|
||||
|
||||
public class IC2EnergyController implements IIC2EnergyController {
|
||||
private BasicSink sink;
|
||||
|
||||
public IC2EnergyController(final TileController controller) {
|
||||
this.sink = new BasicSink(controller, (int) IC2Integration.toEU(controller.getEnergy().getMaxEnergyStored()), Integer.MAX_VALUE) {
|
||||
@Override
|
||||
public double getDemandedEnergy() {
|
||||
return Math.max(0.0D, IC2Integration.toEU(controller.getEnergy().getMaxEnergyStored()) - IC2Integration.toEU(controller.getEnergy().getEnergyStored()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
|
||||
controller.getEnergy().setEnergyStored(controller.getEnergy().getEnergyStored() + IC2Integration.toRS(amount));
|
||||
|
||||
return 0.0D;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
sink.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
sink.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
sink.onChunkUnload();
|
||||
}
|
||||
}
|
15
src/main/java/refinedstorage/integration/ic2/IC2EnergyControllerNone.java
Executable file
15
src/main/java/refinedstorage/integration/ic2/IC2EnergyControllerNone.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package refinedstorage.integration.ic2;
|
||||
|
||||
public class IC2EnergyControllerNone implements IIC2EnergyController {
|
||||
@Override
|
||||
public void invalidate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
}
|
||||
}
|
17
src/main/java/refinedstorage/integration/ic2/IC2Integration.java
Executable file
17
src/main/java/refinedstorage/integration/ic2/IC2Integration.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package refinedstorage.integration.ic2;
|
||||
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
||||
public final class IC2Integration {
|
||||
public static boolean isLoaded() {
|
||||
return Loader.isModLoaded("IC2");
|
||||
}
|
||||
|
||||
public static int toRS(double amount) {
|
||||
return amount >= Double.POSITIVE_INFINITY ? Integer.MAX_VALUE : ((int) Math.floor(amount) * 4);
|
||||
}
|
||||
|
||||
public static double toEU(int amount) {
|
||||
return Math.floor(amount / 4);
|
||||
}
|
||||
}
|
9
src/main/java/refinedstorage/integration/ic2/IIC2EnergyController.java
Executable file
9
src/main/java/refinedstorage/integration/ic2/IIC2EnergyController.java
Executable file
@@ -0,0 +1,9 @@
|
||||
package refinedstorage.integration.ic2;
|
||||
|
||||
public interface IIC2EnergyController {
|
||||
void invalidate();
|
||||
|
||||
void update();
|
||||
|
||||
void onChunkUnload();
|
||||
}
|
@@ -25,15 +25,13 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.integration.ic2.IC2Integration;
|
||||
import refinedstorage.tile.controller.TileController;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static refinedstorage.apiimpl.network.NetworkUtils.convertIC2ToRF;
|
||||
import static refinedstorage.apiimpl.network.NetworkUtils.convertRFToIC2;
|
||||
|
||||
@Optional.InterfaceList({
|
||||
@Optional.Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = "IC2"),
|
||||
@Optional.Interface(iface = "ic2.api.item.IElectricItemManager", modid = "IC2")
|
||||
@@ -239,25 +237,25 @@ public class ItemWirelessGrid extends ItemEnergyContainer implements ISpecialEle
|
||||
@Optional.Method(modid = "IC2")
|
||||
@Override
|
||||
public double charge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
return convertRFToIC2(receiveEnergy(stack, convertIC2ToRF(amount), simulate));
|
||||
return IC2Integration.toEU(receiveEnergy(stack, IC2Integration.toRS(amount), simulate));
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "IC2")
|
||||
@Override
|
||||
public double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate) {
|
||||
return convertRFToIC2(extractEnergy(stack, convertIC2ToRF(amount), simulate));
|
||||
return IC2Integration.toEU(extractEnergy(stack, IC2Integration.toRS(amount), simulate));
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "IC2")
|
||||
@Override
|
||||
public double getCharge(ItemStack stack) {
|
||||
return convertRFToIC2(getEnergyStored(stack));
|
||||
return IC2Integration.toEU(getEnergyStored(stack));
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "IC2")
|
||||
@Override
|
||||
public double getMaxCharge(ItemStack stack) {
|
||||
return convertRFToIC2(getMaxEnergyStored(stack));
|
||||
return IC2Integration.toEU(getMaxEnergyStored(stack));
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "IC2")
|
||||
|
@@ -1,35 +0,0 @@
|
||||
package refinedstorage.tile.controller;
|
||||
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import static refinedstorage.apiimpl.network.NetworkUtils.convertIC2ToRF;
|
||||
import static refinedstorage.apiimpl.network.NetworkUtils.convertRFToIC2;
|
||||
|
||||
public class IC2Energy {
|
||||
private BasicSink sink;
|
||||
|
||||
public IC2Energy(final TileController controller) {
|
||||
this.sink = new BasicSink(controller, (int) convertRFToIC2(controller.getEnergy().getMaxEnergyStored()), Integer.MAX_VALUE) {
|
||||
@Override
|
||||
public double getDemandedEnergy() {
|
||||
return Math.max(0.0D, convertRFToIC2(controller.getEnergy().getMaxEnergyStored()) - convertRFToIC2(controller.getEnergy().getEnergyStored()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
|
||||
controller.getEnergy().setEnergyStored(controller.getEnergy().getEnergyStored() + convertIC2ToRF(amount));
|
||||
|
||||
return 0.0D;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
sink.invalidate();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
sink.update();
|
||||
}
|
||||
}
|
@@ -41,6 +41,10 @@ import refinedstorage.block.BlockController;
|
||||
import refinedstorage.block.EnumControllerType;
|
||||
import refinedstorage.container.ContainerController;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.integration.ic2.IC2EnergyController;
|
||||
import refinedstorage.integration.ic2.IC2EnergyControllerNone;
|
||||
import refinedstorage.integration.ic2.IC2Integration;
|
||||
import refinedstorage.integration.ic2.IIC2EnergyController;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.network.MessageGridDelta;
|
||||
import refinedstorage.network.MessageGridUpdate;
|
||||
@@ -100,7 +104,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
private List<ICraftingTask> craftingTasksToCancel = new ArrayList<ICraftingTask>();
|
||||
|
||||
private EnergyStorage energy = new EnergyStorage(RefinedStorage.INSTANCE.controllerCapacity);
|
||||
private IC2Energy IC2Energy;
|
||||
private IIC2EnergyController energyEU;
|
||||
private int energyUsage;
|
||||
|
||||
private int lastEnergyDisplay;
|
||||
@@ -115,8 +119,10 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
private List<ClientNode> clientNodes = new ArrayList<ClientNode>();
|
||||
|
||||
public TileController() {
|
||||
if (RefinedStorage.hasIC2()) {
|
||||
this.IC2Energy = new IC2Energy(this);
|
||||
if (IC2Integration.isLoaded()) {
|
||||
this.energyEU = new IC2EnergyController(this);
|
||||
} else {
|
||||
this.energyEU = new IC2EnergyControllerNone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +149,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
@Override
|
||||
public void update() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (IC2Energy != null) {
|
||||
IC2Energy.update();
|
||||
}
|
||||
energyEU.update();
|
||||
|
||||
if (canRun()) {
|
||||
Collections.sort(storage.getStorages(), sizeComparator);
|
||||
@@ -227,11 +231,9 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
energyEU.invalidate();
|
||||
|
||||
if (IC2Energy != null) {
|
||||
IC2Energy.invalidate();
|
||||
}
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
public List<ClientNode> getClientNodes() {
|
||||
@@ -250,9 +252,9 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
if (IC2Energy != null) {
|
||||
IC2Energy.invalidate();
|
||||
}
|
||||
super.onChunkUnload();
|
||||
|
||||
energyEU.onChunkUnload();
|
||||
}
|
||||
|
||||
public IGroupedStorage getStorage() {
|
||||
|
Reference in New Issue
Block a user