Remove overcomplicated powernet
This commit is contained in:
parent
e448bd1317
commit
06d23b10b7
10 changed files with 0 additions and 352 deletions
|
@ -42,7 +42,6 @@ import techreborn.init.RecipeCompact;
|
|||
import techreborn.lib.ModInfo;
|
||||
import techreborn.packets.PacketAesu;
|
||||
import techreborn.packets.PacketIdsu;
|
||||
import techreborn.powernet.PowerEvent;
|
||||
import techreborn.proxies.CommonProxy;
|
||||
import techreborn.tiles.idsu.IDSUManager;
|
||||
import techreborn.world.TROreGen;
|
||||
|
@ -132,7 +131,6 @@ public class Core {
|
|||
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new TRTickHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new OreUnifier());
|
||||
MinecraftForge.EVENT_BUS.register(new PowerEvent());
|
||||
logHelper.info("Initialization Complete");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package techreborn.blocks;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.BaseTileBlock;
|
||||
import techreborn.client.TechRebornCreativeTabMisc;
|
||||
import techreborn.powernet.PowerCable;
|
||||
import techreborn.tiles.TileCable;
|
||||
|
||||
public class BlockCable extends BaseTileBlock {
|
||||
|
||||
public BlockCable() {
|
||||
super(Material.iron);
|
||||
setUnlocalizedName("techreborn.cable");
|
||||
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileCable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
if(worldIn.getTileEntity(pos) instanceof TileCable){
|
||||
((TileCable) worldIn.getTileEntity(pos)).onRemoved();
|
||||
}
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
}
|
||||
}
|
|
@ -141,7 +141,6 @@ public class ModBlocks {
|
|||
public static Block rubberPlanks;
|
||||
|
||||
public static Block ironFence;
|
||||
public static Block cable;
|
||||
|
||||
public static void init() {
|
||||
thermalGenerator = new BlockThermalGenerator();
|
||||
|
@ -362,10 +361,6 @@ public class ModBlocks {
|
|||
ironFence = new BlockIronFence();
|
||||
GameRegistry.registerBlock(ironFence, "ironFence");
|
||||
|
||||
cable = new BlockCable();
|
||||
GameRegistry.registerBlock(cable, "cable");
|
||||
GameRegistry.registerTileEntity(TileCable.class, "tilecable");
|
||||
|
||||
registerOreDict();
|
||||
Core.logHelper.info("TechReborns Blocks Loaded");
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package techreborn.powernet;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IPowerCableContainer {
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getPos();
|
||||
|
||||
boolean canConnectTo(EnumFacing facing);
|
||||
|
||||
PowerCable getPowerCable();
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
package techreborn.powernet;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PowerCable {
|
||||
|
||||
List<PowerNode> nodes = new ArrayList<PowerNode>();
|
||||
|
||||
IPowerCableContainer container;
|
||||
|
||||
PowerNetwork network;
|
||||
|
||||
public PowerCable(IPowerCableContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public void blockUpdate(){
|
||||
checkNodes();
|
||||
}
|
||||
|
||||
public void checkNodes(){
|
||||
nodes.clear();
|
||||
for(EnumFacing dir : EnumFacing.VALUES){
|
||||
if(!container.canConnectTo(dir)){
|
||||
continue;
|
||||
}
|
||||
BlockPos blockPos = container.getPos().offset(dir);
|
||||
if(container.getWorld().isBlockLoaded(blockPos)){
|
||||
TileEntity tileEntity = container.getWorld().getTileEntity(blockPos);
|
||||
if(network != null){
|
||||
if(tileEntity instanceof IPowerCableContainer){
|
||||
IPowerCableContainer powerCableContainer = (IPowerCableContainer) tileEntity;
|
||||
if(powerCableContainer.getPowerCable() != null && powerCableContainer.getPowerCable().network != network){
|
||||
network.merge(powerCableContainer.getPowerCable().network);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!(tileEntity instanceof IEnergyInterfaceTile)){
|
||||
continue;
|
||||
}
|
||||
IEnergyInterfaceTile energyInterfaceTile = (IEnergyInterfaceTile) tileEntity;
|
||||
PowerNode node = new PowerNode(blockPos, tileEntity, dir);
|
||||
if(energyInterfaceTile.canAcceptEnergy(dir)){
|
||||
// This tile will be classed as a receiver
|
||||
node.type = PowerType.RECEIVER;
|
||||
} else if(energyInterfaceTile.canProvideEnergy(dir)){
|
||||
//This tile can then provide
|
||||
node.type = PowerType.COLLECTOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PowerNetwork getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public void setNetwork(PowerNetwork network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public void removeCable(){
|
||||
network.removeCable(this);
|
||||
this.network = null;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package techreborn.powernet;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PowerEvent extends Event {
|
||||
|
||||
World world;
|
||||
|
||||
public static List<PowerNetwork> networks = new ArrayList<>();
|
||||
|
||||
public PowerEvent(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public PowerEvent() {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void worldTick(TickEvent.WorldTickEvent event){
|
||||
MinecraftForge.EVENT_BUS.post(new PowerEvent(event.world));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void worldUnload(WorldEvent.Unload event){
|
||||
List<PowerNetwork> deadNetworks = new ArrayList<>();
|
||||
for(PowerNetwork network : networks){
|
||||
if(network.cables.size() != 0){
|
||||
if(network.cables.get(0).container.getWorld() == event.world){
|
||||
MinecraftForge.EVENT_BUS.unregister(network);
|
||||
deadNetworks.add(network);
|
||||
}
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.unregister(network);
|
||||
deadNetworks.add(network);
|
||||
}
|
||||
}
|
||||
networks.removeAll(deadNetworks);
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package techreborn.powernet;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PowerNetwork {
|
||||
|
||||
List<PowerCable> cables = new ArrayList<>();
|
||||
|
||||
int networkPower;
|
||||
|
||||
double maxTransfer = 128;
|
||||
|
||||
public PowerNetwork() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public PowerNetwork merge(PowerNetwork network){
|
||||
cables.addAll(network.cables);
|
||||
for(PowerCable cable : network.cables){
|
||||
cable.setNetwork(this);
|
||||
}
|
||||
network.destoryNetwork();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void destoryNetwork(){
|
||||
cables.clear();
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
|
||||
public void addCable(PowerCable cable){
|
||||
cables.add(cable);
|
||||
cable.setNetwork(this);
|
||||
}
|
||||
|
||||
public void removeCable(PowerCable cable){
|
||||
cables.remove(cable);
|
||||
cable.setNetwork(null);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(PowerEvent event){
|
||||
World world = event.world;
|
||||
if(cables.size() == 0){
|
||||
destoryNetwork();
|
||||
return;
|
||||
}
|
||||
for(PowerCable cable : cables){
|
||||
if(cable.container.getWorld() == world){
|
||||
for(PowerNode node : cable.nodes){
|
||||
TileEntity tileEntity = node.nodeTile;
|
||||
if(!(tileEntity instanceof IEnergyInterfaceTile)){
|
||||
continue;
|
||||
}
|
||||
IEnergyInterfaceTile iEnergyInterfaceTile = (IEnergyInterfaceTile) tileEntity;
|
||||
switch (node.type){
|
||||
case COLLECTOR:
|
||||
if(iEnergyInterfaceTile.canProvideEnergy(node.facingFromCable)){
|
||||
double transfer = Math.min(maxTransfer, Math.min(iEnergyInterfaceTile.getMaxOutput(), iEnergyInterfaceTile.getEnergy()));
|
||||
networkPower += iEnergyInterfaceTile.useEnergy(transfer);
|
||||
}
|
||||
break;
|
||||
case RECEIVER:
|
||||
if(iEnergyInterfaceTile.canAcceptEnergy(node.facingFromCable)){
|
||||
double transfer = Math.min(maxTransfer, Math.min(iEnergyInterfaceTile.getMaxOutput(), iEnergyInterfaceTile.getEnergy()));
|
||||
networkPower -= iEnergyInterfaceTile.addEnergy(transfer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(networkPower + "cables:" + cables.size() + ":" + this);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package techreborn.powernet;
|
||||
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class PowerNode {
|
||||
|
||||
BlockPos nodePos;
|
||||
|
||||
TileEntity nodeTile;
|
||||
|
||||
PowerType type = PowerType.UNKNOWN;
|
||||
|
||||
EnumFacing facingFromCable;
|
||||
|
||||
public PowerNode(BlockPos nodePos, TileEntity nodeTile, EnumFacing facingFromCable) {
|
||||
this.nodePos = nodePos;
|
||||
this.nodeTile = nodeTile;
|
||||
this.facingFromCable = facingFromCable;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package techreborn.powernet;
|
||||
|
||||
|
||||
public enum PowerType {
|
||||
COLLECTOR,
|
||||
RECEIVER,
|
||||
UNKNOWN
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package techreborn.tiles;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import techreborn.powernet.IPowerCableContainer;
|
||||
import techreborn.powernet.PowerCable;
|
||||
import techreborn.powernet.PowerEvent;
|
||||
import techreborn.powernet.PowerNetwork;
|
||||
|
||||
|
||||
public class TileCable extends TileEntity implements IPowerCableContainer, ITickable{
|
||||
|
||||
PowerCable cable = null;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canConnectTo(EnumFacing facing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerCable getPowerCable() {
|
||||
return cable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(cable == null){
|
||||
createCable();
|
||||
} else {
|
||||
cable.checkNodes();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createCable(){
|
||||
if(cable != null){
|
||||
cable.getNetwork().removeCable(cable);
|
||||
cable = null;
|
||||
}
|
||||
PowerNetwork network = new PowerNetwork();
|
||||
cable = new PowerCable(this);
|
||||
cable.setNetwork(network);
|
||||
network.addCable(cable);
|
||||
cable.checkNodes();
|
||||
}
|
||||
|
||||
public void onRemoved(){
|
||||
if(cable != null){
|
||||
cable.removeCable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
onRemoved();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue