generated from tilera/1710mod
feat: implement electricraft converters
All checks were successful
ci/woodpecker/push/central-override Pipeline was successful
All checks were successful
ci/woodpecker/push/central-override Pipeline was successful
This commit is contained in:
parent
083a30d6bc
commit
0f858338ff
|
@ -10,6 +10,7 @@ import cpw.mods.fml.common.Mod;
|
|||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.anvilcraft.pccompat.mods.AppliedEnergisticsProxy;
|
||||
import net.anvilcraft.pccompat.mods.ElectriCraftProxy;
|
||||
import net.anvilcraft.pccompat.mods.GregTechProxy;
|
||||
import net.anvilcraft.pccompat.mods.HBMProxy;
|
||||
import net.anvilcraft.pccompat.mods.MagneticraftProxy;
|
||||
|
@ -24,7 +25,7 @@ import net.anvilcraft.pccompat.mods.UniversalElectricityProxy;
|
|||
name = "PC Compat",
|
||||
version = "0.1.0",
|
||||
dependencies
|
||||
= "required-after:PowerConverters3;after:basiccomponents;after:appliedenergistics2;after:hbm;after:RedPowerCore;after:ProjRed|Expansion;after:gregtech;after:UltraTech;after:Railcraft;after:Magneticraft"
|
||||
= "required-after:PowerConverters3;after:basiccomponents;after:appliedenergistics2;after:hbm;after:RedPowerCore;after:ProjRed|Expansion;after:gregtech;after:UltraTech;after:Railcraft;after:Magneticraft;after:ElectriCraft"
|
||||
)
|
||||
public class PCCompat {
|
||||
public static HashSet<IModProxy> mods = new HashSet<>();
|
||||
|
@ -73,5 +74,7 @@ public class PCCompat {
|
|||
mods.add(new RailcraftProxy());
|
||||
if (Loader.isModLoaded("Magneticraft"))
|
||||
mods.add(new MagneticraftProxy());
|
||||
if (Loader.isModLoaded("ElectriCraft"))
|
||||
mods.add(new ElectriCraftProxy());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ import covers1624.powerconverters.block.BlockPowerConverter;
|
|||
import covers1624.powerconverters.gui.PCCreativeTab;
|
||||
import net.anvilcraft.pccompat.IModProxy;
|
||||
import net.anvilcraft.pccompat.Utils;
|
||||
import net.anvilcraft.pccompat.tiles.ITileNeighborNotify;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockPCCConverter extends BlockPowerConverter {
|
||||
|
@ -28,4 +30,14 @@ public class BlockPCCConverter extends BlockPowerConverter {
|
|||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return this.proxy.createTileEntity(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChange(
|
||||
IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ
|
||||
) {
|
||||
super.onNeighborChange(world, x, y, z, tileX, tileY, tileZ);
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te instanceof ITileNeighborNotify)
|
||||
((ITileNeighborNotify) te).onNeighborTEChange();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package net.anvilcraft.pccompat.mods;
|
||||
|
||||
import covers1624.powerconverters.api.registry.PowerSystemRegistry;
|
||||
import covers1624.powerconverters.api.registry.PowerSystemRegistry.PowerSystem;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.anvilcraft.pccompat.IModProxy;
|
||||
import net.anvilcraft.pccompat.blocks.BlockPCCConverter;
|
||||
import net.anvilcraft.pccompat.items.ItemBlockPowerConverter;
|
||||
import net.anvilcraft.pccompat.tiles.TileEntityElectriCraftConsumer;
|
||||
import net.anvilcraft.pccompat.tiles.TileEntityElectriCraftProducer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class ElectriCraftProxy implements IModProxy {
|
||||
public static final double ACTUAL_SCALE_AMOUNT = 112.0 / 20.0;
|
||||
|
||||
public static PowerSystem powerSystem;
|
||||
public static Block blockPowerConverter;
|
||||
|
||||
@Override
|
||||
public void registerPowerSystem() {
|
||||
PowerSystemRegistry.registerPowerSystem(
|
||||
powerSystem = new PowerSystem(
|
||||
// Scale "Ammount" determined experimentally
|
||||
"Joules",
|
||||
"J",
|
||||
120 / 20,
|
||||
"W"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlocks() {
|
||||
GameRegistry.registerBlock(
|
||||
blockPowerConverter = new BlockPCCConverter(this),
|
||||
ItemBlockPowerConverter.class,
|
||||
"power_converter_electricraft"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTiles() {
|
||||
GameRegistry.registerTileEntity(
|
||||
TileEntityElectriCraftConsumer.class, "electricraft_consumer"
|
||||
);
|
||||
GameRegistry.registerTileEntity(
|
||||
TileEntityElectriCraftProducer.class, "electricraft_producer"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipes() {}
|
||||
|
||||
@Override
|
||||
public String getModPrefix() {
|
||||
return "ec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(int meta) {
|
||||
return meta == 0 ? new TileEntityElectriCraftConsumer()
|
||||
: new TileEntityElectriCraftProducer();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package net.anvilcraft.pccompat.tiles;
|
||||
|
||||
/**
|
||||
* An interface for PowerConverter TEs that will be notified by the
|
||||
* block when a neighbor TE changes
|
||||
*/
|
||||
public interface ITileNeighborNotify {
|
||||
public void onNeighborTEChange();
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
package net.anvilcraft.pccompat.tiles;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
import Reika.DragonAPI.Instantiable.Data.Immutable.WorldLocation;
|
||||
import Reika.DragonAPI.Libraries.World.ReikaWorldHelper;
|
||||
import Reika.ElectriCraft.Auxiliary.Interfaces.NetworkTile;
|
||||
import Reika.ElectriCraft.Auxiliary.Interfaces.WireReceiver;
|
||||
import Reika.ElectriCraft.Network.WireNetwork;
|
||||
import covers1624.powerconverters.tile.main.TileEntityEnergyConsumer;
|
||||
import net.anvilcraft.pccompat.mods.ElectriCraftProxy;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityElectriCraftConsumer extends TileEntityEnergyConsumer<NetworkTile>
|
||||
implements WireReceiver, ITileNeighborNotify {
|
||||
public WireNetwork network;
|
||||
public double lastTransfer;
|
||||
|
||||
public TileEntityElectriCraftConsumer() {
|
||||
super(ElectriCraftProxy.powerSystem, 0, NetworkTile.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (this.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
this.lastTransfer = 0.0;
|
||||
if (this.network == null) {
|
||||
this.findAndJoinNetwork(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.worldObj.getTotalWorldTime() % 64L == 0L) {
|
||||
// TODO: WTF does this do?
|
||||
ReikaWorldHelper.causeAdjacentUpdates(
|
||||
this.worldObj, this.xCoord, this.yCoord, this.zCoord
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.canReceivePower())
|
||||
return;
|
||||
|
||||
double p = (long) this.network.getTerminalVoltage(this)
|
||||
* (long) this.network.getTerminalCurrent(this);
|
||||
|
||||
this.lastTransfer = p;
|
||||
double leftover
|
||||
= this.storeEnergy(p * ElectriCraftProxy.ACTUAL_SCALE_AMOUNT, false);
|
||||
|
||||
if (leftover > 0.0)
|
||||
this.network.updateWires();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNetworkOnSide(ForgeDirection arg0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findAndJoinNetwork(World arg0, int arg1, int arg2, int arg3) {
|
||||
this.network = new WireNetwork();
|
||||
this.network.addElement(this);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
TileEntity te = this.worldObj.getTileEntity(
|
||||
this.xCoord + dir.offsetX,
|
||||
this.yCoord + dir.offsetY,
|
||||
this.zCoord + dir.offsetZ
|
||||
);
|
||||
if (te instanceof NetworkTile) {
|
||||
NetworkTile n = (NetworkTile) te;
|
||||
if (n.canNetworkOnSide(dir.getOpposite())) {
|
||||
WireNetwork w = n.getNetwork();
|
||||
if (w != null) {
|
||||
w.merge(this.network);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WireNetwork getNetwork() {
|
||||
return this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.xCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.yCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.zCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkChanged() {}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void removeFromNetwork() {
|
||||
if (this.network != null) {
|
||||
try {
|
||||
// Thanks for private fields, Java!
|
||||
Field sinksField = WireNetwork.class.getDeclaredField("sinks");
|
||||
sinksField.setAccessible(true);
|
||||
HashMap<WorldLocation, WireReceiver> sinks
|
||||
= (HashMap<WorldLocation, WireReceiver>) sinksField.get(this.network);
|
||||
sinks.remove(new WorldLocation(this));
|
||||
|
||||
Method rebuild = WireNetwork.class.getDeclaredMethod("rebuild");
|
||||
rebuild.setAccessible(true);
|
||||
rebuild.invoke(this.network);
|
||||
} catch (
|
||||
NoSuchFieldException | SecurityException | IllegalArgumentException
|
||||
| IllegalAccessException | NoSuchMethodException
|
||||
| InvocationTargetException e
|
||||
) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetNetwork() {
|
||||
this.network = null;
|
||||
}
|
||||
|
||||
public final void rebuildNetwork() {
|
||||
this.removeFromNetwork();
|
||||
this.resetNetwork();
|
||||
this.findAndJoinNetwork(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(WireNetwork net) {
|
||||
if (net != null) {
|
||||
this.network = net;
|
||||
this.network.addElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceivePower() {
|
||||
return this.getTotalEnergyDemand() > 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceivePowerFromSide(ForgeDirection arg0) {
|
||||
return this.canReceivePower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getInputRate() {
|
||||
return this.lastTransfer / 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborTEChange() {
|
||||
this.rebuildNetwork();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
package net.anvilcraft.pccompat.tiles;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
import Reika.DragonAPI.Instantiable.Data.Immutable.WorldLocation;
|
||||
import Reika.ElectriCraft.Auxiliary.Interfaces.NetworkTile;
|
||||
import Reika.ElectriCraft.Auxiliary.Interfaces.WireEmitter;
|
||||
import Reika.ElectriCraft.Network.WireNetwork;
|
||||
import covers1624.powerconverters.tile.main.TileEntityEnergyProducer;
|
||||
import net.anvilcraft.pccompat.mods.ElectriCraftProxy;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityElectriCraftProducer extends TileEntityEnergyProducer<NetworkTile>
|
||||
implements WireEmitter, ITileNeighborNotify {
|
||||
public static final int VOLTAGE = 2048;
|
||||
public static final int AMPERAGE = 128;
|
||||
|
||||
public WireNetwork network;
|
||||
public boolean emitLastTick;
|
||||
public boolean hasSufficientPower;
|
||||
|
||||
public TileEntityElectriCraftProducer() {
|
||||
super(ElectriCraftProxy.powerSystem, 0, NetworkTile.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (this.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
if (this.network == null) {
|
||||
this.findAndJoinNetwork(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean emit = this.canEmitPower();
|
||||
if (emit != this.emitLastTick)
|
||||
this.network.updateWires();
|
||||
|
||||
this.emitLastTick = emit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNetworkOnSide(ForgeDirection arg0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findAndJoinNetwork(World arg0, int arg1, int arg2, int arg3) {
|
||||
this.network = new WireNetwork();
|
||||
this.network.addElement(this);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
TileEntity te = this.worldObj.getTileEntity(
|
||||
this.xCoord + dir.offsetX,
|
||||
this.yCoord + dir.offsetY,
|
||||
this.zCoord + dir.offsetZ
|
||||
);
|
||||
if (te instanceof NetworkTile) {
|
||||
NetworkTile n = (NetworkTile) te;
|
||||
if (n.canNetworkOnSide(dir.getOpposite())) {
|
||||
WireNetwork w = n.getNetwork();
|
||||
if (w != null) {
|
||||
w.merge(this.network);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WireNetwork getNetwork() {
|
||||
return this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.xCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.yCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.zCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkChanged() {}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void removeFromNetwork() {
|
||||
if (this.network != null) {
|
||||
try {
|
||||
// Thanks for private fields, Java!
|
||||
Field sinksField = WireNetwork.class.getDeclaredField("sources");
|
||||
sinksField.setAccessible(true);
|
||||
HashMap<WorldLocation, WireEmitter> sinks
|
||||
= (HashMap<WorldLocation, WireEmitter>) sinksField.get(this.network);
|
||||
sinks.remove(new WorldLocation(this));
|
||||
|
||||
Method rebuild = WireNetwork.class.getDeclaredMethod("rebuild");
|
||||
rebuild.setAccessible(true);
|
||||
rebuild.invoke(this.network);
|
||||
} catch (
|
||||
NoSuchFieldException | SecurityException | IllegalArgumentException
|
||||
| IllegalAccessException | NoSuchMethodException
|
||||
| InvocationTargetException e
|
||||
) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetNetwork() {
|
||||
this.network = null;
|
||||
}
|
||||
|
||||
public final void rebuildNetwork() {
|
||||
this.removeFromNetwork();
|
||||
this.resetNetwork();
|
||||
this.findAndJoinNetwork(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(WireNetwork net) {
|
||||
if (net != null) {
|
||||
this.network = net;
|
||||
this.network.addElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReadyToEmitPower() {
|
||||
return this.network != null && this.network.getNumberPathsStartingAt(this) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEmitPower() {
|
||||
return this.isReadyToEmitPower() && this.hasSufficientPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEmitPowerToSide(ForgeDirection arg0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenCurrent() {
|
||||
return this.canEmitPower() ? AMPERAGE : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenVoltage() {
|
||||
return this.canEmitPower() ? VOLTAGE : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double produceEnergy(double energy) {
|
||||
double avail = energy / ElectriCraftProxy.ACTUAL_SCALE_AMOUNT;
|
||||
|
||||
if (!this.isReadyToEmitPower() || avail < VOLTAGE * AMPERAGE) {
|
||||
this.hasSufficientPower = false;
|
||||
return energy;
|
||||
}
|
||||
|
||||
this.hasSufficientPower = true;
|
||||
return energy - VOLTAGE * AMPERAGE * ElectriCraftProxy.ACTUAL_SCALE_AMOUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborTEChange() {
|
||||
this.rebuildNetwork();
|
||||
}
|
||||
}
|
|
@ -36,3 +36,6 @@ pccompat:power_converter_rc_1.name=Railcraft Producer
|
|||
|
||||
pccompat:power_converter_mc_0.name=Magneticraft Consumer
|
||||
pccompat:power_converter_mc_1.name=Magneticraft Producer
|
||||
|
||||
pccompat:power_converter_ec_0.name=ElectriCraft Consumer
|
||||
pccompat:power_converter_ec_1.name=ElectriCraft Producer
|
||||
|
|
Loading…
Reference in a new issue