Working on item networks for AL
This commit is contained in:
parent
06c4b331b6
commit
4d17561a37
8 changed files with 230 additions and 86 deletions
|
@ -1,57 +0,0 @@
|
|||
package basiccomponents.api;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This should be the only class you include in your mod. If your mod is a coremod, feel free to
|
||||
* download Basic Components Core directly during run-time.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
||||
public class BasicRegistry
|
||||
{
|
||||
public static final Set<String> requests = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* @param request - Name of the item/block to register. Use the EXACT FIELD NAME of the
|
||||
* BasicComponents.java field.
|
||||
*/
|
||||
public static void register(String request)
|
||||
{
|
||||
requests.add(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests all items in Basic Components.
|
||||
*/
|
||||
public static void requestAll()
|
||||
{
|
||||
register("ingotCopper");
|
||||
register("ingotTin");
|
||||
|
||||
register("oreCopper");
|
||||
register("oreTin");
|
||||
|
||||
register("ingotSteel");
|
||||
register("dustSteel");
|
||||
register("plateSteel");
|
||||
|
||||
register("ingotBronze");
|
||||
register("dustBronze");
|
||||
register("plateBronze");
|
||||
|
||||
register("plateCopper");
|
||||
register("plateTin");
|
||||
register("plateIron");
|
||||
register("plateGold");
|
||||
|
||||
register("circuitBasic");
|
||||
register("circuitAdvanced");
|
||||
register("circuitElite");
|
||||
|
||||
register("motor");
|
||||
register("wrench");
|
||||
}
|
||||
}
|
22
src/dark/api/parts/IMotionPath.java
Normal file
22
src/dark/api/parts/IMotionPath.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package dark.api.parts;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public interface IMotionPath
|
||||
{
|
||||
|
||||
/** Gets the motion applied to the entity while its on the tile **/
|
||||
public Vector3 getMotion(Entity entity);
|
||||
|
||||
/** Can the path controller move the entity over this tile. Make sure to check the position of
|
||||
* the tile as the controller doesn't know the range of control of the tile. Though it does
|
||||
* limit itself to blocks around the entity. So if your tile only effects entities above it
|
||||
* within its bound then make sure the tile is inside those bounds
|
||||
*
|
||||
* @param entity - entity in question
|
||||
* @param from - direction the entity came from
|
||||
* @return true if it can, false if something is wrong like no power, or solid side */
|
||||
public boolean canMoveEntity(Entity entity);
|
||||
}
|
|
@ -28,6 +28,9 @@ public interface ITileNetwork
|
|||
/** Called when this network is just created */
|
||||
public void onCreated();
|
||||
|
||||
/** How many ticks should base between updates, return 0 or bellow for no ticks */
|
||||
public int getUpdateRate();
|
||||
|
||||
/** Called every so many ticks so the network has a chance to update */
|
||||
public void updateTick();
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@ import cpw.mods.fml.common.Mod.EventHandler;
|
|||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import dark.core.common.ExternalModHandler;
|
||||
import dark.core.prefab.helpers.FluidHelper;
|
||||
import dark.core.prefab.tilenetwork.NetworkUpdateHandler;
|
||||
import dark.core.registration.ModObjectRegistry;
|
||||
import dark.core.save.SaveManager;
|
||||
|
||||
|
@ -48,6 +50,8 @@ public abstract class ModPrefab
|
|||
|
||||
private static Triple<Integer, Integer, Integer> date;
|
||||
|
||||
private static boolean preInit, init, postInit;
|
||||
|
||||
public abstract String getDomain();
|
||||
|
||||
/** Gets the next unused ID in the block list. Does not prevent config file issues after the file
|
||||
|
@ -92,26 +96,41 @@ public abstract class ModPrefab
|
|||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
this.loadModMeta();
|
||||
|
||||
Modstats.instance().getReporter().registerMod(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new FluidHelper());
|
||||
MinecraftForge.EVENT_BUS.register(SaveManager.instance());
|
||||
UniversalElectricity.initiate();
|
||||
Compatibility.initiate();
|
||||
if (!preInit)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(new FluidHelper());
|
||||
MinecraftForge.EVENT_BUS.register(SaveManager.instance());
|
||||
TickRegistry.registerTickHandler(NetworkUpdateHandler.instance(), Side.SERVER);
|
||||
UniversalElectricity.initiate();
|
||||
Compatibility.initiate();
|
||||
preInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
ExternalModHandler.init();
|
||||
ModObjectRegistry.masterBlockConfig.load();
|
||||
if (!init)
|
||||
{
|
||||
ExternalModHandler.init();
|
||||
ModObjectRegistry.masterBlockConfig.load();
|
||||
init = true;
|
||||
}
|
||||
this.registerObjects();
|
||||
ModObjectRegistry.masterBlockConfig.save();
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
if (!postInit)
|
||||
{
|
||||
ModObjectRegistry.masterBlockConfig.save();
|
||||
postInit = true;
|
||||
}
|
||||
this.loadRecipes();
|
||||
}
|
||||
|
||||
|
|
119
src/dark/core/prefab/tilenetwork/NetworkItemSupply.java
Normal file
119
src/dark/core/prefab/tilenetwork/NetworkItemSupply.java
Normal file
|
@ -0,0 +1,119 @@
|
|||
package dark.core.prefab.tilenetwork;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
|
||||
import dark.api.parts.IMotionPath;
|
||||
import dark.api.parts.INetworkPart;
|
||||
|
||||
/** Class that acts like the redpower pipes system. Each item is marked with a destination. Intended
|
||||
* use it to improve the assembly line network
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class NetworkItemSupply extends NetworkTileEntities
|
||||
{
|
||||
List<Pair<Entity, Vector3>> trackingList = new ArrayList<Pair<Entity, Vector3>>();
|
||||
List<Entity> ignoreList = new ArrayList<Entity>();
|
||||
/** Same as valid directions from forge direction enum but Unknown was added so that is gets check and checked first */
|
||||
public static final ForgeDirection[] VALID_DIRECTIONS = {ForgeDirection.UNKNOWN, ForgeDirection.DOWN, ForgeDirection.UP, ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST};
|
||||
|
||||
public NetworkItemSupply(INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick()
|
||||
{
|
||||
Iterator<Pair<Entity, Vector3>> it = trackingList.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Pair<Entity, Vector3> entry = it.next();
|
||||
if (entry.left() == null || !this.isOnPath(entry.left()))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entry.right() == null)
|
||||
{
|
||||
entry.setRight(new Vector3(entry.left()));
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.left().setPosition(entry.right().x, entry.right().y, entry.right().z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUpdateRate()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Remove an entity from the tracking list */
|
||||
public void removeEntity(Entity entity)
|
||||
{
|
||||
this.trackingList.remove(entity);
|
||||
}
|
||||
|
||||
/** Ignores an entity so that is can be controlled by something else for a while. Eg armbots, and
|
||||
* drones */
|
||||
public void ignoreEntity(Entity entity)
|
||||
{
|
||||
if (!this.ignoreList.contains(entity))
|
||||
{
|
||||
this.ignoreList.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/** Add and entity to the tracking list */
|
||||
public void addEntity(Entity entity)
|
||||
{
|
||||
if (!this.trackingList.contains(entity))
|
||||
{
|
||||
this.trackingList.add(new Pair<Entity, Vector3>(entity, new Vector3(entity)));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTrackingEntity(Entity entity)
|
||||
{
|
||||
return this.trackingList.contains(entity);
|
||||
}
|
||||
|
||||
public boolean isOnPath(Entity entity)
|
||||
{
|
||||
if (entity != null)
|
||||
{
|
||||
Vector3 ent = new Vector3(entity);
|
||||
//Check all directions including the current position of the entity
|
||||
for (ForgeDirection direction : this.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity a = ent.clone().modifyPositionFromSide(direction).getTileEntity(entity.worldObj);
|
||||
if (a instanceof IMotionPath && ((IMotionPath) a).canMoveEntity(entity) && this.networkMembers.contains(a))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidMember(INetworkPart part)
|
||||
{
|
||||
return super.isValidMember(part) && part instanceof IMotionPath;
|
||||
}
|
||||
|
||||
}
|
29
src/dark/core/prefab/tilenetwork/NetworkResourceSupply.java
Normal file
29
src/dark/core/prefab/tilenetwork/NetworkResourceSupply.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package dark.core.prefab.tilenetwork;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import dark.api.parts.INetworkPart;
|
||||
|
||||
/** Network that supplies resources to tiles that demand a set resource
|
||||
*
|
||||
* @param C - Storage class used to handle what the network transports
|
||||
* @param I - Base acceptor class
|
||||
* @author DarkGuardsman */
|
||||
public class NetworkResourceSupply<C, I> extends NetworkTileEntities
|
||||
{
|
||||
protected C storage;
|
||||
protected HashMap<I, List<ForgeDirection>> acceptors = new HashMap();
|
||||
|
||||
public NetworkResourceSupply(INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
}
|
||||
|
||||
public boolean isValidAcceptor(TileEntity entity)
|
||||
{
|
||||
return entity != null && !entity.isInvalid();
|
||||
}
|
||||
}
|
|
@ -19,11 +19,12 @@ public class NetworkTileEntities implements ITileNetwork
|
|||
|
||||
public NetworkTileEntities()
|
||||
{
|
||||
|
||||
NetworkUpdateHandler.instance().registerNetwork(this);
|
||||
}
|
||||
|
||||
public NetworkTileEntities(INetworkPart... parts)
|
||||
{
|
||||
this();
|
||||
if (parts != null)
|
||||
{
|
||||
for (INetworkPart part : parts)
|
||||
|
@ -56,6 +57,12 @@ public class NetworkTileEntities implements ITileNetwork
|
|||
this.cleanUpMembers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUpdateRate()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick()
|
||||
{
|
||||
|
@ -170,7 +177,7 @@ public class NetworkTileEntities implements ITileNetwork
|
|||
/** Merges the two networks together */
|
||||
protected void mergeDo(ITileNetwork network)
|
||||
{
|
||||
ITileNetwork newNetwork = NetworkHandler.createNewNetwork(NetworkHandler.getID(this.getClass()));
|
||||
ITileNetwork newNetwork = NetworkUpdateHandler.createNewNetwork(NetworkUpdateHandler.getID(this.getClass()));
|
||||
newNetwork.getMembers().addAll(this.getMembers());
|
||||
newNetwork.getMembers().addAll(network.getMembers());
|
||||
newNetwork.onCreated();
|
||||
|
@ -200,7 +207,7 @@ public class NetworkTileEntities implements ITileNetwork
|
|||
{
|
||||
this.save();
|
||||
/* NO LONGER CONNECTED ELSE WHERE SO SPLIT AND REFRESH */
|
||||
ITileNetwork newNetwork = NetworkHandler.createNewNetwork(NetworkHandler.getID(this.getClass()));
|
||||
ITileNetwork newNetwork = NetworkUpdateHandler.createNewNetwork(NetworkUpdateHandler.getID(this.getClass()));
|
||||
if (newNetwork != null)
|
||||
{
|
||||
for (Vector3 node : finder.closedSet)
|
||||
|
|
|
@ -7,42 +7,49 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import cpw.mods.fml.common.IScheduledTickHandler;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import dark.api.parts.ITileNetwork;
|
||||
|
||||
/** Manages all the tile networks making sure they get world save events, and updates every so often
|
||||
*
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class NetworkHandler implements IScheduledTickHandler
|
||||
public class NetworkUpdateHandler implements ITickHandler
|
||||
{
|
||||
private static HashMap<String, Class<?>> nameToClassMap = new HashMap<String, Class<?>>();
|
||||
private static HashMap<Class<?>, String> classToNameMap = new HashMap<Class<?>, String>();
|
||||
|
||||
private byte count = 0;
|
||||
private int count = 0;
|
||||
private static int refreshTicks = 6000;
|
||||
|
||||
private Set<ITileNetwork> networks = new HashSet();
|
||||
private Set<ITileNetwork> activeNetworks = new HashSet();
|
||||
private Set<ITileNetwork> allNetworks = new HashSet();
|
||||
|
||||
private static NetworkHandler instance;
|
||||
private static NetworkUpdateHandler instance;
|
||||
|
||||
static
|
||||
{
|
||||
registerNetworkClass("base", NetworkTileEntities.class);
|
||||
}
|
||||
|
||||
public static NetworkHandler instance()
|
||||
public static NetworkUpdateHandler instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new NetworkHandler();
|
||||
instance = new NetworkUpdateHandler();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void registerNetwork(ITileNetwork network)
|
||||
{
|
||||
if (!networks.contains(network))
|
||||
if (network != null && !activeNetworks.contains(network))
|
||||
{
|
||||
this.networks.add(network);
|
||||
this.allNetworks.add(network);
|
||||
if (network.getUpdateRate() > 0)
|
||||
{
|
||||
this.activeNetworks.add(network);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,10 +102,10 @@ public class NetworkHandler implements IScheduledTickHandler
|
|||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
if (count + 1 >= Byte.MAX_VALUE)
|
||||
if (count + 1 >= this.refreshTicks)
|
||||
{
|
||||
count = 0;
|
||||
for (ITileNetwork network : networks)
|
||||
for (ITileNetwork network : allNetworks)
|
||||
{
|
||||
if (!network.isInvalid())
|
||||
{
|
||||
|
@ -109,7 +116,7 @@ public class NetworkHandler implements IScheduledTickHandler
|
|||
else
|
||||
{
|
||||
count++;
|
||||
for (ITileNetwork network : networks)
|
||||
for (ITileNetwork network : activeNetworks)
|
||||
{
|
||||
if (!network.isInvalid())
|
||||
{
|
||||
|
@ -123,7 +130,7 @@ public class NetworkHandler implements IScheduledTickHandler
|
|||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
Iterator<ITileNetwork> it = networks.iterator();
|
||||
Iterator<ITileNetwork> it = activeNetworks.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
ITileNetwork network = it.next();
|
||||
|
@ -131,6 +138,7 @@ public class NetworkHandler implements IScheduledTickHandler
|
|||
{
|
||||
network.invalidate();
|
||||
it.remove();
|
||||
allNetworks.remove(network);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,10 +155,4 @@ public class NetworkHandler implements IScheduledTickHandler
|
|||
{
|
||||
return "[CoreMachine]TileNetworkHandler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextTickSpacing()
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue