Separate the static travelling item collection between client and server

This commit is contained in:
Krapht 2012-08-26 12:56:34 +02:00
parent 7faf685e42
commit ab119af770
2 changed files with 19 additions and 6 deletions

View file

@ -4,11 +4,17 @@ import java.util.TreeMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import net.minecraft.src.World; import net.minecraft.src.World;
public abstract class PipeManager { public abstract class PipeManager {
public static TreeMap<Integer, IPipedItem> allEntities = new TreeMap<Integer, IPipedItem>(); private static TreeMap<Integer, IPipedItem> allServerEntities = new TreeMap<Integer, IPipedItem>();
private static TreeMap<Integer, IPipedItem> allClientEntities = new TreeMap<Integer, IPipedItem>();
public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>(); public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>();
public static void registerExtractionHandler(IExtractionHandler handler) { public static void registerExtractionHandler(IExtractionHandler handler) {
@ -30,4 +36,11 @@ public abstract class PipeManager {
return true; return true;
} }
public static TreeMap<Integer, IPipedItem> getAllEntities(){
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
return allClientEntities;
}
return allServerEntities;
}
} }

View file

@ -52,7 +52,7 @@ public class EntityPassiveItem implements IPipedItem {
public EntityPassiveItem(World world, int id) { public EntityPassiveItem(World world, int id) {
setEntityId(id); setEntityId(id);
PipeManager.allEntities.put(getEntityId(), this); PipeManager.getAllEntities().put(getEntityId(), this);
worldObj = world; worldObj = world;
} }
@ -69,8 +69,8 @@ public class EntityPassiveItem implements IPipedItem {
/* CREATING & CACHING */ /* CREATING & CACHING */
public static IPipedItem getOrCreate(World world, int id) { public static IPipedItem getOrCreate(World world, int id) {
if (PipeManager.allEntities.containsKey(id)) { if (PipeManager.getAllEntities().containsKey(id)) {
return PipeManager.allEntities.get(id); return PipeManager.getAllEntities().get(id);
} else { } else {
return new EntityPassiveItem(world, id); return new EntityPassiveItem(world, id);
} }
@ -81,8 +81,8 @@ public class EntityPassiveItem implements IPipedItem {
*/ */
@Override @Override
public void remove() { public void remove() {
if (PipeManager.allEntities.containsKey(getEntityId())) { if (PipeManager.getAllEntities().containsKey(getEntityId())) {
PipeManager.allEntities.remove(getEntityId()); PipeManager.getAllEntities().remove(getEntityId());
} }
} }