Files
Mekanism-Community-Edition/src/minecraft/mekanism/common/CommonWorldTickHandler.java
T
Aidan Brady a51050e30f v5.5.6 Beta #18
*Robit GUI closes when "go home" called.
*Refactor multiblock inventory system to use only 1 map.
*Better-balanced recipes.
*Metallurgic Infuser now has a purple side by default.
*Configurable generation for MekanismGenerators.
*isAirBlock() instead of explicit id == 0 check.
*doubles instead of ints.
2013-06-19 14:11:29 -04:00

103 lines
2.4 KiB
Java

package mekanism.common;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import mekanism.api.Object3D;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
public class CommonWorldTickHandler implements ITickHandler
{
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
if(tickData[0] instanceof World)
{
ArrayList<Integer> idsToKill = new ArrayList<Integer>();
HashMap<Integer, HashSet<Object3D>> tilesToKill = new HashMap<Integer, HashSet<Object3D>>();
World world = (World)tickData[0];
if(!world.isRemote)
{
for(Map.Entry<Integer, DynamicTankCache> entry : Mekanism.dynamicInventories.entrySet())
{
int inventoryID = entry.getKey();
for(Object3D obj : entry.getValue().locations)
{
if(obj.dimensionId == world.provider.dimensionId)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(world);
if(tileEntity == null || tileEntity.inventoryID != inventoryID)
{
if(!tilesToKill.containsKey(inventoryID))
{
tilesToKill.put(inventoryID, new HashSet<Object3D>());
}
tilesToKill.get(inventoryID).add(obj);
}
}
}
if(entry.getValue().locations.isEmpty())
{
idsToKill.add(inventoryID);
}
}
for(Map.Entry<Integer, HashSet<Object3D>> entry : tilesToKill.entrySet())
{
for(Object3D obj : entry.getValue())
{
Mekanism.dynamicInventories.get(entry.getKey()).locations.remove(obj);
}
}
for(int inventoryID : idsToKill)
{
for(Object3D obj : Mekanism.dynamicInventories.get(inventoryID).locations)
{
TileEntityDynamicTank dynamicTank = (TileEntityDynamicTank)obj.getTileEntity(world);
if(dynamicTank != null)
{
dynamicTank.cachedLiquid = null;
dynamicTank.inventory = new ItemStack[2];
dynamicTank.inventoryID = -1;
}
}
Mekanism.dynamicInventories.remove(inventoryID);
}
}
}
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.WORLD);
}
@Override
public String getLabel()
{
return "MekanismCommonWorld";
}
}