NEITHER SNOW NOR RAIN NOR THE GLOOM OF NIGHT

This commit is contained in:
Bob 2024-04-11 21:58:47 +02:00
parent c16818c15d
commit e5dffd3d2a
10 changed files with 138 additions and 220 deletions

View File

@ -79,13 +79,8 @@ public class Nodespace {
if(conNode.hasValidNet() && conNode.net == node.net) continue; // if the net is valid and both nodes have the same net, skip if(conNode.hasValidNet() && conNode.net == node.net) continue; // if the net is valid and both nodes have the same net, skip
for(DirPos revCon : conNode.connections) { // check if neighbor node also has a valid reverse connection if(checkConnection(conNode, con, false)) {
connectToNode(node, conNode);
// god i hope i didn't fuck this up my brain is hurting already
if(revCon.getX() - revCon.getDir().offsetX == con.getX() && revCon.getY() - revCon.getDir().offsetY == con.getY() && revCon.getZ() - revCon.getDir().offsetZ == con.getZ() && revCon.getDir() == con.getDir().getOpposite()) {
connectToNode(node, conNode);
break;
}
} }
} }
} }
@ -93,6 +88,18 @@ public class Nodespace {
if(node.net == null || !node.net.isValid()) new PowerNetMK2().joinLink(node); if(node.net == null || !node.net.isValid()) new PowerNetMK2().joinLink(node);
} }
public static boolean checkConnection(PowerNode connectsTo, DirPos connectFrom, boolean skipSideCheck) {
for(DirPos revCon : connectsTo.connections) {
if(revCon.getX() - revCon.getDir().offsetX == connectFrom.getX() && revCon.getY() - revCon.getDir().offsetY == connectFrom.getY() && revCon.getZ() - revCon.getDir().offsetZ == connectFrom.getZ() && (revCon.getDir() == connectFrom.getDir().getOpposite() || skipSideCheck)) {
return true;
}
}
return false;
}
/** Links two nodes with different or potentially no networks */ /** Links two nodes with different or potentially no networks */
private static void connectToNode(PowerNode origin, PowerNode connection) { private static void connectToNode(PowerNode origin, PowerNode connection) {
@ -166,6 +173,14 @@ public class Nodespace {
return this; return this;
} }
public PowerNode addConnection(DirPos connection) {
DirPos[] newCons = new DirPos[this.connections.length + 1];
for(int i = 0; i < this.connections.length; i++) newCons[i] = this.connections[i];
newCons[newCons.length - 1] = connection;
this.connections = newCons;
return this;
}
public boolean hasValidNet() { public boolean hasValidNet() {
return this.net != null && this.net.isValid(); return this.net != null && this.net.isValid();
} }

View File

@ -177,6 +177,10 @@ public class PowerNetMK2 {
} }
} }
public long sendPowerDiode(long power) {
return power;
}
public static final ReceiverComparator COMP = new ReceiverComparator(); public static final ReceiverComparator COMP = new ReceiverComparator();
public static class ReceiverComparator implements Comparator<IEnergyReceiverMK2> { public static class ReceiverComparator implements Comparator<IEnergyReceiverMK2> {

View File

@ -8,9 +8,14 @@ import com.hbm.blocks.ITooltipProvider;
import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.tileentity.TileEntityLoadedBase;
import com.hbm.util.BobMathUtil; import com.hbm.util.BobMathUtil;
import com.hbm.util.I18nUtil; import com.hbm.util.I18nUtil;
import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.block.IToolable; import api.hbm.block.IToolable;
import api.hbm.energymk2.IEnergyConnectorBlock; import api.hbm.energymk2.IEnergyConnectorBlock;
import api.hbm.energymk2.IEnergyReceiverMK2;
import api.hbm.energymk2.Nodespace;
import api.hbm.energymk2.Nodespace.PowerNode;
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -136,7 +141,7 @@ public class CableDiode extends BlockContainer implements IEnergyConnectorBlock,
return new TileEntityDiode(); return new TileEntityDiode();
} }
public static class TileEntityDiode extends TileEntityLoadedBase implements IEnergyUser { public static class TileEntityDiode extends TileEntityLoadedBase implements IEnergyReceiverMK2 {
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
@ -189,9 +194,9 @@ public class CableDiode extends BlockContainer implements IEnergyConnectorBlock,
return dir != getDir(); return dir != getDir();
} }
/** Used as an intra-tick tracker for how much energy has been transmitted, resets to 0 each tick and maxes out based on transfer */
private long power;
private boolean recursionBrake = false; private boolean recursionBrake = false;
private long subBuffer;
private long contingent = 0;
private long lastTransfer = 0; private long lastTransfer = 0;
private int pulses = 0; private int pulses = 0;
public ConnectionPriority priority = ConnectionPriority.NORMAL; public ConnectionPriority priority = ConnectionPriority.NORMAL;
@ -206,31 +211,25 @@ public class CableDiode extends BlockContainer implements IEnergyConnectorBlock,
if(lastTransfer != worldObj.getTotalWorldTime()) { if(lastTransfer != worldObj.getTotalWorldTime()) {
lastTransfer = worldObj.getTotalWorldTime(); lastTransfer = worldObj.getTotalWorldTime();
contingent = getMaxPower();
pulses = 0; pulses = 0;
this.setPower(0); //tick is over, reset our allowed transfe
} }
if(contingent <= 0 || pulses > 10) if(this.getPower() >= this.getMaxPower() || pulses > 10) return power; //if we have already maxed out transfer or max pulses, abort
return power;
//this part turns "maxPower" from a glorified transfer weight into an actual transfer cap
long overShoot = Math.max(0, power - contingent);
power = Math.min(power, contingent);
recursionBrake = true; recursionBrake = true;
this.subBuffer = power;
ForgeDirection dir = getDir(); ForgeDirection dir = getDir();
this.sendPower(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); PowerNode node = Nodespace.getNode(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
long ret = this.subBuffer;
long sent = power - ret; if(node.hasValidNet() && Nodespace.checkConnection(node, new DirPos(xCoord, yCoord, zCoord, dir), false)) {
contingent -= sent; long prevPower = power;
power = node.net.sendPowerDiode(power);
this.power += (prevPower - power);
}
this.subBuffer = 0;
recursionBrake = false; recursionBrake = false;
return power;
return ret + overShoot;
} }
@ -241,12 +240,12 @@ public class CableDiode extends BlockContainer implements IEnergyConnectorBlock,
@Override @Override
public long getPower() { public long getPower() {
return subBuffer; return Math.min(power, this.getMaxPower());
} }
@Override @Override
public void setPower(long power) { public void setPower(long power) {
this.subBuffer = power; this.power = power;
} }
@Override @Override

View File

@ -1,20 +1,14 @@
package com.hbm.inventory.gui; package com.hbm.inventory.gui;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import com.hbm.inventory.container.ContainerMachineSelenium; import com.hbm.inventory.container.ContainerMachineSelenium;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.tileentity.machine.TileEntityMachineSeleniumEngine; import com.hbm.tileentity.machine.TileEntityMachineSeleniumEngine;
import com.hbm.util.BobMathUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class GUIMachineSelenium extends GuiInfoContainer { public class GUIMachineSelenium extends GuiInfoContainer {
@ -36,22 +30,6 @@ public class GUIMachineSelenium extends GuiInfoContainer {
selenium.tank.renderTankInfo(this, mouseX, mouseY, guiLeft + 116, guiTop + 18, 16, 52); selenium.tank.renderTankInfo(this, mouseX, mouseY, guiLeft + 116, guiTop + 18, 16, 52);
this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 8, guiTop + 108, 160, 16, selenium.power, selenium.powerCap); this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 8, guiTop + 108, 160, 16, selenium.power, selenium.powerCap);
List<String> text = new ArrayList();
text.add(EnumChatFormatting.YELLOW + "Accepted Fuels:");
for(FluidType type : Fluids.getInNiceOrder()) {
long energy = selenium.getHEFromFuel(type);
if(energy > 0)
text.add(" " + type.getLocalizedName() + " (" + BobMathUtil.getShortNumber(energy) + "HE/t)");
}
text.add(EnumChatFormatting.ITALIC + "(These numbers are base values,");
text.add(EnumChatFormatting.ITALIC + "actual output is based");
text.add(EnumChatFormatting.ITALIC + "on piston count)");
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 36, 16, 16, guiLeft - 8, guiTop + 36 + 16, text.toArray(new String[0]));
String[] text1 = new String[] { "Fuel consumption rate:", String[] text1 = new String[] { "Fuel consumption rate:",
" 1 mB/t", " 1 mB/t",
@ -65,13 +43,6 @@ public class GUIMachineSelenium extends GuiInfoContainer {
"required to operate this radial engine!" }; "required to operate this radial engine!" };
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 36 + 32, 16, 16, guiLeft - 8, guiTop + 36 + 16 + 32, text2); this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 36 + 32, 16, 16, guiLeft - 8, guiTop + 36 + 16 + 32, text2);
} }
if(!selenium.hasAcceptableFuel()) {
String[] text2 = new String[] { "Error: The currently set fuel type",
"is not supported by this engine!" };
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 36 + 48, 16, 16, guiLeft - 8, guiTop + 36 + 16 + 32, text2);
}
} }
@Override @Override
@ -88,19 +59,6 @@ public class GUIMachineSelenium extends GuiInfoContainer {
Minecraft.getMinecraft().getTextureManager().bindTexture(texture); Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
if(selenium.power > 0) {
int i = (int)selenium.getPowerScaled(160);
i = (int) Math.min(i, 160);
drawTexturedModalRect(guiLeft + 8, guiTop + 108, 0, 222, i, 16);
}
if(selenium.tank.getFill() > 0 && selenium.hasAcceptableFuel() && selenium.pistonCount > 2)
{
drawTexturedModalRect(guiLeft + 115, guiTop + 71, 192, 0, 18, 18);
}
if(selenium.pistonCount > 0) if(selenium.pistonCount > 0)
{ {
int k = selenium.pistonCount; int k = selenium.pistonCount;
@ -110,9 +68,6 @@ public class GUIMachineSelenium extends GuiInfoContainer {
if(selenium.pistonCount < 3) if(selenium.pistonCount < 3)
this.drawInfoPanel(guiLeft - 16, guiTop + 36 + 32, 16, 16, 6); this.drawInfoPanel(guiLeft - 16, guiTop + 36 + 32, 16, 16, 6);
if(!selenium.hasAcceptableFuel())
this.drawInfoPanel(guiLeft - 16, guiTop + 36 + 48, 16, 16, 7);
this.drawInfoPanel(guiLeft - 16, guiTop + 36, 16, 16, 2); this.drawInfoPanel(guiLeft - 16, guiTop + 36, 16, 16, 2);
this.drawInfoPanel(guiLeft - 16, guiTop + 36 + 16, 16, 16, 3); this.drawInfoPanel(guiLeft - 16, guiTop + 36 + 16, 16, 16, 3);

View File

@ -6,11 +6,12 @@ import com.hbm.blocks.BlockDummyable;
import com.hbm.packet.AuxParticlePacketNT; import com.hbm.packet.AuxParticlePacketNT;
import com.hbm.packet.PacketDispatcher; import com.hbm.packet.PacketDispatcher;
import com.hbm.util.ChatBuilder; import com.hbm.util.ChatBuilder;
import com.hbm.util.fauxpointtwelve.BlockPos;
import api.hbm.energy.IEnergyConductor; import api.hbm.energymk2.IEnergyConductorMK2;
import api.hbm.energy.IEnergyConnector; import api.hbm.energymk2.Nodespace;
import api.hbm.energy.IPowerNet; import api.hbm.energymk2.Nodespace.PowerNode;
import api.hbm.energy.PowerNet; import api.hbm.energymk2.PowerNetMK2;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -19,7 +20,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ItemPowerNetTool extends Item { public class ItemPowerNetTool extends Item {
@ -44,51 +44,33 @@ public class ItemPowerNetTool extends Item {
if(world.isRemote) if(world.isRemote)
return true; return true;
if((te instanceof IEnergyConductor)) { if((te instanceof IEnergyConductorMK2)) {
PowerNode node = Nodespace.getNode(world, x, y, z);
IEnergyConductor con = (IEnergyConductor) te; if(node != null && node.hasValidNet()) {
IPowerNet net = con.getPowerNet();
if(net == null) {
player.addChatComponentMessage(ChatBuilder.start("Error: No network found! This should be impossible!").color(EnumChatFormatting.RED).flush());
return true;
}
if(!(net instanceof PowerNet)) {
player.addChatComponentMessage(ChatBuilder.start("Error: Cannot print diagnostic for non-standard power net implementation!").color(EnumChatFormatting.RED).flush());
}
PowerNet network = (PowerNet) net;
String id = Integer.toHexString(net.hashCode());
player.addChatComponentMessage(ChatBuilder.start("Start of diagnostic for network " + id).color(EnumChatFormatting.GOLD).flush());
player.addChatComponentMessage(ChatBuilder.start("Links: " + network.getLinks().size()).color(EnumChatFormatting.YELLOW).flush());
player.addChatComponentMessage(ChatBuilder.start("Proxies: " + network.getProxies().size()).color(EnumChatFormatting.YELLOW).flush());
player.addChatComponentMessage(ChatBuilder.start("Subscribers: " + network.getSubscribers().size()).color(EnumChatFormatting.YELLOW).flush());
player.addChatComponentMessage(ChatBuilder.start("End of diagnostic for network " + id).color(EnumChatFormatting.GOLD).flush());
for(IEnergyConductor link : network.getLinks()) {
Vec3 pos = link.getDebugParticlePos();
boolean errored = link.getPowerNet() != net; PowerNetMK2 net = node.net;
String id = Integer.toHexString(net.hashCode());
player.addChatComponentMessage(ChatBuilder.start("Start of diagnostic for network " + id).color(EnumChatFormatting.GOLD).flush());
player.addChatComponentMessage(ChatBuilder.start("Links: " + net.links.size()).color(EnumChatFormatting.YELLOW).flush());
player.addChatComponentMessage(ChatBuilder.start("Providers: " + net.providerEntries.size()).color(EnumChatFormatting.YELLOW).flush());
player.addChatComponentMessage(ChatBuilder.start("Receivers: " + net.receiverEntries.size()).color(EnumChatFormatting.YELLOW).flush());
player.addChatComponentMessage(ChatBuilder.start("End of diagnostic for network " + id).color(EnumChatFormatting.GOLD).flush());
NBTTagCompound data = new NBTTagCompound(); for(PowerNode link : net.links) {
data.setString("type", "debug");
data.setInteger("color", errored ? 0xff0000 : 0xffff00); for(BlockPos pos : link.positions) {
data.setFloat("scale", 0.5F); NBTTagCompound data = new NBTTagCompound();
data.setString("text", id); data.setString("type", "debug");
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.xCoord, pos.yCoord, pos.zCoord), new TargetPoint(world.provider.dimensionId, pos.xCoord, pos.yCoord, pos.zCoord, radius)); data.setInteger("color", 0xffff00);
} data.setFloat("scale", 0.5F);
data.setString("text", id);
for(IEnergyConnector subscriber : network.getSubscribers()) { PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5), new TargetPoint(world.provider.dimensionId, pos.getX(), pos.getY(), pos.getZ(), radius));
Vec3 pos = subscriber.getDebugParticlePos(); }
}
NBTTagCompound data = new NBTTagCompound(); } else {
data.setString("type", "debug"); player.addChatComponentMessage(ChatBuilder.start("Error: No network found!").color(EnumChatFormatting.RED).flush());
data.setInteger("color", 0x0000ff);
data.setFloat("scale", 1.5F);
data.setString("text", id);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.xCoord, pos.yCoord, pos.zCoord), new TargetPoint(world.provider.dimensionId, pos.xCoord, pos.yCoord, pos.zCoord, radius));
} }
return true; return true;

View File

@ -46,9 +46,6 @@ public class RenderSelenium extends TileEntitySpecialRenderer {
ResourceManager.selenium_piston.renderAll(); ResourceManager.selenium_piston.renderAll();
GL11.glRotatef(rot, 0, 0, 1); GL11.glRotatef(rot, 0, 0, 1);
} }
if(count > 2 && ((TileEntityMachineSeleniumEngine)tileEntity).hasAcceptableFuel() && ((TileEntityMachineSeleniumEngine)tileEntity).tank.getFill() > 0)
GL11.glRotatef((System.currentTimeMillis() / 2) % 360, 0F, 0F, -1F);
bindTexture(ResourceManager.selenium_rotor_tex); bindTexture(ResourceManager.selenium_rotor_tex);
ResourceManager.selenium_rotor.renderAll(); ResourceManager.selenium_rotor.renderAll();

View File

@ -1,9 +1,9 @@
package com.hbm.tileentity.network; package com.hbm.tileentity.network;
import java.util.ArrayList; import com.hbm.util.fauxpointtwelve.BlockPos;
import java.util.List; import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energy.IEnergyConductor; import api.hbm.energymk2.Nodespace.PowerNode;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -24,33 +24,14 @@ public class TileEntityConnector extends TileEntityPylonBase {
public double getMaxWireLength() { public double getMaxWireLength() {
return 10; return 10;
} }
@Override @Override
public List<int[]> getConnectionPoints() { public PowerNode createNode() {
List<int[]> pos = new ArrayList(connected); TileEntity tile = (TileEntity) this;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite();
//pos.add(new int[] {xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ}); PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(new DirPos(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir));
for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN));
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ); return node;
if(te instanceof IEnergyConductor) {
IEnergyConductor conductor = (IEnergyConductor) te;
if(conductor.canConnect(dir.getOpposite())) {
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());
}
}
}
return pos;
} }
@Override @Override

View File

@ -1,8 +1,11 @@
package com.hbm.tileentity.network; package com.hbm.tileentity.network;
import java.util.ArrayList; import com.hbm.lib.Library;
import java.util.List; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energymk2.Nodespace.PowerNode;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -22,14 +25,19 @@ public class TileEntityPylon extends TileEntityPylonBase {
public double getMaxWireLength() { public double getMaxWireLength() {
return 25D; return 25D;
} }
@Override @Override
public List<int[]> getConnectionPoints() { public PowerNode createNode() {
List<int[]> pos = new ArrayList(connected); TileEntity tile = (TileEntity) this;
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { new DirPos(xCoord + 1, yCoord, zCoord, Library.POS_X),
pos.add(new int[] {xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ}); new DirPos(xCoord - 1, yCoord, zCoord, Library.NEG_X),
} new DirPos(xCoord, yCoord + 1, zCoord, Library.POS_Y),
return pos; new DirPos(xCoord, yCoord - 1, zCoord, Library.NEG_Y),
new DirPos(xCoord, yCoord, zCoord + 1, Library.POS_Z),
new DirPos(xCoord, yCoord, zCoord - 1, Library.NEG_Z)
);
for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN));
return node;
} }
} }

View File

@ -3,7 +3,11 @@ package com.hbm.tileentity.network;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import api.hbm.energy.IEnergyConductor; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energymk2.Nodespace;
import api.hbm.energymk2.Nodespace.PowerNode;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -14,6 +18,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
@ -40,15 +45,22 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
return len >= delta.lengthVector() ? 0 : 3; return len >= delta.lengthVector() ? 0 : 3;
} }
@Override
public PowerNode createNode() {
TileEntity tile = (TileEntity) this;
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord));
for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN));
return node;
}
public void addConnection(int x, int y, int z) { public void addConnection(int x, int y, int z) {
connected.add(new int[] {x, y, z}); connected.add(new int[] {x, y, z});
if(this.getPowerNet() != null) { PowerNode node = Nodespace.getNode(worldObj, xCoord, yCoord, zCoord);
this.getPowerNet().reevaluate(); node.recentlyChanged = true;
this.network = null; node.addConnection(new DirPos(x, y, z, ForgeDirection.UNKNOWN));
}
this.markDirty(); this.markDirty();
@ -87,33 +99,8 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
} }
} }
} }
}
@Override
protected void connect() {
for(int[] pos : getConnectionPoints()) { Nodespace.destroyNode(worldObj, xCoord, yCoord, zCoord);
TileEntity te = worldObj.getTileEntity(pos[0], pos[1], pos[2]);
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());
}
}
}
}
@Override
public List<int[]> getConnectionPoints() {
return new ArrayList(connected);
} }
public abstract ConnectionType getConnectionType(); public abstract ConnectionType getConnectionType();

View File

@ -1,12 +1,14 @@
package com.hbm.tileentity.network; package com.hbm.tileentity.network;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.lib.Library;
import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energy.IEnergyConductor; import api.hbm.energymk2.Nodespace.PowerNode;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntitySubstation extends TileEntityPylonBase { public class TileEntitySubstation extends TileEntityPylonBase {
@ -45,33 +47,21 @@ public class TileEntitySubstation extends TileEntityPylonBase {
public double getMaxWireLength() { public double getMaxWireLength() {
return 20; return 20;
} }
@Override
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;
}
@Override @Override
public boolean hasProxies() { public PowerNode createNode() {
return true; TileEntity tile = (TileEntity) this;
} PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(
new DirPos(xCoord + 2, yCoord, zCoord - 1, Library.POS_X),
@Override new DirPos(xCoord + 2, yCoord, zCoord + 1, Library.POS_X),
public List<Integer> getProxies() { new DirPos(xCoord - 2, yCoord, zCoord - 1, Library.NEG_X),
List<Integer> proxies = new ArrayList(); new DirPos(xCoord - 2, yCoord, zCoord + 1, Library.NEG_X),
proxies.add(IEnergyConductor.getIdentityFromPos(xCoord + 1, yCoord, zCoord + 1)); new DirPos(xCoord - 1, yCoord, zCoord + 2, Library.POS_Z),
proxies.add(IEnergyConductor.getIdentityFromPos(xCoord + 1, yCoord, zCoord - 1)); new DirPos(xCoord + 1, yCoord, zCoord + 2, Library.POS_Z),
proxies.add(IEnergyConductor.getIdentityFromPos(xCoord - 1, yCoord, zCoord + 1)); new DirPos(xCoord - 1, yCoord, zCoord - 2, Library.NEG_Z),
proxies.add(IEnergyConductor.getIdentityFromPos(xCoord - 1, yCoord, zCoord - 1)); new DirPos(xCoord + 1, yCoord, zCoord - 2, Library.NEG_Z)
return proxies; );
for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN));
return node;
} }
} }