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.
@ -27,9 +27,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
# Developers & Credits #
**Head Developer:** aidancbrady
**Lead Developer:** aidancbrady
**Contributors:** viper283, Condo97
**Co-developer:** unpairedbracket
**Contributors:** micdoodle, Calclavia
**Credits:**

View file

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

View file

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

View file

@ -25,13 +25,15 @@ import buildcraft.api.power.PowerHandler.Type;
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 Map<TileEntity, ForgeDirection> acceptorDirections = new HashMap<TileEntity, ForgeDirection>();
private double joulesTransmitted = 0;
private double joulesLastTick = 0;
private int ticksSinceCreate = 0;
private boolean fixed = false;
public EnergyNetwork(IUniversalCable... varCables)
{
@ -39,6 +41,20 @@ public class EnergyNetwork
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)
{
double totalNeeded = 0;
@ -157,7 +173,8 @@ public class EnergyNetwork
public void refresh()
{
Iterator it = cables.iterator();
Set<IUniversalCable> iterCables = (Set<IUniversalCable>) cables.clone();
Iterator<IUniversalCable> it = iterCables.iterator();
possibleAcceptors.clear();
acceptorDirections.clear();
@ -166,20 +183,17 @@ public class EnergyNetwork
{
IUniversalCable conductor = (IUniversalCable)it.next();
if(conductor == null)
{
it.remove();
}
else if(((TileEntity)conductor).isInvalid())
if(conductor == null || ((TileEntity)conductor).isInvalid())
{
it.remove();
cables.remove(conductor);
}
else {
conductor.setNetwork(this);
}
}
for(IUniversalCable cable : cables)
for(IUniversalCable cable : iterCables)
{
TileEntity[] acceptors = CableUtils.getConnectedEnergyAcceptors((TileEntity)cable);
@ -196,24 +210,26 @@ public class EnergyNetwork
public void merge(EnergyNetwork network)
{
EnergyNetworkRegistry registry = EnergyNetworkRegistry.getInstance();
if(network != null && network != this)
{
EnergyNetwork newNetwork = new EnergyNetwork();
newNetwork.cables.addAll(cables);
registry.removeNetwork(this);
newNetwork.cables.addAll(network.cables);
registry.removeNetwork(network);
Set<EnergyNetwork> networks = new HashSet();
networks.add(this);
networks.add(network);
EnergyNetwork newNetwork = new EnergyNetwork(networks);
newNetwork.refresh();
}
}
public void addAllCables(Set<IUniversalCable> newCables)
{
cables.addAll(newCables);
}
public void split(IUniversalCable splitPoint)
{
if(splitPoint instanceof TileEntity)
{
cables.remove(splitPoint);
removeCable(splitPoint);
TileEntity[] connectedBlocks = new TileEntity[6];
boolean[] dealtWith = {false, false, false, false, false, false};
@ -235,7 +251,7 @@ public class EnergyNetwork
if(connectedBlockA instanceof IUniversalCable && !dealtWith[countOne])
{
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++)
{
@ -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 World worldObj;
@ -315,7 +370,7 @@ public class EnergyNetwork
}
}
public List<Object3D> findNetwork()
public List<Object3D> exploreNetwork()
{
loopAll(start);
@ -352,6 +407,22 @@ public class EnergyNetwork
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()
{
joulesLastTick = joulesTransmitted;
@ -360,6 +431,6 @@ public class EnergyNetwork
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 Set<EnergyNetwork> networks = new HashSet<EnergyNetwork>();
private HashSet<EnergyNetwork> networks = new HashSet<EnergyNetwork>();
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
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
@ -47,9 +58,13 @@ public class EnergyNetworkRegistry implements ITickHandler
@Override
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.
* Will try to connect to adjacent networks or create a new one
* @return EnergyNetwork this cable is using
*/
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.
* @param network - EnergyNetwork to set to
@ -23,4 +33,16 @@ public interface IUniversalCable
* Refreshes the cable's EnergyNetwork.
*/
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;
}
}
else if(world.getBlockTileEntity(x, y, z) instanceof IUniversalCable)
{
((IUniversalCable)world.getBlockTileEntity(x, y, z)).fixNetwork();
}
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 + " -------------"));
}
}
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;

View file

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

View file

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

View file

@ -1,6 +1,7 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.HashSet;
import mekanism.api.Object3D;
import net.minecraft.tileentity.TileEntity;
@ -36,14 +37,47 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
@Override
public EnergyNetwork getNetwork()
{
if(energyNetwork == null)
return getNetwork(true);
}
@Override
public EnergyNetwork getNetwork(boolean createIfNull)
{
if(energyNetwork == null && createIfNull)
{
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;
}
@Override
public void fixNetwork()
{
getNetwork().fixMessedUpNetwork(this);
}
@Override
public void invalidate()
{
@ -58,8 +92,18 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
@Override
public void setNetwork(EnergyNetwork network)
{
if(network != energyNetwork)
{
removeFromNetwork();
energyNetwork = network;
}
}
@Override
public void removeFromNetwork()
{
energyNetwork.removeCable(this);
}
@Override
public void refreshNetwork()
@ -101,4 +145,11 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
{
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