Skip to content

[WIP]Mod #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/MineCase.Core/Registry/IRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MineCase.Registry
{
public interface IRegistry<TK, TV>
{
TV GetObject(TK name);

// Register an object on this registry.
void PutObject(TK key, TV value);
}
}
67 changes: 67 additions & 0 deletions src/MineCase.Core/Registry/RegistryNamespaced.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace MineCase.Registry
{
public class RegistryNamespaced<TK, TV> : RegistrySimple<TK, TV>
{
/** The backing store that maps Integers to objects. */
protected readonly Dictionary<int, TV> underlyingIntegerMap = new Dictionary<int, TV>();

protected readonly Dictionary<TV, int> underlyingInversedIntegerMap = new Dictionary<TV, int>();

/** A BiMap of objects (key) to their names (value). */
protected readonly Dictionary<TV, TK> inverseObjectRegistry;

public RegistryNamespaced()
{
// this.inverseObjectRegistry = ((BiMap)this.registryObjects).inverse();
}

public void Register(int id, TK key, TV value)
{
underlyingIntegerMap.Add(id, value);
underlyingInversedIntegerMap.Add(value, id);
PutObject(key, value);
}

public override TV GetObject(TK name)
{
return GetObject(name);
}

/**
* Gets the name we use to identify the given object.
*/
public TK GetNameForObject(TV value)
{
return inverseObjectRegistry[value];
}

/**
* Does this registry contain an entry for the given key?
*/
public new bool ContainsKey(TK key)
{
return base.ContainsKey(key);
}

/**
* Gets the integer ID we use to identify the given object.
*/
public int GetIDForObject(TV value)
{
return underlyingInversedIntegerMap[value];
}

/**
* Gets the object identified by the given ID.
*/
public TV GetObjectById(int id)
{
return underlyingIntegerMap[id];
}
}
}
82 changes: 82 additions & 0 deletions src/MineCase.Core/Registry/RegistrySimple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MineCase.Registry
{
public class RegistrySimple<TK, TV> : IRegistry<TK, TV>
{
/** Objects registered on this registry. */
protected readonly Dictionary<TK, TV> registryObjects;
private TV[] values;

public RegistrySimple()
{
registryObjects = new Dictionary<TK, TV>();
}

public virtual TV GetObject( TK name)
{
return this.registryObjects[name];
}

/**
* Register an object on this registry.
*/
public void PutObject(TK key, TV value)
{
if (key == null)
{
throw new ArgumentNullException();
}

if (value == null)
{
throw new ArgumentNullException();
}

this.values = null;

if (this.registryObjects.ContainsKey(key))
{
// LOGGER.debug("Adding duplicate key '{}' to registry", key);
}

registryObjects.Add(key, value);
}

/**
* Gets all the keys recognized by this registry.
*/
public Dictionary<TK, TV>.KeyCollection GetKeys()
{
return registryObjects.Keys;
}

public TV GetRandomObject(Random random)
{
if (values == null)
{
var collection = registryObjects.Values;

if (collection.Count == 0)
{
return default(TV);
}

values = new TV[collection.Count];
collection.CopyTo(values, 0);
}

return values[random.Next(values.Length)];
}

/**
* Does this registry contain an entry for the given key?
*/
public bool ContainsKey(TK key)
{
return registryObjects.ContainsKey(key);
}
}
}
7 changes: 7 additions & 0 deletions src/MineCase.Mod/MineCase.Mod.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

</Project>
30 changes: 30 additions & 0 deletions src/MineCase.Mod/MinecraftMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MineCase.Mod.common.eventhandler;
using System;
using System.Collections.Generic;
using System.Text;

namespace MineCase.Mod
{
public class MinecraftMod
{
/**
* The core Forge EventBusses, all events for Forge will be fired on these,
* you should use this to register all your listeners.
* This replaces every register*Handler() function in the old version of Forge.
* TERRAIN_GEN_BUS for terrain gen events
* ORE_GEN_BUS for ore gen events
* EVENT_BUS for everything else
*/
public static readonly EventBus EVENT_BUS = new EventBus();
public static readonly EventBus TERRAIN_GEN_BUS = new EventBus();
public static readonly EventBus ORE_GEN_BUS = new EventBus();
// public static readonly string MC_VERSION = Loader.MC_VERSION;

static MinecraftMod()
{
EVENT_BUS = new EventBus();
TERRAIN_GEN_BUS = new EventBus();
ORE_GEN_BUS = new EventBus();
}
}
}
98 changes: 98 additions & 0 deletions src/MineCase.Mod/common/Loader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MineCase.Mod.common
{
public class Loader
{
// public static readonly String MC_VERSION = net.minecraftforge.common.ForgeVersion.mcVersion;
/**
* The singleton instance
*/
private static Loader instance;
/**
* Build information for tracking purposes.
*/
private static String major;
private static String minor;
private static String rev;
private static String build;
private static String mccversion;
private static String mcpversion;

/**
* The class loader we load the mods into.
*/
private ModClassLoader modClassLoader;
/**
* The sorted list of mods.
*/
private List<ModContainer> mods;
/**
* A named list of mods
*/
private Dictionary<String, ModContainer> namedMods;
/**
* A reverse dependency graph for mods
*/
private ListMultimap<String, String> reverseDependencies;
/**
* The canonical configuration directory
*/
private File canonicalConfigDir;
private File canonicalModsDir;
private LoadController modController;
private MinecraftDummyContainer minecraft;
private MCPDummyContainer mcp;

private static File minecraftDir;
private static List<String> injectedContainers;
private ImmutableMap<String, String> fmlBrandingProperties;
private File forcedModFile;
private ModDiscoverer discoverer;
private ProgressBar progressBar;

public static Loader GetInstance()
{
if (instance == null)
{
instance = new Loader();
}

return instance;
}

public static void injectData(Object[] data)
{
major = (String)data[0];
minor = (String)data[1];
rev = (String)data[2];
build = (String)data[3];
mccversion = (String)data[4];
mcpversion = (String)data[5];
minecraftDir = (string)data[6];
injectedContainers = (List<String>)data[7];
}

private Loader()
{
modClassLoader = new ModClassLoader(getClass().getClassLoader());
if (mccversion != null && !mccversion.equals(MC_VERSION))
{
throw new LoaderException(String.Format("This version of FML is built for Minecraft %s, we have detected Minecraft %s in your minecraft jar file", mccversion, MC_VERSION));
}

minecraft = new MinecraftDummyContainer(MC_VERSION);
InputStream mcpModInputStream = getClass().getResourceAsStream("/mcpmod.info");
try
{
mcp = new MCPDummyContainer(MetadataCollection.from(mcpModInputStream, "MCP").getMetadataForId("mcp", null));
}
finally
{
IOUtils.closeQuietly(mcpModInputStream);
}
}
}
}
Loading