mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-02-23 14:30:51 +00:00
power net crap
This commit is contained in:
parent
4869dbb1c8
commit
1b24a1d860
@ -1,9 +1,12 @@
|
|||||||
package api.hbm.energymk2;
|
package api.hbm.energymk2;
|
||||||
|
|
||||||
|
import api.hbm.energymk2.Nodespace.PowerNode;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
public interface IEnergyConductorMK2 extends IEnergyConnectorMK2 {
|
public interface IEnergyConductorMK2 extends IEnergyConnectorMK2 {
|
||||||
|
|
||||||
// ??? could be redundant because of nodespace, we'll see how that works out
|
public default PowerNode getNode() {
|
||||||
public PowerNetMK2 getPowerNet();
|
TileEntity tile = (TileEntity) this;
|
||||||
|
return Nodespace.getNode(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord);
|
||||||
public void setPowerNet(PowerNetMK2 network);
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import com.hbm.util.CompatEnergyControl;
|
|||||||
|
|
||||||
import api.hbm.energy.ILoadedTile;
|
import api.hbm.energy.ILoadedTile;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public interface IEnergyConnectorMK2 extends ILoadedTile {
|
public interface IEnergyConnectorMK2 extends ILoadedTile {
|
||||||
@ -17,9 +19,18 @@ public interface IEnergyConnectorMK2 extends ILoadedTile {
|
|||||||
public default boolean canConnect(ForgeDirection dir) {
|
public default boolean canConnect(ForgeDirection dir) {
|
||||||
return dir != ForgeDirection.UNKNOWN;
|
return dir != ForgeDirection.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getPower();
|
public long getPower();
|
||||||
public long getMaxPower();
|
public long getMaxPower();
|
||||||
|
|
||||||
|
public static final boolean particleDebug = false;
|
||||||
|
|
||||||
|
public default Vec3 getDebugParticlePos() {
|
||||||
|
TileEntity te = (TileEntity) this;
|
||||||
|
Vec3 vec = Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 1, te.zCoord + 0.5);
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
public default void provideInfoForEC(NBTTagCompound data) {
|
public default void provideInfoForEC(NBTTagCompound data) {
|
||||||
data.setLong(CompatEnergyControl.L_ENERGY_HE, this.getPower());
|
data.setLong(CompatEnergyControl.L_ENERGY_HE, this.getPower());
|
||||||
data.setLong(CompatEnergyControl.L_CAPACITY_HE, this.getMaxPower());
|
data.setLong(CompatEnergyControl.L_CAPACITY_HE, this.getMaxPower());
|
||||||
|
|||||||
@ -1,7 +1,46 @@
|
|||||||
package api.hbm.energymk2;
|
package api.hbm.energymk2;
|
||||||
|
|
||||||
|
import com.hbm.packet.AuxParticlePacketNT;
|
||||||
|
import com.hbm.packet.PacketDispatcher;
|
||||||
|
|
||||||
import api.hbm.energy.IEnergyConnector;
|
import api.hbm.energy.IEnergyConnector;
|
||||||
|
import api.hbm.energymk2.Nodespace.PowerNode;
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public interface IEnergyProviderMK2 extends IEnergyConnector {
|
public interface IEnergyProviderMK2 extends IEnergyConnector {
|
||||||
|
|
||||||
|
public default void tryProvide(World world, int x, int y, int z, ForgeDirection dir) {
|
||||||
|
|
||||||
|
TileEntity te = world.getTileEntity(x, y, z);
|
||||||
|
boolean red = false;
|
||||||
|
|
||||||
|
if(te instanceof IEnergyConductorMK2) {
|
||||||
|
IEnergyConductorMK2 con = (IEnergyConductorMK2) te;
|
||||||
|
if(!con.canConnect(dir.getOpposite())) return;
|
||||||
|
|
||||||
|
PowerNode node = con.getNode();
|
||||||
|
|
||||||
|
if(node != null && node.net != null) {
|
||||||
|
node.net.addProvider(this);
|
||||||
|
red = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(particleDebug) {
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
data.setString("type", "network");
|
||||||
|
data.setString("mode", "power");
|
||||||
|
double posX = x + 0.5 - dir.offsetX * 0.5 + world.rand.nextDouble() * 0.5 - 0.25;
|
||||||
|
double posY = y + 0.5 - dir.offsetY * 0.5 + world.rand.nextDouble() * 0.5 - 0.25;
|
||||||
|
double posZ = z + 0.5 - dir.offsetZ * 0.5 + world.rand.nextDouble() * 0.5 - 0.25;
|
||||||
|
data.setDouble("mX", dir.offsetX * (red ? 0.025 : 0.1));
|
||||||
|
data.setDouble("mY", dir.offsetY * (red ? 0.025 : 0.1));
|
||||||
|
data.setDouble("mZ", dir.offsetZ * (red ? 0.025 : 0.1));
|
||||||
|
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, posX, posY, posZ), new TargetPoint(world.provider.dimensionId, posX, posY, posZ, 25));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@ package api.hbm.energymk2;
|
|||||||
import com.hbm.packet.AuxParticlePacketNT;
|
import com.hbm.packet.AuxParticlePacketNT;
|
||||||
import com.hbm.packet.PacketDispatcher;
|
import com.hbm.packet.PacketDispatcher;
|
||||||
|
|
||||||
|
import api.hbm.energymk2.Nodespace.PowerNode;
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Vec3;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
@ -21,15 +21,14 @@ public interface IEnergyReceiverMK2 extends IEnergyConnectorMK2 {
|
|||||||
|
|
||||||
if(te instanceof IEnergyConductorMK2) {
|
if(te instanceof IEnergyConductorMK2) {
|
||||||
IEnergyConductorMK2 con = (IEnergyConductorMK2) te;
|
IEnergyConductorMK2 con = (IEnergyConductorMK2) te;
|
||||||
|
if(!con.canConnect(dir.getOpposite())) return;
|
||||||
|
|
||||||
if(!con.canConnect(dir.getOpposite()))
|
PowerNode node = con.getNode();
|
||||||
return;
|
|
||||||
|
|
||||||
if(con.getPowerNet() != null && !con.getPowerNet().isSubscribed(this))
|
if(node != null && node.net != null) {
|
||||||
con.getPowerNet().subscribe(this);
|
node.net.addReceiver(this);
|
||||||
|
|
||||||
if(con.getPowerNet() != null)
|
|
||||||
red = true;
|
red = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(particleDebug) {
|
if(particleDebug) {
|
||||||
@ -52,20 +51,14 @@ public interface IEnergyReceiverMK2 extends IEnergyConnectorMK2 {
|
|||||||
|
|
||||||
if(te instanceof IEnergyConductorMK2) {
|
if(te instanceof IEnergyConductorMK2) {
|
||||||
IEnergyConductorMK2 con = (IEnergyConductorMK2) te;
|
IEnergyConductorMK2 con = (IEnergyConductorMK2) te;
|
||||||
|
PowerNode node = con.getNode();
|
||||||
|
|
||||||
if(con.getPowerNet() != null && con.getPowerNet().isSubscribed(this))
|
if(node != null && node.net != null) {
|
||||||
con.getPowerNet().unsubscribe(this);
|
node.net.removeReceiver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean particleDebug = false;
|
|
||||||
|
|
||||||
public default Vec3 getDebugParticlePos() {
|
|
||||||
TileEntity te = (TileEntity) this;
|
|
||||||
Vec3 vec = Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 1, te.zCoord + 0.5);
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public default ConnectionPriority getPriority() {
|
public default ConnectionPriority getPriority() {
|
||||||
return ConnectionPriority.NORMAL;
|
return ConnectionPriority.NORMAL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
package api.hbm.energymk2;
|
package api.hbm.energymk2;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,6 +19,19 @@ public class Nodespace {
|
|||||||
/** Contains all "NodeWorld" instances, i.e. lists of nodes existing per world */
|
/** Contains all "NodeWorld" instances, i.e. lists of nodes existing per world */
|
||||||
public static HashMap<World, NodeWorld> worlds = new HashMap();
|
public static HashMap<World, NodeWorld> worlds = new HashMap();
|
||||||
|
|
||||||
|
public static PowerNode getNode(World world, int x, int y, int z) {
|
||||||
|
NodeWorld nodeWorld = worlds.get(world);
|
||||||
|
if(nodeWorld != null) return nodeWorld.nodes.get(new BlockPos(x, y, z));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateNodespace() {
|
||||||
|
|
||||||
|
for(World world : MinecraftServer.getServer().worldServers) {
|
||||||
|
NodeWorld nodes = worlds.get(world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class NodeWorld {
|
public static class NodeWorld {
|
||||||
|
|
||||||
/** Contains a map showing where each node is, a node is every spot that a cable exists at.
|
/** Contains a map showing where each node is, a node is every spot that a cable exists at.
|
||||||
@ -48,6 +63,7 @@ public class Nodespace {
|
|||||||
|
|
||||||
public BlockPos[] positions;
|
public BlockPos[] positions;
|
||||||
public DirPos[] connections;
|
public DirPos[] connections;
|
||||||
|
public PowerNetMK2 net;
|
||||||
|
|
||||||
public PowerNode(BlockPos... positions) {
|
public PowerNode(BlockPos... positions) {
|
||||||
this.positions = positions;
|
this.positions = positions;
|
||||||
|
|||||||
@ -12,45 +12,77 @@ public class PowerNetMK2 {
|
|||||||
private Set<PowerNode> links = new HashSet();
|
private Set<PowerNode> links = new HashSet();
|
||||||
|
|
||||||
/** Maps all active subscribers to a timestamp, handy for handling timeouts. In a good system this shouldn't be necessary, but the previous system taught me to be cautious anyway */
|
/** Maps all active subscribers to a timestamp, handy for handling timeouts. In a good system this shouldn't be necessary, but the previous system taught me to be cautious anyway */
|
||||||
private HashMap<IEnergyReceiverMK2, Long> subscriberEntries = new HashMap();
|
private HashMap<IEnergyReceiverMK2, Long> receiverEntries = new HashMap();
|
||||||
/** A simple set containing all subscribers, might be redundant because of the hashmap, we'll see if we keep this around */
|
|
||||||
private Set<IEnergyReceiverMK2> subscriberSet = new HashSet();
|
|
||||||
|
|
||||||
private HashMap<IEnergyProviderMK2, Long> providerEntries = new HashMap();
|
private HashMap<IEnergyProviderMK2, Long> providerEntries = new HashMap();
|
||||||
private Set<IEnergyProviderMK2> providerSet = new HashSet();
|
|
||||||
|
|
||||||
/// SUBSCRIBER HANDLING ///
|
/// SUBSCRIBER HANDLING ///
|
||||||
public boolean isSubscribed(IEnergyReceiverMK2 receiver) {
|
public boolean isSubscribed(IEnergyReceiverMK2 receiver) {
|
||||||
return this.subscriberSet.contains(receiver);
|
return this.receiverEntries.containsKey(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void subscribe(IEnergyReceiverMK2 receiver) {
|
public void addReceiver(IEnergyReceiverMK2 receiver) {
|
||||||
this.subscriberSet.add(receiver);
|
this.receiverEntries.put(receiver, System.currentTimeMillis());
|
||||||
this.subscriberEntries.put(receiver, System.currentTimeMillis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unsubscribe(IEnergyReceiverMK2 receiver) {
|
public void removeReceiver(IEnergyReceiverMK2 receiver) {
|
||||||
this.subscriberSet.remove(receiver);
|
this.receiverEntries.remove(receiver);
|
||||||
this.subscriberEntries.remove(receiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PROVIDER HANDLING ///
|
/// PROVIDER HANDLING ///
|
||||||
public boolean isProvider(IEnergyProviderMK2 provider) {
|
public boolean isProvider(IEnergyProviderMK2 provider) {
|
||||||
return this.providerSet.contains(provider);
|
return this.providerEntries.containsKey(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProvider(IEnergyProviderMK2 provider) {
|
public void addProvider(IEnergyProviderMK2 provider) {
|
||||||
this.providerSet.add(provider);
|
|
||||||
this.providerEntries.put(provider, System.currentTimeMillis());
|
this.providerEntries.put(provider, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeProvider(IEnergyProviderMK2 provider) {
|
public void removeProvider(IEnergyProviderMK2 provider) {
|
||||||
this.providerSet.remove(provider);
|
|
||||||
this.providerEntries.remove(provider);
|
this.providerEntries.remove(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// LINK JOINING ///
|
||||||
|
|
||||||
|
/** Combines two networks into one */
|
||||||
|
public void joinNetworks(PowerNetMK2 network) {
|
||||||
|
|
||||||
|
if(network == this) return; //wtf?!
|
||||||
|
|
||||||
|
for(PowerNode conductor : network.links) joinLink(conductor);
|
||||||
|
network.links.clear();
|
||||||
|
|
||||||
|
for(IEnergyReceiverMK2 connector : network.receiverEntries.keySet()) this.addReceiver(connector);
|
||||||
|
for(IEnergyProviderMK2 connector : network.providerEntries.keySet()) this.addProvider(connector);
|
||||||
|
network.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds the power node as part of this network's links */
|
||||||
|
public PowerNetMK2 joinLink(PowerNode node) {
|
||||||
|
if(node.net != null) node.net.leaveLink(node);
|
||||||
|
node.net = this;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes the specified power node */
|
||||||
|
public void leaveLink(PowerNode node) {
|
||||||
|
node.net = null;
|
||||||
|
this.links.remove(node);
|
||||||
|
}
|
||||||
|
|
||||||
/// GENERAL POWER NET CONTROL ///
|
/// GENERAL POWER NET CONTROL ///
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
this.valid = false;
|
this.valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return this.valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
this.invalidate();
|
||||||
|
for(PowerNode link : this.links) if(link.net == this) link.net = null;
|
||||||
|
this.links.clear();
|
||||||
|
this.receiverEntries.clear();
|
||||||
|
this.providerEntries.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user