mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
new energy API and power net
This commit is contained in:
parent
6d211ee8db
commit
bb8a42e0b7
12
src/main/java/api/hbm/energy/IEnergyConductor.java
Normal file
12
src/main/java/api/hbm/energy/IEnergyConductor.java
Normal file
@ -0,0 +1,12 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
/**
|
||||
* For compatible cables with no buffer, using the IPowertNet. You can make your own cables with IEnergyConnector as well, but they won't join their power network.
|
||||
* @author hbm
|
||||
*/
|
||||
public interface IEnergyConductor extends IEnergyConnector {
|
||||
|
||||
public IPowerNet getPowerNet();
|
||||
|
||||
public void setPowerNet(IPowerNet network);
|
||||
}
|
||||
36
src/main/java/api/hbm/energy/IEnergyConnector.java
Normal file
36
src/main/java/api/hbm/energy/IEnergyConnector.java
Normal file
@ -0,0 +1,36 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* For anything that connects to power and can be transferred power to, the bottom-level interface.
|
||||
* @author hbm
|
||||
*/
|
||||
public interface IEnergyConnector {
|
||||
|
||||
/**
|
||||
* Returns the amount of power that was added
|
||||
* @param power
|
||||
* @return
|
||||
*/
|
||||
public long transferPower(long power);
|
||||
|
||||
/**
|
||||
* Whether the given side can be connected to
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
public boolean canConnect(ForgeDirection dir);
|
||||
|
||||
/**
|
||||
* The current power of either the machine or an entire network
|
||||
* @return
|
||||
*/
|
||||
public long getPower();
|
||||
|
||||
/**
|
||||
* The capacity of either the machine or an entire network
|
||||
* @return
|
||||
*/
|
||||
public long getMaxPower();
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
public interface IEnergyConsumer {
|
||||
/// WIP ///
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
public interface IEnergySource {
|
||||
/// WIP ///
|
||||
}
|
||||
13
src/main/java/api/hbm/energy/IEnergyUser.java
Normal file
13
src/main/java/api/hbm/energy/IEnergyUser.java
Normal file
@ -0,0 +1,13 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
/**
|
||||
* For machines and things that have an energy buffer and are affected by EMPs
|
||||
* @author hbm
|
||||
*/
|
||||
public interface IEnergyUser extends IEnergyConnector {
|
||||
|
||||
/**
|
||||
* Not to be used for actual energy transfer, rather special external things like EMPs
|
||||
*/
|
||||
public void setPower();
|
||||
}
|
||||
22
src/main/java/api/hbm/energy/IPowerNet.java
Normal file
22
src/main/java/api/hbm/energy/IPowerNet.java
Normal file
@ -0,0 +1,22 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Not mandatory to use, but making your cables IPowerNet-compliant will allow them to connect to NTM cables.
|
||||
* Cables will still work without it as long as they implement IEnergyConductor (or even IEnergyConnector) + self-built network code
|
||||
* @author hbm
|
||||
*/
|
||||
public interface IPowerNet {
|
||||
|
||||
public void join(IPowerNet network);
|
||||
|
||||
public IPowerNet subscribe(IEnergyConductor conductor);
|
||||
public void unsubscribe(IEnergyConductor conductor);
|
||||
|
||||
public void destroy();
|
||||
|
||||
public boolean isValid();
|
||||
|
||||
public List<IEnergyConductor> getSubscribers();
|
||||
}
|
||||
50
src/main/java/api/hbm/energy/PowerNet.java
Normal file
50
src/main/java/api/hbm/energy/PowerNet.java
Normal file
@ -0,0 +1,50 @@
|
||||
package api.hbm.energy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Basic IPowerNet implementation. The behavior of this demo might change inbetween releases, but the API remains the same.
|
||||
* For more consistency please implement your own IPowerNet.
|
||||
* @author hbm
|
||||
*/
|
||||
public class PowerNet implements IPowerNet {
|
||||
|
||||
private boolean valid = true;
|
||||
private List<IEnergyConductor> subscribers = new ArrayList();
|
||||
|
||||
@Override
|
||||
public void join(IPowerNet network) { }
|
||||
|
||||
@Override
|
||||
public IPowerNet subscribe(IEnergyConductor conductor) {
|
||||
|
||||
if(conductor.getPowerNet() != null)
|
||||
conductor.getPowerNet().unsubscribe(conductor);
|
||||
|
||||
conductor.setPowerNet(this);
|
||||
this.getSubscribers().add(conductor);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe(IEnergyConductor conductor) {
|
||||
conductor.setPowerNet(null);
|
||||
this.getSubscribers().remove(conductor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IEnergyConductor> getSubscribers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.valid = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.valid;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import api.hbm.energy.IEnergyConductor;
|
||||
import api.hbm.energy.IEnergyConnector;
|
||||
import api.hbm.energy.IPowerNet;
|
||||
import api.hbm.energy.PowerNet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityCableBaseTN extends TileEntity implements IEnergyConductor {
|
||||
|
||||
private IPowerNet network;
|
||||
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord);
|
||||
|
||||
if(te instanceof IEnergyConductor) {
|
||||
|
||||
IEnergyConductor conductor = (IEnergyConductor) te;
|
||||
|
||||
if(this.getPowerNet() == null) {
|
||||
this.setPowerNet(conductor.getPowerNet());
|
||||
} else if(conductor.getPowerNet() != null) {
|
||||
conductor.getPowerNet().join(this.getPowerNet());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.getPowerNet() == null) {
|
||||
this.setPowerNet(new PowerNet().subscribe(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update until a power net is formed, in >99% of the cases it should be the first tick. Everything else is handled by neighbors and the net itself.
|
||||
*/
|
||||
@Override
|
||||
public boolean canUpdate() {
|
||||
return network == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection dir) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPowerNet(IPowerNet network) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long transferPower(long power) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPowerNet getPowerNet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user