*Remade module system. Much more efficient and just plain better.

*Client update thread works much better now.
*Fixed bug where client update doesn't remove old modules.
*Removed Mekanism damage source, useless.
*Removed MachineryManager, it's the cause of world leaks.
*Much better upgrade notification, lets you know which modules are
outdated.
*Gave each module a unique version number.
*Crafting recipe for the Electric Pump.
*Removed IC2 coal dust dependency.
*Crusher recipe for Charcoal Dust in a different mod.
*Made the pump work much, much better.
This commit is contained in:
Aidan Brady 2013-04-06 13:28:59 -04:00
parent 5f496a00ec
commit f464d2143b
13 changed files with 338 additions and 275 deletions

View file

@ -2,8 +2,10 @@ package mekanism.client;
import cpw.mods.fml.common.Loader;
import mekanism.api.EnumColor;
import mekanism.common.IModule;
import mekanism.common.Mekanism;
import mekanism.common.MekanismUtils;
import mekanism.common.Version;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
@ -19,7 +21,7 @@ public class GuiCredits extends GuiScreen
buttonList.clear();
buttonList.add(new GuiButton(0, width / 2 - 100, height / 4 + 72 + 12, "Update"));
buttonList.add(new GuiButton(1, width / 2 - 100, height / 4 + 96 + 12, "Cancel"));
((GuiButton)buttonList.get(0)).enabled = !MekanismUtils.isNotOutdated() && !ThreadClientUpdate.hasUpdated;
((GuiButton)buttonList.get(0)).enabled = !MekanismUtils.noUpdates() && !ThreadClientUpdate.hasUpdated;
}
public static void onFinishedDownloading()
@ -43,22 +45,23 @@ public class GuiCredits extends GuiScreen
}
if(guibutton.id == 0)
{
if(!MekanismUtils.isNotOutdated())
if(!MekanismUtils.noUpdates())
{
updatedRecently = true;
updateProgress = "Downloading latest version...";
guibutton.enabled = false;
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/Mekanism-v" + Mekanism.latestVersionNumber + ".jar", 0);
if(Loader.isModLoaded("MekanismGenerators"))
if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/MekanismGenerators-v" + Mekanism.latestVersionNumber + ".jar", 1);
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/Mekanism-v" + Mekanism.latestVersionNumber + ".jar", "");
}
if(Loader.isModLoaded("MekanismTools"))
for(IModule module : Mekanism.modulesLoaded)
{
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/MekanismTools-v" + Mekanism.latestVersionNumber + ".jar", 2);
if(module.getVersion().comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/Mekanism" + module.getName() + "-v" + Mekanism.latestVersionNumber + ".jar", module.getName());
}
}
}
else {
@ -100,12 +103,21 @@ public class GuiCredits extends GuiScreen
drawDefaultBackground();
drawCenteredString(fontRenderer, EnumColor.DARK_BLUE + "Mekanism" + EnumColor.GREY + " by aidancbrady", width / 2, (height / 4 - 60) + 20, 0xffffff);
writeText(EnumColor.GREY + "Your version: " + (MekanismUtils.isNotOutdated() ? Mekanism.versionNumber : EnumColor.DARK_RED + Mekanism.versionNumber.toString() + EnumColor.GREY + " -- OUTDATED"), 36);
writeText(EnumColor.GREY + "Newest version: " + Mekanism.latestVersionNumber, 45);
writeText(EnumColor.GREY + "*Developed on Mac OS X 10.8 Mountain Lion", 63);
writeText(EnumColor.GREY + "*Code, textures, and ideas by aidancbrady", 72);
writeText(EnumColor.GREY + "Recent news: " + EnumColor.DARK_BLUE + (!Mekanism.recentNews.contains("null") ? Mekanism.recentNews : "couldn't access."), 81);
writeText(EnumColor.GREY + updateProgress, 99);
writeText(EnumColor.INDIGO + "Mekanism " + (Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1 ? EnumColor.DARK_RED : EnumColor.GREY) + Mekanism.versionNumber, 36);
int size = 36;
for(IModule module : Mekanism.modulesLoaded)
{
size += 9;
writeText(EnumColor.INDIGO + "Mekanism" + module.getName() + (module.getVersion().comparedState(Version.get(Mekanism.latestVersionNumber)) == -1 ? EnumColor.DARK_RED : EnumColor.GREY) + " " + module.getVersion(), size);
}
writeText(EnumColor.GREY + "Newest version: " + Mekanism.latestVersionNumber, size+9);
writeText(EnumColor.GREY + "*Developed on Mac OS X 10.8 Mountain Lion", size+18);
writeText(EnumColor.GREY + "*Code, textures, and ideas by aidancbrady", size+27);
writeText(EnumColor.GREY + "Recent news: " + EnumColor.DARK_BLUE + (!Mekanism.recentNews.contains("null") ? Mekanism.recentNews : "couldn't access."), size+36);
writeText(EnumColor.GREY + updateProgress, size+45);
super.drawScreen(i, j, f);
}
}

View file

@ -16,19 +16,19 @@ import net.minecraft.client.Minecraft;
*/
public class ThreadClientUpdate extends Thread
{
private int downloadType;
private int bytesDownloaded;
private int lastBytesDownloaded;
private byte[] buffer = new byte[10240];
private URL url;
public String moduleName;
public static int modulesBeingDownloaded;
public static boolean hasUpdated;
public ThreadClientUpdate(String location, int type)
public ThreadClientUpdate(String location, String name)
{
moduleName = name;
modulesBeingDownloaded++;
downloadType = type;
try {
url = new URL(location);
setDaemon(false);
@ -41,8 +41,7 @@ public class ThreadClientUpdate extends Thread
@Override
public void run()
{
String downloadName = downloadType == 0 ? "" : (downloadType == 1 ? "Generators" : "Tools");
File download = new File(new StringBuilder().append(Minecraft.getMinecraftDir()).append(File.separator + "mods" + File.separator + "Mekanism" + downloadName + "-v" + Mekanism.latestVersionNumber + ".jar").toString());
File download = new File(new StringBuilder().append(Minecraft.getMinecraftDir()).append(File.separator + "mods" + File.separator + "Mekanism" + moduleName + "-v" + Mekanism.latestVersionNumber + ".jar").toString());
try {
prepareForDownload();
download.createNewFile();
@ -83,7 +82,7 @@ public class ThreadClientUpdate extends Thread
for(File file : modsList)
{
if(file.getName().startsWith("Mekanism") && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber))
if(file.getName().startsWith("Mekanism" + moduleName) && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber))
{
file.delete();
}

View file

@ -556,7 +556,7 @@ public class BlockMachine extends BlockContainer implements IDismantleable
}
}
if (tileEntity != null)
if(tileEntity != null)
{
if(metadata != MachineType.TELEPORTER.meta)
{

View file

@ -1,34 +0,0 @@
package mekanism.common;
import net.minecraft.entity.Entity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSourceIndirect;
public class DamageSourceMekanism extends EntityDamageSourceIndirect
{
private Entity damageSourceProjectile;
private Entity damageSourceEntity;
public DamageSourceMekanism(String s, Entity entity, Entity entity1)
{
super(s, entity, entity1);
damageSourceProjectile = entity;
damageSourceEntity = entity1;
}
public Entity getProjectile()
{
return damageSourceProjectile;
}
@Override
public Entity getEntity()
{
return damageSourceEntity;
}
public static DamageSource causeWeaponDamage(Entity entity, Entity entity1)
{
return (new DamageSourceMekanism("weapon", entity, entity1)).setProjectile();
}
}

View file

@ -0,0 +1,22 @@
package mekanism.common;
/**
* Implement in your main class if your mod happens to be completely reliant on Mekanism, or in other words, a Mekanism module.
* @author aidancbrady
*
*/
public interface IModule
{
/**
* Gets the version of the module.
* @return the module's version
*/
public Version getVersion();
/**
* Gets the name of the module. Note that this doesn't include "Mekanism" like the actual module's name does, just the
* unique name. For example, MekanismGenerators returns "Generators" here.
* @return unique name of the module
*/
public String getName();
}

View file

@ -1,108 +0,0 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.World;
/**
* A simple way of managing all machines -- MachineryManager! Contains an ArrayList of
* basic machines that all machines are added to on placement.
* @author AidanBrady
*
*/
public class MachineryManager
{
/** The list of machines used */
public List<TileEntityBasicMachine> machines = new ArrayList<TileEntityBasicMachine>();
/**
* MachineryManager -- the easiest way of managing machines.
*/
public MachineryManager()
{
reset();
System.out.println("[Mekanism] Successfully initialized Machinery Manager.");
}
/**
* Register a machine with the manager.
* @param machine - to be added
*/
public void register(TileEntityBasicMachine machine)
{
if(!machines.contains(machine))
{
machines.add(machine);
}
else {
System.out.println("[Mekanism] Attempted to add machine to manager that already exists.");
}
}
/**
* Remove a machine from the manager.
* @param machine - to be removed
*/
public void remove(TileEntityBasicMachine machine)
{
if(machines.contains(machine))
{
machines.remove(machine);
}
else {
System.out.println("[Mekanism] Attempted to remove machine from manager that doesn't exist.");
}
}
/**
* Grabs a machine from the manager.
* @param world - to be grabbed
* @param x - block coord
* @param y - block coord
* @param z - block coord
* @return machine grabbed from the manager
*/
public TileEntityBasicMachine getMachine(World world, int x, int y, int z)
{
if(machines.contains((TileEntityBasicMachine)world.getBlockTileEntity(x, y, z)))
{
return (TileEntityBasicMachine)world.getBlockTileEntity(x, y, z);
}
else {
System.out.println("[Mekanism] Attempted to grab machine from manager that doesn't exist.");
return null;
}
}
/**
* Destroys all machines registered, as well as removing them from the manager's ArrayList.
* @param explode - whether or not to show fake explosion
*/
public void destroyAll(boolean explode)
{
for(TileEntityBasicMachine machine : machines)
{
if(explode)
{
MekanismUtils.doFakeBlockExplosion(machine.worldObj, machine.xCoord, machine.yCoord, machine.zCoord);
}
machine.worldObj.setBlockToAir(machine.xCoord, machine.yCoord, machine.zCoord);
machine.worldObj.removeBlockTileEntity(machine.xCoord, machine.yCoord, machine.zCoord);
remove(machine);
}
}
public int size()
{
return machines.size();
}
/**
* Resets the manager -- removing all machines from the ArrayList
*/
public void reset()
{
machines.clear();
}
}

View file

@ -87,16 +87,13 @@ public class Mekanism
public static CreativeTabMekanism tabMekanism = new CreativeTabMekanism();
/** List of Mekanism modules loaded */
public static List modulesLoaded = new ArrayList();
public static List<IModule> modulesLoaded = new ArrayList<IModule>();
/** The latest version number which is received from the Mekanism server */
public static String latestVersionNumber;
/** The recent news which is received from the Mekanism server */
public static String recentNews;
/** The main MachineryManager instance that is used by all machines */
public static MachineryManager manager;
@SideOnly(Side.CLIENT)
/** The main SoundHandler instance that is used by all audio sources */
@ -305,7 +302,7 @@ public class Mekanism
"OOO", "OGO", "OOO", Character.valueOf('O'), "ingotRefinedObsidian", Character.valueOf('G'), "ingotRefinedGlowstone"
}));
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(Transmitter, 8, 0), new Object[] {
"OOO", "GGG", "OOO", Character.valueOf('O'), "ingotOsmium", Character.valueOf('G'), Block.glass
"OGO", Character.valueOf('O'), "ingotOsmium", Character.valueOf('G'), Block.glass
}));
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(BasicBlock, 1, 8), new Object[] {
" S ", "SPS", " S ", Character.valueOf('S'), "ingotSteel", Character.valueOf('P'), "ingotOsmium"
@ -314,7 +311,10 @@ public class Mekanism
"SCS", "GIG", "SCS", Character.valueOf('S'), Block.cobblestone, Character.valueOf('C'), ControlCircuit, Character.valueOf('G'), Block.glass, Character.valueOf('I'), new ItemStack(BasicBlock, 1, 8)
}));
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(Transmitter, 8, 1), new Object[] {
"OOO", "RRR", "OOO", Character.valueOf('O'), "ingotOsmium", Character.valueOf('R'), Item.redstone
"ORO", Character.valueOf('O'), "ingotOsmium", Character.valueOf('R'), Item.redstone
}));
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(MachineBlock, 1, 12), new Object[] {
" B ", "ECE", "OOO", Character.valueOf('B'), Item.bucketWater, Character.valueOf('E'), EnrichedAlloy, Character.valueOf('C'), new ItemStack(BasicBlock, 1, 8), Character.valueOf('O'), "ingotOsmium"
}));
//Factory Recipes
@ -652,8 +652,6 @@ public class Mekanism
{
Ic2Recipes.addMaceratorRecipe(new ItemStack(Block.obsidian), new ItemStack(DirtyDust, 1, 6));
}
RecipeHandler.addCrusherRecipe(new ItemStack(Item.coal), hooks.IC2CoalDust);
}
for(ItemStack ore : OreDictionary.getOres("dustRefinedObsidian"))
@ -810,6 +808,14 @@ public class Mekanism
FurnaceRecipes.smelting().addSmelting(Dust.itemID, 8, MekanismUtils.getStackWithSize(OreDictionary.getOres("ingotSilver").get(0), 1), 1.0F);
} catch(Exception e) {}
try {
RecipeHandler.addCrusherRecipe(new ItemStack(Item.coal), MekanismUtils.getStackWithSize(OreDictionary.getOres("dustCoal").get(0), 1));
} catch(Exception e) {}
try {
RecipeHandler.addCrusherRecipe(new ItemStack(Item.coal, 1, 1), MekanismUtils.getStackWithSize(OreDictionary.getOres("dustCharcoal").get(0), 1));
} catch(Exception e) {}
try {
for(ItemStack ore : OreDictionary.getOres("ingotCopper"))
{
@ -973,18 +979,12 @@ public class Mekanism
@Init
public void init(FMLInitializationEvent event)
{
//Add this module to the core list
modulesLoaded.add(this);
//Register the mod's ore handler
GameRegistry.registerWorldGenerator(new OreHandler());
//Register the mod's GUI handler
NetworkRegistry.instance().registerGuiHandler(this, new CoreGuiHandler());
//Register the MachineryManager
manager = new MachineryManager();
//Initialization notification
System.out.println("[Mekanism] Version " + versionNumber + " initializing...");

View file

@ -14,7 +14,6 @@ import net.minecraft.item.ItemStack;
*/
public final class MekanismHooks
{
private Class Ic2Items;
private Class IC2;
private Class Railcraft;
@ -26,8 +25,6 @@ public final class MekanismHooks
private Class ForestryItem;
private Class Forestry;
public ItemStack IC2CoalDust;
public int BuildCraftFuelID = 19108;
public ItemStack BuildCraftFuelBucket;
@ -55,8 +52,6 @@ public final class MekanismHooks
if(IC2Loaded)
{
IC2CoalDust = getIC2Item("coalDust");
Ic2Recipes.addMaceratorRecipe(new ItemStack(Mekanism.OreBlock, 1, 0), new ItemStack(Mekanism.Dust, 2, 2));
Ic2Recipes.addMaceratorRecipe(new ItemStack(Mekanism.Ingot, 1, 1), new ItemStack(Mekanism.Dust, 1, 2));
@ -75,10 +70,6 @@ public final class MekanismHooks
System.out.println("[Mekanism] Hooked into IC2 successfully.");
}
if(RailcraftLoaded)
{
System.out.println("[Mekanism] Hooked into Railcraft successfully.");
}
if(BasicComponentsLoaded)
{
if(Mekanism.disableBCSteelCrafting)
@ -111,35 +102,6 @@ public final class MekanismHooks
}
}
/**
* Gets an object out of the class Ic2Items.
* @param name - name of the item
* @return the object
*/
public ItemStack getIC2Item(String name)
{
try {
if(Ic2Items == null) Ic2Items = Class.forName("ic2.core.Ic2Items");
if(Ic2Items == null) Ic2Items = Class.forName("net.minecraft.src.ic2.core.Ic2Items");
Object ret = Ic2Items.getField(name).get(null);
if(ret instanceof ItemStack)
{
return (ItemStack)ret;
}
else if(ret instanceof Block)
{
return new ItemStack((Block)ret);
}
else {
throw new Exception("not instanceof ItemStack");
}
} catch(Exception e) {
System.out.println("[Mekanism] Unable to retrieve IC2 item " + name + ".");
return null;
}
}
public ItemStack getBuildCraftItem(String name)
{
try {

View file

@ -66,10 +66,31 @@ public final class MekanismUtils
{
if(!Mekanism.latestVersionNumber.equals("null"))
{
if(Version.get(Mekanism.latestVersionNumber).comparedState(Mekanism.versionNumber) == 1)
ArrayList<IModule> list = new ArrayList<IModule>();
for(IModule module : Mekanism.modulesLoaded)
{
if(Version.get(Mekanism.latestVersionNumber).comparedState(module.getVersion()) == 1)
{
list.add(module);
}
}
if(Version.get(Mekanism.latestVersionNumber).comparedState(Mekanism.versionNumber) == 1 || !list.isEmpty())
{
entityplayer.addChatMessage(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " -------------");
entityplayer.addChatMessage(EnumColor.GREY + " Using outdated version " + EnumColor.DARK_GREY + Mekanism.versionNumber + EnumColor.GREY + " for your client.");
entityplayer.addChatMessage(EnumColor.GREY + " Using outdated version on one or more modules.");
if(Version.get(Mekanism.latestVersionNumber).comparedState(Mekanism.versionNumber) == 1)
{
entityplayer.addChatMessage(EnumColor.INDIGO + " Mekanism: " + EnumColor.DARK_RED + Mekanism.versionNumber);
}
for(IModule module : list)
{
entityplayer.addChatMessage(EnumColor.INDIGO + " Mekanism" + module.getName() + ": " + EnumColor.DARK_RED + module.getVersion());
}
entityplayer.addChatMessage(EnumColor.GREY + " Consider updating to version " + EnumColor.DARK_GREY + Mekanism.latestVersionNumber);
entityplayer.addChatMessage(EnumColor.GREY + " New features: " + EnumColor.INDIGO + Mekanism.recentNews);
entityplayer.addChatMessage(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------");
@ -218,12 +239,30 @@ public final class MekanismUtils
}
/**
* Checks if the mod is running on the latest version.
* @return if mod is latest version
* Checks if the mod doesn't need an update.
* @return if mod doesn't need an update
*/
public static boolean isNotOutdated()
public static boolean noUpdates()
{
return Mekanism.latestVersionNumber.contains("null") || Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) != -1;
if(Mekanism.latestVersionNumber.contains("null"))
{
return true;
}
if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
return false;
}
for(IModule module : Mekanism.modulesLoaded)
{
if(module.getVersion().comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
return false;
}
}
return true;
}
/**
@ -573,18 +612,18 @@ public final class MekanismUtils
*/
public static boolean isLiquid(World world, int x, int y, int z)
{
return getLiquidAndCleanup(world, x, y, z) != null;
return getLiquid(world, x, y, z) != null;
}
/**
* Gets a liquid from a certain location, or removes it if it's a dead lava block.
* Gets a liquid from a certain location.
* @param world - world the block is in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @return the liquid at the certain location, null if it doesn't exist
*/
public static LiquidStack getLiquidAndCleanup(World world, int x, int y, int z)
public static LiquidStack getLiquid(World world, int x, int y, int z)
{
int id = world.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
@ -598,20 +637,10 @@ public final class MekanismUtils
{
return new LiquidStack(Block.waterStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0);
}
else if((id == Block.waterStill.blockID || id == Block.waterMoving.blockID) && meta != 0)
{
world.setBlockToAir(x, y, z);
return null;
}
else if((id == Block.lavaStill.blockID || id == Block.lavaMoving.blockID) && meta == 0)
{
return new LiquidStack(Block.lavaStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0);
}
else if((id == Block.lavaStill.blockID || id == Block.lavaMoving.blockID) && meta != 0)
{
world.setBlockToAir(x, y, z);
return null;
}
else if(Block.blocksList[id] instanceof ILiquid)
{
ILiquid liquid = (ILiquid)Block.blocksList[id];
@ -624,14 +653,46 @@ public final class MekanismUtils
{
return new LiquidStack(liquid.stillLiquidId(), LiquidContainerRegistry.BUCKET_VOLUME, 0);
}
else {
world.setBlockToAir(x, y, z);
}
}
return null;
}
public static boolean isDeadLiquid(World world, int x, int y, int z)
{
int id = world.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(id == 0)
{
return false;
}
if((id == Block.waterStill.blockID || id == Block.waterMoving.blockID) && meta != 0)
{
return true;
}
else if((id == Block.lavaStill.blockID || id == Block.lavaMoving.blockID) && meta != 0)
{
return true;
}
else if(Block.blocksList[id] instanceof ILiquid)
{
ILiquid liquid = (ILiquid)Block.blocksList[id];
if(liquid.isMetaSensitive())
{
return liquid.stillLiquidMeta() != meta || liquid.stillLiquidId() != id;
}
else if(meta != 0)
{
return true;
}
}
return false;
}
/**
* Gets the distance between one block and another.
* @param blockOne - first block

View file

@ -64,9 +64,6 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp
/** The previous active state for this block. */
public boolean prevActive;
/** Whether or not this machine has been registered with the MachineryManager. */
public boolean registered;
/** The GUI texture path for this machine. */
public String guiTexturePath;
@ -94,12 +91,6 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp
{
super.onUpdate();
if(!registered && worldObj != null && !worldObj.isRemote)
{
Mekanism.manager.register(this);
registered = true;
}
if(worldObj.isRemote)
{
try {
@ -212,11 +203,6 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp
public void invalidate()
{
super.invalidate();
if(!worldObj.isRemote && registered)
{
Mekanism.manager.remove(this);
registered = false;
}
if(worldObj.isRemote && audio != null)
{

View file

@ -34,10 +34,16 @@ import net.minecraftforge.liquids.LiquidTank;
public class TileEntityElectricPump extends TileEntityElectricBlock implements ITankContainer, ISustainedTank
{
/** This pump's tank */
public LiquidTank liquidTank;
/** The nodes that have full sources near them or in them */
public Set<BlockWrapper> recurringNodes = new HashSet<BlockWrapper>();
/** The nodes that have already been sucked up, but are held on to in order to remove dead blocks */
public Set<BlockWrapper> cleaningNodes = new HashSet<BlockWrapper>();
/** Random for this pump */
public Random random = new Random();
public TileEntityElectricPump()
@ -117,6 +123,14 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
}
}
if(!suck(true) && !clean(true))
{
cleaningNodes.clear();
}
else {
clean(true);
}
if(liquidTank.getLiquid() != null)
{
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
@ -134,24 +148,56 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
}
}
}
if(!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0)
}
public boolean suck(boolean take)
{
if(!worldObj.isRemote && worldObj.getWorldTime() % 1 == 0)
{
if(electricityStored >= 100 && (liquidTank.getLiquid() == null || liquidTank.getLiquid().amount+LiquidContainerRegistry.BUCKET_VOLUME <= 10000))
if(/*electricityStored >= 100 && (liquidTank.getLiquid() == null || liquidTank.getLiquid().amount+LiquidContainerRegistry.BUCKET_VOLUME <= 10000)*/true)
{
List<BlockWrapper> tempPumpList = Arrays.asList(recurringNodes.toArray(new BlockWrapper[recurringNodes.size()]));
Collections.shuffle(tempPumpList);
for(BlockWrapper wrapper : cleaningNodes)
{
if(MekanismUtils.isLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z))
{
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z).isLiquidEqual(liquidTank.getLiquid()))
{
if(take)
{
setJoules(electricityStored - 100);
liquidTank.fill(MekanismUtils.getLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z), true);
worldObj.setBlockToAir(wrapper.x, wrapper.y, wrapper.z);
}
return true;
}
}
}
for(BlockWrapper wrapper : tempPumpList)
{
if(MekanismUtils.isLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z))
{
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquidAndCleanup(worldObj, wrapper.x, wrapper.y, wrapper.z).isLiquidEqual(liquidTank.getLiquid()))
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z).isLiquidEqual(liquidTank.getLiquid()))
{
if(take)
{
setJoules(electricityStored - 100);
liquidTank.fill(MekanismUtils.getLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z), true);
worldObj.setBlockToAir(wrapper.x, wrapper.y, wrapper.z);
}
return true;
}
}
else if(MekanismUtils.isDeadLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z))
{
if(take)
{
setJoules(electricityStored - 100);
liquidTank.fill(MekanismUtils.getLiquidAndCleanup(worldObj, wrapper.x, wrapper.y, wrapper.z), true);
worldObj.setBlockToAir(wrapper.x, wrapper.y, wrapper.z);
return;
}
}
@ -161,22 +207,34 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
int y = MekanismUtils.getCoords(wrapper, orientation)[1];
int z = MekanismUtils.getCoords(wrapper, orientation)[2];
if(MekanismUtils.getDistance(BlockWrapper.get(this), new BlockWrapper(x, y, z)) <= 60)
if(MekanismUtils.getDistance(BlockWrapper.get(this), new BlockWrapper(x, y, z)) <= 2340)
{
if(MekanismUtils.isLiquid(worldObj, x, y, z))
{
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z).isLiquidEqual(liquidTank.getLiquid()))
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquid(worldObj, x, y, z).isLiquidEqual(liquidTank.getLiquid()))
{
if(take)
{
setJoules(electricityStored - 100);
recurringNodes.add(new BlockWrapper(x, y, z));
liquidTank.fill(MekanismUtils.getLiquid(worldObj, x, y, z), true);
worldObj.setBlockToAir(x, y, z);
}
return true;
}
}
else if(MekanismUtils.isDeadLiquid(worldObj, x, y, z))
{
if(take)
{
setJoules(electricityStored - 100);
recurringNodes.add(new BlockWrapper(x, y, z));
liquidTank.fill(MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z), true);
worldObj.setBlockToAir(x, y, z);
return;
}
}
}
}
cleaningNodes.add(wrapper);
recurringNodes.remove(wrapper);
}
@ -190,19 +248,65 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
if(MekanismUtils.isLiquid(worldObj, x, y, z))
{
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z).isLiquidEqual(liquidTank.getLiquid()))
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquid(worldObj, x, y, z).isLiquidEqual(liquidTank.getLiquid()))
{
if(take)
{
setJoules(electricityStored - 100);
recurringNodes.add(new BlockWrapper(x, y, z));
liquidTank.fill(MekanismUtils.getLiquid(worldObj, x, y, z), true);
worldObj.setBlockToAir(x, y, z);
}
return true;
}
}
else if(MekanismUtils.isDeadLiquid(worldObj, x, y, z))
{
if(take)
{
setJoules(electricityStored - 100);
recurringNodes.add(new BlockWrapper(x, y, z));
liquidTank.fill(MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z), true);
worldObj.setBlockToAir(x, y, z);
return;
}
}
}
}
}
}
return false;
}
public boolean clean(boolean take)
{
boolean took = false;
if(!worldObj.isRemote)
{
for(BlockWrapper wrapper : cleaningNodes)
{
if(MekanismUtils.isDeadLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z))
{
took = true;
if(take)
{
worldObj.setBlockToAir(wrapper.x, wrapper.y, wrapper.z);
}
}
}
for(BlockWrapper wrapper : recurringNodes)
{
if(MekanismUtils.isDeadLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z))
{
took = true;
if(take)
{
worldObj.setBlockToAir(wrapper.x, wrapper.y, wrapper.z);
}
}
}
}
return took;
}
@Override
@ -257,18 +361,32 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
nbtTags.setTag("liquidTank", liquidTank.writeToNBT(new NBTTagCompound()));
}
NBTTagList tagList = new NBTTagList();
NBTTagList recurringList = new NBTTagList();
for(BlockWrapper wrapper : recurringNodes)
{
NBTTagCompound tagCompound = new NBTTagCompound();
wrapper.write(tagCompound);
tagList.appendTag(tagCompound);
recurringList.appendTag(tagCompound);
}
if(!tagList.tagList.isEmpty())
if(!recurringList.tagList.isEmpty())
{
nbtTags.setTag("recurringNodes", tagList);
nbtTags.setTag("recurringNodes", recurringList);
}
NBTTagList cleaningList = new NBTTagList();
for(BlockWrapper wrapper : cleaningNodes)
{
NBTTagCompound tagCompound = new NBTTagCompound();
wrapper.write(tagCompound);
cleaningList.appendTag(tagCompound);
}
if(!cleaningList.tagList.isEmpty())
{
nbtTags.setTag("cleaningNodes", cleaningList);
}
}
@ -291,6 +409,16 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
recurringNodes.add(BlockWrapper.read((NBTTagCompound)tagList.tagAt(i)));
}
}
if(nbtTags.hasKey("cleaningNodes"))
{
NBTTagList tagList = nbtTags.getTagList("cleaningNodes");
for(int i = 0; i < tagList.tagCount(); i++)
{
cleaningNodes.add(BlockWrapper.read((NBTTagCompound)tagList.tagAt(i)));
}
}
}
@Override

View file

@ -2,9 +2,11 @@ package mekanism.generators.common;
import mekanism.api.InfuseObject;
import mekanism.api.InfusionType;
import mekanism.common.IModule;
import mekanism.common.ItemMekanism;
import mekanism.common.Mekanism;
import mekanism.common.RecipeHandler;
import mekanism.common.Version;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.item.Item;
@ -12,6 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
@ -24,7 +27,7 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "MekanismGenerators", name = "MekanismGenerators", version = "5.5.4", dependencies = "required-after:Mekanism")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class MekanismGenerators
public class MekanismGenerators implements IModule
{
@SidedProxy(clientSide = "mekanism.generators.client.GeneratorsClientProxy", serverSide = "mekanism.generators.common.GeneratorsCommonProxy")
public static GeneratorsCommonProxy proxy;
@ -32,6 +35,9 @@ public class MekanismGenerators
@Instance("MekanismGenerators")
public static MekanismGenerators instance;
/** MekanismGenerators version number */
public static Version versionNumber = new Version(5, 5, 4);
//Items
public static Item BioFuel;
public static Item ElectrolyticCore;
@ -153,4 +159,16 @@ public class MekanismGenerators
OreDictionary.registerOre("itemBioFuel", new ItemStack(BioFuel));
}
@Override
public Version getVersion()
{
return versionNumber;
}
@Override
public String getName()
{
return "Generators";
}
}

View file

@ -14,7 +14,9 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.oredict.ShapedOreRecipe;
import mekanism.common.IModule;
import mekanism.common.Mekanism;
import mekanism.common.Version;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.Init;
@ -24,11 +26,14 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "MekanismTools", name = "MekanismTools", version = "5.5.4", dependencies = "required-after:Mekanism")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class MekanismTools
public class MekanismTools implements IModule
{
@Instance("MekanismTools")
public static MekanismTools instance;
/** MekanismTools version number */
public static Version versionNumber = new Version(5, 5, 4);
//Enums: Tools
public static EnumToolMaterial toolOBSIDIAN = EnumHelper.addToolMaterial("OBSIDIAN", 3, 2500, 20F, 10, 100);
public static EnumToolMaterial toolOBSIDIAN2 = EnumHelper.addToolMaterial("OBSIDIAN2", 3, 3000, 25F, 10, 100);
@ -588,4 +593,16 @@ public class MekanismTools
}
}
}
@Override
public Version getVersion()
{
return versionNumber;
}
@Override
public String getName()
{
return "Tools";
}
}