Conflicts:
	common/mekanism/common/TileEntityUniversalCable.java
This commit is contained in:
Aidan Brady 2013-07-31 11:59:49 -04:00
commit 1953e16b5a
12 changed files with 229 additions and 37 deletions

View file

@ -1,4 +1,4 @@
# Mekanism for Minecraft 1.5.2 # # Mekanism for Minecraft 1.6.2 #
Source code. More information can be found on the mod's forum post. Source code. More information can be found on the mod's forum post.
@ -27,9 +27,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
# Developers & Credits # # Developers & Credits #
**Head Developer:** aidancbrady **Lead Developer:** aidancbrady
**Contributors:** viper283, Condo97 **Co-developer:** unpairedbracket
**Contributors:** micdoodle, Calclavia
**Credits:** **Credits:**

View file

@ -31,7 +31,8 @@ public class MekanismRenderer
private static float lightmapLastX; private static float lightmapLastX;
private static float lightmapLastY; private static float lightmapLastY;
private static boolean optifineBreak = false;
public static class Model3D public static class Model3D
{ {
public double minX; public double minX;
@ -145,15 +146,29 @@ public class MekanismRenderer
public static void glowOn() public static void glowOn()
{ {
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT); GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
lightmapLastX = OpenGlHelper.lastBrightnessX; try
lightmapLastY = OpenGlHelper.lastBrightnessY; {
lightmapLastX = OpenGlHelper.lastBrightnessX;
lightmapLastY = OpenGlHelper.lastBrightnessY;
}
catch(NoSuchFieldError e)
{
optifineBreak = true;
}
RenderHelper.disableStandardItemLighting(); RenderHelper.disableStandardItemLighting();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F); if(!optifineBreak)
{
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
}
} }
public static void glowOff() public static void glowOff()
{ {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapLastX, lightmapLastY); if(!optifineBreak)
{
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapLastX, lightmapLastY);
}
GL11.glPopAttrib(); GL11.glPopAttrib();
} }

View file

@ -8,10 +8,17 @@ import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender; import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import net.minecraft.server.MinecraftServer;
public class CommandMekanism extends CommandBase public class CommandMekanism extends CommandBase
{ {
@Override @Override
public boolean canCommandSenderUseCommand(ICommandSender sender)
{
return MinecraftServer.getServer().isSinglePlayer() || super.canCommandSenderUseCommand(sender);
}
@Override
public String getCommandName() public String getCommandName()
{ {
return "mk"; return "mk";

View file

@ -25,13 +25,15 @@ import buildcraft.api.power.PowerHandler.Type;
public class EnergyNetwork public class EnergyNetwork
{ {
public Set<IUniversalCable> cables = new HashSet<IUniversalCable>(); public HashSet<IUniversalCable> cables = new HashSet<IUniversalCable>();
public Set<TileEntity> possibleAcceptors = new HashSet<TileEntity>(); public Set<TileEntity> possibleAcceptors = new HashSet<TileEntity>();
public Map<TileEntity, ForgeDirection> acceptorDirections = new HashMap<TileEntity, ForgeDirection>(); public Map<TileEntity, ForgeDirection> acceptorDirections = new HashMap<TileEntity, ForgeDirection>();
private double joulesTransmitted = 0; private double joulesTransmitted = 0;
private double joulesLastTick = 0; private double joulesLastTick = 0;
private int ticksSinceCreate = 0;
private boolean fixed = false;
public EnergyNetwork(IUniversalCable... varCables) public EnergyNetwork(IUniversalCable... varCables)
{ {
@ -39,6 +41,20 @@ public class EnergyNetwork
EnergyNetworkRegistry.getInstance().registerNetwork(this); EnergyNetworkRegistry.getInstance().registerNetwork(this);
} }
public EnergyNetwork(Set<EnergyNetwork> networks)
{
for (EnergyNetwork net : networks)
{
if(net != null)
{
addAllCables(net.cables);
net.deregister();
}
}
refresh();
EnergyNetworkRegistry.getInstance().registerNetwork(this);
}
public double getEnergyNeeded(ArrayList<TileEntity> ignored) public double getEnergyNeeded(ArrayList<TileEntity> ignored)
{ {
double totalNeeded = 0; double totalNeeded = 0;
@ -157,7 +173,8 @@ public class EnergyNetwork
public void refresh() public void refresh()
{ {
Iterator it = cables.iterator(); Set<IUniversalCable> iterCables = (Set<IUniversalCable>) cables.clone();
Iterator<IUniversalCable> it = iterCables.iterator();
possibleAcceptors.clear(); possibleAcceptors.clear();
acceptorDirections.clear(); acceptorDirections.clear();
@ -166,20 +183,17 @@ public class EnergyNetwork
{ {
IUniversalCable conductor = (IUniversalCable)it.next(); IUniversalCable conductor = (IUniversalCable)it.next();
if(conductor == null) if(conductor == null || ((TileEntity)conductor).isInvalid())
{
it.remove();
}
else if(((TileEntity)conductor).isInvalid())
{ {
it.remove(); it.remove();
cables.remove(conductor);
} }
else { else {
conductor.setNetwork(this); conductor.setNetwork(this);
} }
} }
for(IUniversalCable cable : cables) for(IUniversalCable cable : iterCables)
{ {
TileEntity[] acceptors = CableUtils.getConnectedEnergyAcceptors((TileEntity)cable); TileEntity[] acceptors = CableUtils.getConnectedEnergyAcceptors((TileEntity)cable);
@ -196,24 +210,26 @@ public class EnergyNetwork
public void merge(EnergyNetwork network) public void merge(EnergyNetwork network)
{ {
EnergyNetworkRegistry registry = EnergyNetworkRegistry.getInstance();
if(network != null && network != this) if(network != null && network != this)
{ {
EnergyNetwork newNetwork = new EnergyNetwork(); Set<EnergyNetwork> networks = new HashSet();
newNetwork.cables.addAll(cables); networks.add(this);
registry.removeNetwork(this); networks.add(network);
newNetwork.cables.addAll(network.cables); EnergyNetwork newNetwork = new EnergyNetwork(networks);
registry.removeNetwork(network);
newNetwork.refresh(); newNetwork.refresh();
} }
} }
public void addAllCables(Set<IUniversalCable> newCables)
{
cables.addAll(newCables);
}
public void split(IUniversalCable splitPoint) public void split(IUniversalCable splitPoint)
{ {
if(splitPoint instanceof TileEntity) if(splitPoint instanceof TileEntity)
{ {
cables.remove(splitPoint); removeCable(splitPoint);
TileEntity[] connectedBlocks = new TileEntity[6]; TileEntity[] connectedBlocks = new TileEntity[6];
boolean[] dealtWith = {false, false, false, false, false, false}; boolean[] dealtWith = {false, false, false, false, false, false};
@ -235,7 +251,7 @@ public class EnergyNetwork
if(connectedBlockA instanceof IUniversalCable && !dealtWith[countOne]) if(connectedBlockA instanceof IUniversalCable && !dealtWith[countOne])
{ {
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint)); NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
List<Object3D> partNetwork = finder.findNetwork(); List<Object3D> partNetwork = finder.exploreNetwork();
for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++) for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++)
{ {
@ -269,10 +285,49 @@ public class EnergyNetwork
} }
} }
EnergyNetworkRegistry.getInstance().removeNetwork(this); deregister();
} }
} }
public void fixMessedUpNetwork(IUniversalCable cable)
{
if(cable instanceof TileEntity)
{
NetworkFinder finder = new NetworkFinder(((TileEntity) cable).getWorldObj(), Object3D.get((TileEntity)cable), null);
List<Object3D> partNetwork = finder.exploreNetwork();
Set<IUniversalCable> newCables = new HashSet<IUniversalCable>();
for(Object3D node : partNetwork)
{
TileEntity nodeTile = node.getTileEntity(((TileEntity)cable).worldObj);
if(nodeTile instanceof IUniversalCable)
{
((IUniversalCable) nodeTile).removeFromNetwork();
newCables.add((IUniversalCable)nodeTile);
}
}
EnergyNetwork newNetwork = new EnergyNetwork(newCables.toArray(new IUniversalCable[0]));
newNetwork.refresh();
newNetwork.fixed = true;
deregister();
}
}
public void removeCable(IUniversalCable cable)
{
cables.remove(cable);
if(cables.size() == 0)
{
deregister();
}
}
public void deregister()
{
cables.clear();
EnergyNetworkRegistry.getInstance().removeNetwork(this);
}
public static class NetworkFinder public static class NetworkFinder
{ {
public World worldObj; public World worldObj;
@ -315,7 +370,7 @@ public class EnergyNetwork
} }
} }
public List<Object3D> findNetwork() public List<Object3D> exploreNetwork()
{ {
loopAll(start); loopAll(start);
@ -352,6 +407,22 @@ public class EnergyNetwork
return "[EnergyNetwork] " + cables.size() + " cables, " + possibleAcceptors.size() + " acceptors."; return "[EnergyNetwork] " + cables.size() + " cables, " + possibleAcceptors.size() + " acceptors.";
} }
public void tick()
{
clearJoulesTransmitted();
//Fix weird behaviour periodically.
if(!fixed)
{
++ticksSinceCreate;
if(ticksSinceCreate > 1200)
{
ticksSinceCreate = 0;
fixMessedUpNetwork(cables.toArray(new IUniversalCable[0])[0]);
}
}
}
public void clearJoulesTransmitted() public void clearJoulesTransmitted()
{ {
joulesLastTick = joulesTransmitted; joulesLastTick = joulesTransmitted;
@ -360,6 +431,6 @@ public class EnergyNetwork
public double getPower() public double getPower()
{ {
return joulesTransmitted * 20; return joulesLastTick * 20;
} }
} }

View file

@ -13,7 +13,7 @@ public class EnergyNetworkRegistry implements ITickHandler
{ {
private static EnergyNetworkRegistry INSTANCE = new EnergyNetworkRegistry(); private static EnergyNetworkRegistry INSTANCE = new EnergyNetworkRegistry();
private Set<EnergyNetwork> networks = new HashSet<EnergyNetwork>(); private HashSet<EnergyNetwork> networks = new HashSet<EnergyNetwork>();
public EnergyNetworkRegistry() public EnergyNetworkRegistry()
{ {
@ -38,6 +38,17 @@ public class EnergyNetworkRegistry implements ITickHandler
} }
} }
public void pruneEmptyNetworks() {
for(EnergyNetwork e : networks)
{
if(e.cables.size() == 0)
{
removeNetwork(e);
}
}
}
@Override @Override
public void tickStart(EnumSet<TickType> type, Object... tickData) public void tickStart(EnumSet<TickType> type, Object... tickData)
{ {
@ -47,9 +58,13 @@ public class EnergyNetworkRegistry implements ITickHandler
@Override @Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) public void tickEnd(EnumSet<TickType> type, Object... tickData)
{ {
for(EnergyNetwork net : networks) Set<EnergyNetwork> iterNetworks = (Set<EnergyNetwork>) networks.clone();
for(EnergyNetwork net : iterNetworks)
{ {
net.clearJoulesTransmitted(); if(networks.contains(net))
{
net.tick();
}
} }
} }

View file

@ -9,10 +9,20 @@ public interface IUniversalCable
{ {
/** /**
* Gets the EnergyNetwork currently in use by this cable segment. * Gets the EnergyNetwork currently in use by this cable segment.
* Will try to connect to adjacent networks or create a new one
* @return EnergyNetwork this cable is using * @return EnergyNetwork this cable is using
*/ */
public EnergyNetwork getNetwork(); public EnergyNetwork getNetwork();
/**
* Gets the EnergyNetwork currently in use by this cable segment.
* @param createIfNull - If true, the cable will try and connect to an
* adjacent network, merging several if necessary, or creating a new one
* if none is available
* @return EnergyNetwork this cable is using
*/
public EnergyNetwork getNetwork(boolean createIfNull);
/** /**
* Sets this cable segment's EnergyNetwork to a new value. * Sets this cable segment's EnergyNetwork to a new value.
* @param network - EnergyNetwork to set to * @param network - EnergyNetwork to set to
@ -23,4 +33,16 @@ public interface IUniversalCable
* Refreshes the cable's EnergyNetwork. * Refreshes the cable's EnergyNetwork.
*/ */
public void refreshNetwork(); public void refreshNetwork();
/**
* Remove a cable from its network.
*/
public void removeFromNetwork();
/**
* Call this if you're worried a cable's network is messed up and you want
* it to try and fix itself.
*/
public void fixNetwork();
} }

View file

@ -60,6 +60,10 @@ public class ItemConfigurator extends ItemEnergized
return true; return true;
} }
} }
else if(world.getBlockTileEntity(x, y, z) instanceof IUniversalCable)
{
((IUniversalCable)world.getBlockTileEntity(x, y, z)).fixNetwork();
}
if(getState(stack) == 0) if(getState(stack) == 0)
{ {

View file

@ -44,6 +44,11 @@ public class ItemEnergyMeter extends ItemEnergized
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------")); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------"));
} }
} }
if(player.isSneaking() && Mekanism.debug){
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "---------- " + EnumColor.DARK_BLUE + "[Mekanism Debug]" + EnumColor.GREY + " ----------"));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Networks: " + EnumColor.DARK_GREY + EnergyNetworkRegistry.getInstance().toString()));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------"));
}
} }
return false; return false;

View file

@ -731,7 +731,7 @@ public class Mekanism
System.out.println("[Mekanism] Hooked into Thermal Expansion successfully."); System.out.println("[Mekanism] Hooked into Thermal Expansion successfully.");
} catch(Exception e) {} } catch(Exception e) {}
if(controlCircuitOreDict || (!controlCircuitOreDict && !hooks.BasicComponentsLoaded)) if(controlCircuitOreDict || !hooks.BasicComponentsLoaded)
{ {
OreDictionary.registerOre("circuitBasic", new ItemStack(ControlCircuit)); OreDictionary.registerOre("circuitBasic", new ItemStack(ControlCircuit));
} }

View file

@ -146,7 +146,7 @@ public class TileEntityElectricChest extends TileEntityElectricBlock
return new int[] {54}; return new int[] {54};
} }
else { else {
int[] ret = new int[54]; int[] ret = new int[55];
for(int i = 0; i <= ret.length; i++) for(int i = 0; i <= ret.length; i++)
{ {

View file

@ -1,6 +1,7 @@
package mekanism.common; package mekanism.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -36,14 +37,47 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
@Override @Override
public EnergyNetwork getNetwork() public EnergyNetwork getNetwork()
{ {
if(energyNetwork == null) return getNetwork(true);
}
@Override
public EnergyNetwork getNetwork(boolean createIfNull)
{
if(energyNetwork == null && createIfNull)
{ {
energyNetwork = new EnergyNetwork(this); TileEntity[] adjacentCables = CableUtils.getConnectedCables(this);
HashSet<EnergyNetwork> connectedNets = new HashSet<EnergyNetwork>();
for(TileEntity cable : adjacentCables)
{
if(cable instanceof IUniversalCable && ((IUniversalCable)cable).getNetwork(false) != null)
{
connectedNets.add(((IUniversalCable)cable).getNetwork());
}
}
if(connectedNets.size() == 0)
{
energyNetwork = new EnergyNetwork(this);
}
else if(connectedNets.size() == 1)
{
energyNetwork = (EnergyNetwork)connectedNets.toArray()[0];
energyNetwork.cables.add(this);
}
else {
energyNetwork = new EnergyNetwork(connectedNets);
energyNetwork.cables.add(this);
}
} }
return energyNetwork; return energyNetwork;
} }
@Override
public void fixNetwork()
{
getNetwork().fixMessedUpNetwork(this);
}
@Override @Override
public void invalidate() public void invalidate()
{ {
@ -58,7 +92,17 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
@Override @Override
public void setNetwork(EnergyNetwork network) public void setNetwork(EnergyNetwork network)
{ {
energyNetwork = network; if(network != energyNetwork)
{
removeFromNetwork();
energyNetwork = network;
}
}
@Override
public void removeFromNetwork()
{
energyNetwork.removeCable(this);
} }
@Override @Override
@ -101,4 +145,11 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
{ {
return INFINITE_EXTENT_AABB; return INFINITE_EXTENT_AABB;
} }
@Override
public void onChunkUnload()
{
invalidate();
EnergyNetworkRegistry.getInstance().pruneEmptyNetworks();
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 728 B