implemented re-eval for power nets

this should keep power nets intact when links (i.e. cables) are removed instead of outright destroying them they are re-calculated. this should keep unloaded and cached links intact which would otherwise not reconnect on their own.
This commit is contained in:
Bob 2022-03-22 14:48:02 +01:00
parent 8c005a39fb
commit c662895f8e
23 changed files with 2397 additions and 2069 deletions

View File

@ -1,6 +1,11 @@
package api.hbm.energy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
/**
* 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.
@ -17,14 +22,76 @@ public interface IEnergyConductor extends IEnergyConnector {
* @return
*/
public default int getIdentity() {
TileEntity te = (TileEntity) this;
return getIdentityFromTile((TileEntity) this);
}
public static int getIdentityFromTile(TileEntity te) {
return getIdentityFromPos(te.xCoord, te.yCoord, te.zCoord);
}
public static int getIdentityFromPos(int x, int y, int z) {
final int prime = 31;
int result = 1;
result = prime * result + te.xCoord;
result = prime * result + te.yCoord;
result = prime * result + te.zCoord;
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
/**
* Whether the link should be part of reeval when the network is changed.
* I.e. if this link should join any of the new networks (FALSE for switches that are turned off for example)
* @return
*/
public default boolean canReevaluate() {
return !((TileEntity) this).isInvalid();
}
/**
* When a link leaves the network, the net has to manually calculate the resulting networks.
* Each link has to decide what other links will join the same net.
* @param copy
*/
public default void reevaluate(HashMap<Integer, IEnergyConductor> copy) {
for(int[] pos : getConnectionPoints()) {
int newX = pos[0];
int newY = pos[1];
int newZ = pos[2];
int id = IEnergyConductor.getIdentityFromPos(newX, newY, newZ);
IEnergyConductor neighbor = copy.get(id);
if(neighbor != null && neighbor.getPowerNet() != null && this.canReevaluate() && neighbor.canReevaluate()) {
if(this.getPowerNet() == null) {
neighbor.getPowerNet().joinLink(this);
} else {
this.getPowerNet().joinNetworks(neighbor.getPowerNet());
}
}
}
}
/**
* Creates a list of positions for the reeval process. In short - what positions should be considered as connected.
* Also used by pylons to quickly figure out what positions to connect to.
* DEFAULT: Connects to all six neighboring blocks.
* @return
*/
public default List<int[]> getConnectionPoints() {
List<int[]> pos = new ArrayList();
TileEntity tile = (TileEntity) this;
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
int newX = tile.xCoord + dir.offsetX;
int newY = tile.yCoord + dir.offsetY;
int newZ = tile.zCoord + dir.offsetZ;
pos.add(new int[] {newX, newY, newZ});
}
return pos;
}
}

View File

@ -1,6 +1,7 @@
package api.hbm.energy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
@ -13,7 +14,7 @@ import net.minecraft.tileentity.TileEntity;
public class PowerNet implements IPowerNet {
private boolean valid = true;
private List<IEnergyConductor> links = new ArrayList();
private HashMap<Integer, IEnergyConductor> links = new HashMap();
private List<IEnergyConnector> subscribers = new ArrayList();
@Override
@ -23,8 +24,7 @@ public class PowerNet implements IPowerNet {
return; //wtf?!
for(IEnergyConductor conductor : network.getLinks()) {
conductor.setPowerNet(this);
this.getLinks().add(conductor);
joinLink(conductor);
}
network.getLinks().clear();
@ -42,14 +42,14 @@ public class PowerNet implements IPowerNet {
conductor.getPowerNet().leaveLink(conductor);
conductor.setPowerNet(this);
this.getLinks().add(conductor);
this.links.put(conductor.getIdentity(), conductor);
return this;
}
@Override
public void leaveLink(IEnergyConductor conductor) {
conductor.setPowerNet(null);
this.getLinks().remove(conductor);
this.links.remove(conductor.getIdentity());
}
@Override
@ -69,7 +69,9 @@ public class PowerNet implements IPowerNet {
@Override
public List<IEnergyConductor> getLinks() {
return this.links;
List<IEnergyConductor> linkList = new ArrayList();
linkList.addAll(this.links.values());
return linkList;
}
@Override
@ -80,10 +82,9 @@ public class PowerNet implements IPowerNet {
@Override
public void destroy() {
this.valid = false;
this.subscribers.clear();
for(IEnergyConductor link : this.links) {
for(IEnergyConductor link : this.links.values()) {
link.setPowerNet(null);
}
@ -135,5 +136,22 @@ public class PowerNet implements IPowerNet {
}
@Override
public void reevaluate() { }
public void reevaluate() {
HashMap<Integer, IEnergyConductor> copy = new HashMap(links);
for(IEnergyConductor link : copy.values()) {
this.leaveLink(link);
}
for(IEnergyConductor link : copy.values()) {
link.setPowerNet(null);
link.reevaluate(copy);
if(link.getPowerNet() == null) {
link.setPowerNet(new PowerNet().joinLink(link));
}
}
}
}

View File

@ -2,9 +2,9 @@ package api.hbm.fluid;
import com.hbm.inventory.fluid.FluidType;
public interface IFluidConductor {
public interface IFluidConductor extends IFluidConnector {
public IPipeNet getPipeNet(FluidType type);
public void setPipeNet(FluidType type, FluidType network);
public void setPipeNet(FluidType type, IPipeNet network);
}

View File

@ -1,7 +1,13 @@
package api.hbm.fluid;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.packet.AuxParticlePacketNT;
import com.hbm.packet.PacketDispatcher;
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 IFluidConnector {
@ -28,4 +34,51 @@ public interface IFluidConnector {
* @return
*/
public int getDemand(FluidType type);
/**
* Basic implementation of subscribing to a nearby power grid
* @param world
* @param x
* @param y
* @param z
*/
public default void trySubscribe(FluidType type, World world, int x, int y, int z, ForgeDirection dir) {
TileEntity te = world.getTileEntity(x, y, z);
boolean red = false;
if(te instanceof IFluidConductor) {
IFluidConductor con = (IFluidConductor) te;
if(!con.canConnect(type, dir))
return;
if(con.getPipeNet(type) != null && !con.getPipeNet(type).isSubscribed(this))
con.getPipeNet(type).subscribe(this);
if(con.getPipeNet(type) != null)
red = true;
}
if(particleDebug) {
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaExt");
data.setString("mode", red ? "reddust" : "bluedust");
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, x + world.rand.nextDouble(), y + world.rand.nextDouble(), z + world.rand.nextDouble()), new TargetPoint(world.provider.dimensionId, x + 0.5, y + 0.5, z + 0.5, 25));
}
}
public default void tryUnsubscribe(FluidType type, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof IFluidConductor) {
IFluidConductor con = (IFluidConductor) te;
if(con.getPipeNet(type) != null && con.getPipeNet(type).isSubscribed(this))
con.getPipeNet(type).unsubscribe(this);
}
}
public static final boolean particleDebug = false;
}

View File

@ -0,0 +1,13 @@
package api.hbm.fluid;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public interface IFluidUser extends IFluidConnector {
/*public default void updateStandardPipes(World world, int x, int y, int z) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
this.trySubscribe(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir);
}*/
}

View File

@ -1,8 +1,27 @@
package api.hbm.fluid;
import api.hbm.energy.IPowerNet;
import java.util.List;
import com.hbm.inventory.fluid.FluidType;
public interface IPipeNet {
public void joinNetworks(IPowerNet network);
public void joinNetworks(IPipeNet network);
public List<IFluidConductor> getLinks();
public List<IFluidConnector> getSubscribers();
public IPipeNet joinLink(IFluidConductor conductor);
public void leaveLink(IFluidConductor conductor);
public void subscribe(IFluidConnector connector);
public void unsubscribe(IFluidConnector connector);
public boolean isSubscribed(IFluidConnector connector);
public void destroy();
public boolean isValid();
public long transferFluid(long power);
public FluidType getType();
}

View File

@ -0,0 +1,99 @@
package api.hbm.fluid;
import java.util.ArrayList;
import java.util.List;
import com.hbm.inventory.fluid.FluidType;
public class PipeNet implements IPipeNet {
private FluidType type;
private List<IFluidConductor> links = new ArrayList();
private List<IFluidConnector> subscribers = new ArrayList();
public PipeNet(FluidType type) {
this.type = type;
}
@Override
public void joinNetworks(IPipeNet network) {
if(network == this)
return;
for(IFluidConductor conductor : network.getLinks()) {
conductor.setPipeNet(type, this);
this.getLinks().add(conductor);
}
network.getLinks().clear();
for(IFluidConnector connector : network.getSubscribers()) {
this.subscribe(connector);
}
network.destroy();
}
@Override
public List<IFluidConductor> getLinks() {
return links;
}
@Override
public List<IFluidConnector> getSubscribers() {
return subscribers;
}
@Override
public IPipeNet joinLink(IFluidConductor conductor) {
// TODO Auto-generated method stub
return null;
}
@Override
public void leaveLink(IFluidConductor conductor) {
// TODO Auto-generated method stub
}
@Override
public void subscribe(IFluidConnector connector) {
// TODO Auto-generated method stub
}
@Override
public void unsubscribe(IFluidConnector connector) {
// TODO Auto-generated method stub
}
@Override
public boolean isSubscribed(IFluidConnector connector) {
// TODO Auto-generated method stub
return false;
}
@Override
public long transferFluid(long power) {
// TODO Auto-generated method stub
return 0;
}
@Override
public FluidType getType() {
return type;
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public boolean isValid() {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -50,6 +50,7 @@ public class ModBlocks {
public static Block test_core;
public static Block test_charge;
public static Block test_conductor;
public static Block test_pipe;
public static Block test_ct;
public static Block test_rail;
public static Block test_bb_bork;
@ -1252,6 +1253,7 @@ public class ModBlocks {
test_core = new TestCore(Material.iron).setBlockName("test_core").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_core");
test_charge = new TestCharge(Material.iron).setBlockName("test_charge").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F);
test_conductor = new TestConductor(Material.iron).setBlockName("test_conductor").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cable_neo");
test_pipe = new TestPipe(Material.iron).setBlockName("test_pipe").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":pipe_neo");
test_ct = new TestCT(Material.iron).setBlockName("test_ct").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_ct");
test_rail = new TestRail(Material.iron).setBlockName("test_rail").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_rail");
test_bb_bork = new TestBB(Material.iron).setBlockName("test_bb_bork").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_bb_bork");
@ -2260,6 +2262,7 @@ public class ModBlocks {
GameRegistry.registerBlock(test_core, test_core.getUnlocalizedName());
GameRegistry.registerBlock(test_charge, test_charge.getUnlocalizedName());
GameRegistry.registerBlock(test_conductor, test_conductor.getUnlocalizedName());
GameRegistry.registerBlock(test_pipe, test_pipe.getUnlocalizedName());
GameRegistry.registerBlock(test_ct, test_ct.getUnlocalizedName());
GameRegistry.registerBlock(test_rail, test_rail.getUnlocalizedName());
GameRegistry.registerBlock(test_bb_bork, test_bb_bork.getUnlocalizedName());

View File

@ -1,7 +1,5 @@
package com.hbm.blocks.test;
import com.hbm.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@ -9,10 +7,5 @@ public class TestBB extends Block {
public TestBB(Material mat) {
super(mat);
if(this == ModBlocks.test_bb_bork)
this.setBlockBounds(-1000F, -1000F, -1000F, 1001F, 1001F, 1001F);
else
this.setBlockBounds(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
}
}

View File

@ -0,0 +1,38 @@
package com.hbm.blocks.test;
import com.hbm.tileentity.network.TileEntityPipeBaseNT;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TestPipe extends BlockContainer {
public TestPipe(Material mat) {
super(mat);
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileEntityPipeBaseNT();
}
public static int renderID = RenderingRegistry.getNextAvailableRenderId();
@Override
public int getRenderType() {
return renderID;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
}

View File

@ -441,7 +441,6 @@ public class EntityEffectHandler {
ItemStack armorStack = player.inventory.armorInventory[armorSlot];
if(armorStack != null && armorStack.getItem() instanceof ItemArmor) {
ItemArmor armor = (ItemArmor)armorStack.getItem();
for(int modSlot = 0; modSlot < 8; modSlot++) {
ItemStack mod = ArmorModHandler.pryMods(armorStack)[modSlot];
@ -472,10 +471,18 @@ public class EntityEffectHandler {
if(props.getDashCooldown() <= 0) {
if(!player.capabilities.isFlying && player.isSneaking() && stamina >= perDash) {
Vec3 lookingIn = player.getLookVec();
player.addVelocity(lookingIn.xCoord, 0, lookingIn.zCoord);
Vec3 lookingIn = player.getLookVec();
Vec3 strafeVec = player.getLookVec();
strafeVec.rotateAroundY((float)Math.PI * 0.5F);
int forward = (int) Math.signum(player.moveForward);
int strafe = (int) Math.signum(player.moveStrafing);
if(forward == 0 && strafe == 0)
forward = 1;
player.addVelocity(lookingIn.xCoord * forward + strafeVec.xCoord * strafe, 0, lookingIn.zCoord * forward + strafeVec.zCoord * strafe);
player.playSound("hbm:player.dash", 1.0F, 1.0F);
props.setDashCooldown(HbmPlayerProps.dashCooldownLength);

View File

@ -5,7 +5,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.dispenser.BehaviorProjectileDispense;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.IProjectile;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
@ -72,7 +71,6 @@ import com.hbm.tileentity.bomb.TileEntityNukeCustom;
import com.hbm.tileentity.machine.*;
import com.hbm.tileentity.machine.rbmk.RBMKDials;
import com.hbm.util.ArmorUtil;
import com.hbm.world.feature.OreLayer;
import com.hbm.world.feature.SchistStratum;
import com.hbm.world.generator.CellularDungeonFactory;

View File

@ -62,6 +62,7 @@ import com.hbm.util.EntityDamageUtil;
import com.hbm.world.WorldProviderNTM;
import com.hbm.world.generator.TimedGenerator;
import api.hbm.energy.IEnergyConductor;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -1160,6 +1161,17 @@ public class ModEventHandler {
}
/// PU RADIATION END ///
if(player instanceof EntityPlayerMP) {
int x = (int) Math.floor(player.posX);
int y = (int) Math.floor(player.posY - 0.01);
int z = (int) Math.floor(player.posZ);
if(player.worldObj.getTileEntity(x, y, z) instanceof IEnergyConductor) {
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(((IEnergyConductor) player.worldObj.getTileEntity(x, y, z)).getPowerNet() + ""), (EntityPlayerMP) player);
}
}
/// NEW ITEM SYS START ///
HazardSystem.updatePlayerInventory(player);

View File

@ -59,6 +59,7 @@ import com.hbm.util.ArmorUtil;
import com.hbm.util.ArmorRegistry.HazardClass;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import api.hbm.energy.IEnergyConductor;
import api.hbm.item.IButtonReceiver;
import api.hbm.item.IClickReceiver;
@ -245,13 +246,16 @@ public class ModEventHandlerClient {
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
}
}
if(!event.isCanceled() && event.type == event.type.HOTBAR) {
HbmPlayerProps props = HbmPlayerProps.getData(player);
if(props.getDashCount() > 0) {
RenderScreenOverlay.renderDashBar(event.resolution, Minecraft.getMinecraft().ingameGUI, props);
}
}
}

View File

@ -291,7 +291,7 @@ public class TileEntityMachineMiningDrill extends TileEntityMachineBase implemen
Block b = worldObj.getBlock(x, y, z);
float hardness = b.getBlockHardness(worldObj, x, y, z);
return hardness < 70 && hardness >= 0;
return (hardness < 70 && hardness >= 0) || b instanceof IDrillInteraction;
}
/**

View File

@ -56,7 +56,8 @@ public class TileEntityCableBaseNT extends TileEntity implements IEnergyConducto
if(!worldObj.isRemote) {
if(this.network != null) {
this.network.destroy();
this.network.reevaluate();
this.network = null;
}
}
}

View File

@ -14,7 +14,7 @@ public class TileEntityCableSwitch extends TileEntityCableBaseNT {
//if the meta is 0 (OFF) and there is a net present, destroy and de-reference it.
//that should be all, since the state being 0 also prevents the TE from updating and joining the new net.
if(this.getBlockMetadata() == 0 && this.network != null) {
this.network.destroy();
this.network.reevaluate();
this.network = null;
}
@ -26,4 +26,8 @@ public class TileEntityCableSwitch extends TileEntityCableBaseNT {
}
}
}
public boolean canReevaluate() {
return super.canReevaluate() && this.getBlockMetadata() == 1;
}
}

View File

@ -0,0 +1,96 @@
package com.hbm.tileentity.network;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import api.hbm.fluid.IFluidConductor;
import api.hbm.fluid.IPipeNet;
import api.hbm.fluid.PipeNet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityPipeBaseNT extends TileEntity implements IFluidConductor {
private IPipeNet network;
protected FluidType type = Fluids.NONE;
@Override
public void updateEntity() {
if(!worldObj.isRemote && canUpdate()) {
//we got here either because the net doesn't exist or because it's not valid, so that's safe to assume
this.setPipeNet(type, null);
this.connect();
if(this.getPipeNet(type) == null) {
this.setPipeNet(type, new PipeNet(type).joinLink(this));
}
}
}
protected void connect() {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if(te instanceof IFluidConductor) {
IFluidConductor conductor = (IFluidConductor) te;
if(!conductor.canConnect(type, dir.getOpposite()))
continue;
if(this.getPipeNet(type) == null && conductor.getPipeNet(type) != null) {
conductor.getPipeNet(type).joinLink(this);
}
if(this.getPipeNet(type) != null && conductor.getPipeNet(type) != null && this.getPipeNet(type) != conductor.getPipeNet(type)) {
conductor.getPipeNet(type).joinNetworks(this.getPipeNet(type));
}
}
}
}
@Override
public void invalidate() {
super.invalidate();
if(!worldObj.isRemote) {
if(this.network != null) {
this.network.destroy();
}
}
}
/**
* 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 (this.network == null || !this.network.isValid()) && !this.isInvalid();
}
@Override
public int transferFluid(FluidType type, int fluid) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getDemand(FluidType type) {
return 0;
}
@Override
public IPipeNet getPipeNet(FluidType type) {
return type == this.type ? this.network : null;
}
@Override
public void setPipeNet(FluidType type, IPipeNet network) {
this.network = network;
}
}

View File

@ -1,7 +1,8 @@
package com.hbm.tileentity.network;
import api.hbm.energy.IEnergyConductor;
import net.minecraft.tileentity.TileEntity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
@ -23,31 +24,12 @@ public class TileEntityPylon extends TileEntityPylonBase {
}
@Override
protected void connect() {
/*
* Apparently super.super does not exist, and the mentally damaged folk from heckoverflow pretend like that's a good thing.
* Look at this shit, you think that's good? "Write Everything Twice"? You like that, huh?
*/
public List<int[]> getConnectionPoints() {
List<int[]> pos = new ArrayList(connected);
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if(te instanceof IEnergyConductor) {
IEnergyConductor conductor = (IEnergyConductor) te;
if(this.getPowerNet() == null && conductor.getPowerNet() != null) {
conductor.getPowerNet().joinLink(this);
}
if(this.getPowerNet() != null && conductor.getPowerNet() != null && this.getPowerNet() != conductor.getPowerNet()) {
conductor.getPowerNet().joinNetworks(this.getPowerNet());
}
}
pos.add(new int[] {xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ});
}
super.connect();
return pos;
}
}

View File

@ -46,8 +46,8 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
connected.add(new int[] {x, y, z});
if(this.getPowerNet() != null) {
this.getPowerNet().destroy();
this.setPowerNet(null);
this.getPowerNet().reevaluate();
this.network = null;
}
this.markDirty();
@ -92,7 +92,7 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
@Override
protected void connect() {
for(int[] pos : connected) {
for(int[] pos : getConnectionPoints()) {
TileEntity te = worldObj.getTileEntity(pos[0], pos[1], pos[2]);
@ -111,6 +111,11 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
}
}
@Override
public List<int[]> getConnectionPoints() {
return new ArrayList(connected);
}
public abstract ConnectionType getConnectionType();
public abstract Vec3[] getMountPos();
public abstract double getMaxWireLength();

View File

@ -1,9 +1,10 @@
package com.hbm.tileentity.network;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.BlockDummyable;
import api.hbm.energy.IEnergyConductor;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
public class TileEntitySubstation extends TileEntityPylonBase {
@ -45,33 +46,16 @@ public class TileEntitySubstation extends TileEntityPylonBase {
}
@Override
protected void connect() {
manageNets(worldObj.getTileEntity(xCoord + 2, yCoord, zCoord - 1));
manageNets(worldObj.getTileEntity(xCoord + 2, yCoord, zCoord + 1));
manageNets(worldObj.getTileEntity(xCoord - 2, yCoord, zCoord - 1));
manageNets(worldObj.getTileEntity(xCoord - 2, yCoord, zCoord + 1));
manageNets(worldObj.getTileEntity(xCoord - 1, yCoord, zCoord + 2));
manageNets(worldObj.getTileEntity(xCoord + 1, yCoord, zCoord + 2));
manageNets(worldObj.getTileEntity(xCoord - 1, yCoord, zCoord - 2));
manageNets(worldObj.getTileEntity(xCoord + 1, yCoord, zCoord - 2));
super.connect();
}
private void manageNets(TileEntity te) {
if(te instanceof IEnergyConductor) {
IEnergyConductor conductor = (IEnergyConductor) te;
if(this.getPowerNet() == null && conductor.getPowerNet() != null) {
conductor.getPowerNet().joinLink(this);
}
if(this.getPowerNet() != null && conductor.getPowerNet() != null && this.getPowerNet() != conductor.getPowerNet()) {
conductor.getPowerNet().joinNetworks(this.getPowerNet());
}
}
public List<int[]> getConnectionPoints() {
List<int[]> pos = new ArrayList(connected);
pos.add(new int[] {xCoord + 2, yCoord, zCoord - 1});
pos.add(new int[] {xCoord + 2, yCoord, zCoord + 1});
pos.add(new int[] {xCoord - 2, yCoord, zCoord - 1});
pos.add(new int[] {xCoord - 2, yCoord, zCoord + 1});
pos.add(new int[] {xCoord - 1, yCoord, zCoord + 2});
pos.add(new int[] {xCoord + 1, yCoord, zCoord + 2});
pos.add(new int[] {xCoord - 1, yCoord, zCoord - 2});
pos.add(new int[] {xCoord + 1, yCoord, zCoord - 2});
return pos;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -5,20 +5,20 @@
"misc.nullMine": {"category": "player", "sounds": [{"name": "misc/null", "stream": false}]},
"block.crateBreak": {"category": "block", "sounds": ["block/crateBreak1", "block/crateBreak2", "block/crateBreak3", "block/crateBreak4", "block/crateBreak5"]},
"block.shutdown": {"category": "ntmMachines", "sounds": [{"name": "block/shutdown", "stream": true}]},
"block.minerOperate": {"category": "ntmMachines", "sounds": [{"name": "block/minerOperate", "stream": true}]},
"block.assemblerOperate": {"category": "ntmMachines", "sounds": [{"name": "block/assemblerOperate", "stream": true}]},
"block.chemplantOperate": {"category": "ntmMachines", "sounds": [{"name": "block/chemplantOperate", "stream": true}]},
"block.dieselOperate": {"category": "ntmMachines", "sounds": [{"name": "block/dieselOperate", "stream": true}]},
"block.igeneratorOperate": {"category": "ntmMachines", "sounds": [{"name": "block/igeneratorOperate", "stream": true}]},
"block.turbofanOperate": {"category": "ntmMachines", "sounds": [{"name": "block/turbofanOperate", "stream": true}]},
"block.pressOperate": {"category": "ntmMachines", "sounds": [{"name": "block/pressOperate", "stream": false}]},
"block.shutdown": {"category": "block", "sounds": [{"name": "block/shutdown", "stream": true}]},
"block.minerOperate": {"category": "block", "sounds": [{"name": "block/minerOperate", "stream": true}]},
"block.assemblerOperate": {"category": "block", "sounds": [{"name": "block/assemblerOperate", "stream": true}]},
"block.chemplantOperate": {"category": "block", "sounds": [{"name": "block/chemplantOperate", "stream": true}]},
"block.dieselOperate": {"category": "block", "sounds": [{"name": "block/dieselOperate", "stream": true}]},
"block.igeneratorOperate": {"category": "block", "sounds": [{"name": "block/igeneratorOperate", "stream": true}]},
"block.turbofanOperate": {"category": "block", "sounds": [{"name": "block/turbofanOperate", "stream": true}]},
"block.pressOperate": {"category": "block", "sounds": [{"name": "block/pressOperate", "stream": false}]},
"block.broadcast1": {"category": "block", "sounds": [{"name": "block/broadcast1", "stream": true}]},
"block.broadcast2": {"category": "block", "sounds": [{"name": "block/broadcast2", "stream": true}]},
"block.broadcast3": {"category": "block", "sounds": [{"name": "block/broadcast3", "stream": true}]},
"block.sonarPing": {"category": "ntmMachines", "sounds": [{"name": "block/sonarPing", "stream": false}]},
"block.reactorStart": {"category": "ntmMachines", "sounds": [{"name": "block/reactorStart", "stream": false}]},
"block.reactorStop": {"category": "ntmMachines", "sounds": [{"name": "block/reactorStop", "stream": false}]},
"block.sonarPing": {"category": "block", "sounds": [{"name": "block/sonarPing", "stream": false}]},
"block.reactorStart": {"category": "block", "sounds": [{"name": "block/reactorStart", "stream": false}]},
"block.reactorStop": {"category": "block", "sounds": [{"name": "block/reactorStop", "stream": false}]},
"block.vaultScrape": {"category": "block", "sounds": [{"name": "block/vaultScrape", "stream": false}]},
"block.vaultThud": {"category": "block", "sounds": [{"name": "block/vaultThud", "stream": false}]},
"block.vaultScrapeNew": {"category": "block", "sounds": [{"name": "block/vaultScrapeNew", "stream": false}]},
@ -26,17 +26,17 @@
"block.lockOpen": {"category": "block", "sounds": [{"name": "block/lockOpen", "stream": false}]},
"block.lockHang": {"category": "block", "sounds": [{"name": "block/lockHang", "stream": false}]},
"block.debris": {"category": "block", "sounds": ["block/debris1", "block/debris2", "block/debris3"]},
"block.centrifugeOperate": {"category": "ntmMachines", "sounds": [{"name": "block/centrifugeOperate", "stream": true}]},
"block.centrifugeOperate": {"category": "block", "sounds": [{"name": "block/centrifugeOperate", "stream": true}]},
"block.pipePlaced": {"category": "block", "sounds": [{"name": "block/pipePlaced", "stream": false}]},
"block.missileAssembly": {"category": "ntmMachines", "sounds": [{"name": "block/missileAssembly", "stream": false}]},
"block.missileAssembly2": {"category": "ntmMachines", "sounds": [{"name": "block/missileAssembly2", "stream": false}]},
"block.missileAssembly": {"category": "block", "sounds": [{"name": "block/missileAssembly", "stream": false}]},
"block.missileAssembly2": {"category": "block", "sounds": [{"name": "block/missileAssembly2", "stream": false}]},
"block.openDoor": {"category": "block", "sounds": ["block/door_open_1", "block/door_open_2"]},
"block.closeDoor": {"category": "block", "sounds": ["block/door_close_1", "block/door_close_2"]},
"block.soyuzReady": {"category": "ntmMachines", "sounds": [{"name": "block/soyuzReady", "stream": true}]},
"block.soyuzReady": {"category": "block", "sounds": [{"name": "block/soyuzReady", "stream": true}]},
"block.screm": {"category": "block", "sounds": ["screm/scream1", "screm/scream01", "screm/scream2", "screm/scream02", "screm/scream3", "screm/scream03", "screm/scream4", "screm/scream04", "screm/scream5", "screm/scream05", "screm/scream6", "screm/scream06", "screm/scream7", "screm/scream07", "screm/scream08", "screm/scream09", "screm/scream10", "screm/scream11", "screm/scream12", "screm/scream13", "screm/scream14", "screm/scream15", "screm/scream16", "screm/scream17", "screm/scream18", "screm/scream19", "screm/scream20", "screm/scream21", "screm/scream22", "screm/scream23", "screm/scream24", "screm/scream25"]},
"block.rbmk_explosion": {"category": "block", "sounds": [{"name": "block/rbmk_explosion", "stream": false}]},
"block.rbmk_az5_cover": {"category": "block", "sounds": [{"name": "block/rbmk_az5_cover", "stream": false}]},
"block.chungusLever": {"category": "ntmMachines", "sounds": [{"name": "block/chungusLever", "stream": false}]},
"block.chungusLever": {"category": "block", "sounds": [{"name": "block/chungusLever", "stream": false}]},
"block.bobble": {"category": "block", "sounds": [{"name": "block/bobble", "stream": false}]},
"item.techBleep": {"category": "player", "sounds": [{"name": "tool/techBleep", "stream": false}]},