Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Colony Survival Construction Mod by Scarabol

Original Creator: Scarabol Existence Github: https://github.com/Scarabol/ColonyConstructionMod


## Blueprints

Expand Down
130 changes: 51 additions & 79 deletions src/Architects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,71 @@

namespace ScarabolMods
{
[ModLoader.ModManager]
public static class ArchitectsModEntries
{
public static string JOB_NAME = "scarabol.architect";
public static string JOB_ITEM_KEY = ConstructionModEntries.MOD_PREFIX + "architects.table";

[ModLoader.ModCallback (ModLoader.EModCallbackType.AfterItemTypesDefined, "scarabol.architects.registerjobs")]
[ModLoader.ModCallbackProvidesFor ("pipliz.apiprovider.jobs.resolvetypes")]
public static void RegisterJobs ()
[ModLoader.ModManager]
public static class ArchitectsModEntries
{
BlockJobManagerTracker.Register<ArchitectJob> (JOB_ITEM_KEY);
}
public static string JOB_NAME = "scarabol.architect";
public static string JOB_ITEM_KEY = ConstructionModEntries.MOD_PREFIX + "architects.table";

[ModLoader.ModCallback (ModLoader.EModCallbackType.AfterSelectedWorld, "scarabol.architects.registertexturemappings")]
[ModLoader.ModCallbackProvidesFor ("pipliz.server.registertexturemappingtextures")]
public static void AfterSelectedWorld ()
{
var textureMapping = new ItemTypesServer.TextureMapping (new JSONNode ());
textureMapping.AlbedoPath = MultiPath.Combine (ConstructionModEntries.AssetsDirectory, "textures", "albedo", "architectTop.png");
ItemTypesServer.SetTextureMapping (ConstructionModEntries.MOD_PREFIX + "architecttop", textureMapping);
}
[ModLoader.ModCallback(ModLoader.EModCallbackType.AfterItemTypesDefined, "scarabol.architects.registerjobs")]
[ModLoader.ModCallbackProvidesFor("pipliz.apiprovider.jobs.resolvetypes")]
public static void RegisterJobs()
{
BlockJobManagerTracker.Register<ArchitectJob>(JOB_ITEM_KEY);
//add job interface to the job
RecipeStorage.AddBlockToRecipeMapping(JOB_ITEM_KEY, JOB_NAME);
}

[ModLoader.ModCallback (ModLoader.EModCallbackType.AfterAddingBaseTypes, "scarabol.architects.addrawtypes")]
[ModLoader.ModCallbackDependsOn ("scarabol.blueprints.addrawtypes")]
public static void AfterAddingBaseTypes (Dictionary<string, ItemTypesServer.ItemTypeRaw> itemTypes)
{
itemTypes.Add (JOB_ITEM_KEY, new ItemTypesServer.ItemTypeRaw (JOB_ITEM_KEY, new JSONNode ()
.SetAs ("onPlaceAudio", "woodPlace")
.SetAs ("onRemoveAudio", "woodDeleteLight")
.SetAs ("icon", MultiPath.Combine (ConstructionModEntries.AssetsDirectory, "icons", "architect.png"))
.SetAs ("sideall", "planks")
.SetAs ("sidey+", ConstructionModEntries.MOD_PREFIX + "architecttop")
.SetAs ("npcLimit", 0)
));
[ModLoader.ModCallback(ModLoader.EModCallbackType.AfterItemTypesDefined, "scarabol.architects.loadrecipes")]
[ModLoader.ModCallbackDependsOn("pipliz.server.loadresearchables")]
public static void LoadRecipes()
{
//Add blueprints as recipes
foreach(string blueprintTypename in ManagerBlueprints.Blueprints.Keys)
{
RecipeStorage.AddDefaultLimitTypeRecipe(JOB_NAME, new ArchitectRecipe(blueprintTypename));
}
}
}

[ModLoader.ModCallback (ModLoader.EModCallbackType.AfterItemTypesDefined, "scarabol.architects.loadrecipes")]
[ModLoader.ModCallbackDependsOn ("pipliz.server.loadresearchables")]
public static void LoadRecipes ()
public class ArchitectJob : CraftingJobBase, IBlockJobBase, INPCTypeDefiner
{
RecipePlayer.AddDefaultRecipe (new Recipe (JOB_ITEM_KEY + ".recipe", new InventoryItem (BuiltinBlocks.Planks, 1), new InventoryItem (JOB_ITEM_KEY, 1), 0));
}
}
public override string NPCTypeKey { get { return ArchitectsModEntries.JOB_NAME; } }

public class ArchitectJob : CraftingJobBase, IBlockJobBase, INPCTypeDefiner
{
public override string NPCTypeKey { get { return ArchitectsModEntries.JOB_NAME; } }
public override float CraftingCooldown { get { return 10.0f; } }

public override float CraftingCooldown { get { return 10.0f; } }
public override int MaxRecipeCraftsPerHaul { get { return 1; } }

public override int MaxRecipeCraftsPerHaul { get { return 1; } }
//Decrease the amount of blueprints to build each time that one is crafted
protected override void OnRecipeCrafted()
{
var recipeStorage = RecipeStorage.GetPlayerStorage(owner);
recipeStorage.SetLimit(selectedRecipe.Name, recipeStorage.GetRecipeSetting(selectedRecipe.Name).Limit - 1);
}

public override List<string> GetCraftingLimitsTriggers ()
{
return new List<string> { ArchitectsModEntries.JOB_ITEM_KEY };
}
NPCTypeStandardSettings INPCTypeDefiner.GetNPCTypeDefinition()
{
return new NPCTypeStandardSettings
{
keyName = NPCTypeKey,
printName = "Architect",
maskColor1 = new UnityEngine.Color32(220, 220, 220, 255),
type = NPCTypeID.GetNextID()
};
}

protected override void OnRecipeCrafted ()
{
var recipeStorage = RecipeStorage.GetPlayerStorage (owner);
recipeStorage.SetLimit (selectedRecipe.Name, recipeStorage.GetRecipeSetting (selectedRecipe.Name).Limit - 1);
}

NPCTypeStandardSettings INPCTypeDefiner.GetNPCTypeDefinition ()
public class ArchitectRecipe : Recipe
{
return new NPCTypeStandardSettings {
keyName = NPCTypeKey,
printName = "Architect",
maskColor1 = new UnityEngine.Color32 (220, 220, 220, 255),
type = NPCTypeID.GetNextID ()
};
}

public override IList<Recipe> GetCraftingLimitsRecipes ()
{
List<Recipe> result = new List<Recipe> ();
foreach (string blueprintTypename in ManagerBlueprints.Blueprints.Keys) {
result.Add (new ArchitectRecipe (blueprintTypename));
}
return result;
}
}
public ArchitectRecipe(string blueprintTypename)
: base(blueprintTypename + ".recipe", new InventoryItem(BuiltinBlocks.Planks, 1), new InventoryItem(blueprintTypename, 1), 0)
{
}

public class ArchitectRecipe : Recipe
{
public ArchitectRecipe (string blueprintTypename)
: base (blueprintTypename + ".recipe", new InventoryItem (BuiltinBlocks.Planks, 1), new InventoryItem (blueprintTypename, 1), 0)
{
}

public override int ShouldBeMade (Stockpile stockpile, RecipeStorage.PlayerRecipeStorage playerStorage = null)
{
return RecipeStorage.GetPlayerStorage (stockpile.Owner).GetRecipeSetting (this.Name).Limit;
public override int ShouldBeMade(Stockpile stockpile, RecipeStorage.PlayerRecipeStorage playerStorage = null)
{
return RecipeStorage.GetPlayerStorage(stockpile.Owner).GetRecipeSetting(Name).Limit;
}
}
}
}
185 changes: 91 additions & 94 deletions src/Blueprints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,104 @@

namespace ScarabolMods
{
[ModLoader.ModManager]
public static class BlueprintsModEntries
{
[ModLoader.ModCallback (ModLoader.EModCallbackType.AfterSelectedWorld, "scarabol.blueprints.registertexturemappings")]
[ModLoader.ModCallbackProvidesFor ("pipliz.server.registertexturemappingtextures")]
public static void AfterSelectedWorld ()
[ModLoader.ModManager]
public static class BlueprintsModEntries
{
var textureMapping = new ItemTypesServer.TextureMapping (new JSONNode ());
textureMapping.AlbedoPath = MultiPath.Combine (ConstructionModEntries.AssetsDirectory, "textures", "albedo", "blueprintsTop.png");
ItemTypesServer.SetTextureMapping (ConstructionModEntries.MOD_PREFIX + "blueprinttop", textureMapping);
[ModLoader.ModCallback(ModLoader.EModCallbackType.AfterAddingBaseTypes, "scarabol.blueprints.addrawtypes")]
public static void AfterAddingBaseTypes(Dictionary<string, ItemTypesServer.ItemTypeRaw> itemTypes)
{
string iconFilepath = MultiPath.Combine(ConstructionModEntries.AssetsDirectory, "icons", "blueprint.png");
foreach(string blueprintTypename in ManagerBlueprints.Blueprints.Keys)
{
itemTypes.Add(blueprintTypename, new ItemTypesServer.ItemTypeRaw(blueprintTypename,
new JSONNode()
.SetAs("onPlaceAudio", "woodPlace")
.SetAs("onRemoveAudio", "woodDeleteLight")
.SetAs("icon", iconFilepath)
.SetAs("sideall", "planks")
.SetAs("sidey+", "mods.scarabol.construction.blueprintTop")
.SetAs("npcLimit", "0")
.SetAs("isRotatable", "true")
.SetAs("rotatablex+", blueprintTypename + "x+")
.SetAs("rotatablex-", blueprintTypename + "x-")
.SetAs("rotatablez+", blueprintTypename + "z+")
.SetAs("rotatablez-", blueprintTypename + "z-")
));
itemTypes.Add(blueprintTypename + "x+", new ItemTypesServer.ItemTypeRaw(blueprintTypename + "x+",
new JSONNode()
.SetAs("parentType", blueprintTypename)
));
itemTypes.Add(blueprintTypename + "x-", new ItemTypesServer.ItemTypeRaw(blueprintTypename + "x-",
new JSONNode()
.SetAs("parentType", blueprintTypename)
));
itemTypes.Add(blueprintTypename + "z+", new ItemTypesServer.ItemTypeRaw(blueprintTypename + "z+",
new JSONNode()
.SetAs("parentType", blueprintTypename)
));
itemTypes.Add(blueprintTypename + "z-", new ItemTypesServer.ItemTypeRaw(blueprintTypename + "z-",
new JSONNode()
.SetAs("parentType", blueprintTypename)
));
}
}
}

[ModLoader.ModCallback (ModLoader.EModCallbackType.AfterAddingBaseTypes, "scarabol.blueprints.addrawtypes")]
public static void AfterAddingBaseTypes (Dictionary<string, ItemTypesServer.ItemTypeRaw> itemTypes)
public class BlueprintTodoBlock
{
string iconFilepath = MultiPath.Combine (ConstructionModEntries.AssetsDirectory, "icons", "blueprint.png");
foreach (string blueprintTypename in ManagerBlueprints.Blueprints.Keys) {
itemTypes.Add (blueprintTypename, new ItemTypesServer.ItemTypeRaw (blueprintTypename,
new JSONNode ()
.SetAs ("onPlaceAudio", "woodPlace")
.SetAs ("onRemoveAudio", "woodDeleteLight")
.SetAs ("icon", iconFilepath)
.SetAs ("sideall", "planks")
.SetAs ("sidey+", ConstructionModEntries.MOD_PREFIX + "blueprinttop")
.SetAs ("npcLimit", "0")
.SetAs ("isRotatable", "true")
.SetAs ("rotatablex+", blueprintTypename + "x+")
.SetAs ("rotatablex-", blueprintTypename + "x-")
.SetAs ("rotatablez+", blueprintTypename + "z+")
.SetAs ("rotatablez-", blueprintTypename + "z-")
));
itemTypes.Add (blueprintTypename + "x+", new ItemTypesServer.ItemTypeRaw (blueprintTypename + "x+",
new JSONNode ()
.SetAs ("parentType", blueprintTypename)
));
itemTypes.Add (blueprintTypename + "x-", new ItemTypesServer.ItemTypeRaw (blueprintTypename + "x-",
new JSONNode ()
.SetAs ("parentType", blueprintTypename)
));
itemTypes.Add (blueprintTypename + "z+", new ItemTypesServer.ItemTypeRaw (blueprintTypename + "z+",
new JSONNode ()
.SetAs ("parentType", blueprintTypename)
));
itemTypes.Add (blueprintTypename + "z-", new ItemTypesServer.ItemTypeRaw (blueprintTypename + "z-",
new JSONNode ()
.SetAs ("parentType", blueprintTypename)
));
}
}
}
public int OffsetX;
public int OffsetY;
public int OffsetZ;
public string Typename;

public class BlueprintTodoBlock
{
public int OffsetX;
public int OffsetY;
public int OffsetZ;
public string Typename;
public BlueprintTodoBlock(int offsetx, int offsety, int offsetz, string typename)
{
OffsetX = offsetx;
OffsetY = offsety;
OffsetZ = offsetz;
Typename = typename;
}

public BlueprintTodoBlock (int offsetx, int offsety, int offsetz, string typename)
{
OffsetX = offsetx;
OffsetY = offsety;
OffsetZ = offsetz;
Typename = typename;
}
public BlueprintTodoBlock(JSONNode node)
{
OffsetX = node.getAsOrElse<int>("x", "offsetx");
OffsetY = node.getAsOrElse<int>("y", "offsety");
OffsetZ = node.getAsOrElse<int>("z", "offsetz");
Typename = node.getAsOrElse<string>("t", "typename");
}

public BlueprintTodoBlock (JSONNode node)
{
OffsetX = node.getAsOrElse<int> ("x", "offsetx");
OffsetY = node.getAsOrElse<int> ("y", "offsety");
OffsetZ = node.getAsOrElse<int> ("z", "offsetz");
Typename = node.getAsOrElse<string> ("t", "typename");
}
public JSONNode GetJSON()
{
return new JSONNode()
.SetAs("x", OffsetX)
.SetAs("y", OffsetY)
.SetAs("z", OffsetZ)
.SetAs("t", Typename);
}

public JSONNode GetJSON ()
{
return new JSONNode ()
.SetAs ("x", OffsetX)
.SetAs ("y", OffsetY)
.SetAs ("z", OffsetZ)
.SetAs ("t", Typename);
}

public Vector3Int GetWorldPosition (string typeBasename, Vector3Int position, ushort bluetype)
{
ushort hxm = ItemTypes.IndexLookup.GetIndex (typeBasename + "x-");
ushort hzp = ItemTypes.IndexLookup.GetIndex (typeBasename + "z+");
ushort hzm = ItemTypes.IndexLookup.GetIndex (typeBasename + "z-");
int realx = OffsetZ + 1;
int realz = -OffsetX;
if (bluetype == hxm) {
realx = -OffsetZ - 1;
realz = OffsetX;
} else if (bluetype == hzp) {
realx = OffsetX;
realz = OffsetZ + 1;
} else if (bluetype == hzm) {
realx = -OffsetX;
realz = -OffsetZ - 1;
}
return position.Add (realx, OffsetY, realz);
public Vector3Int GetWorldPosition(string typeBasename, Vector3Int position, ushort bluetype)
{
ushort hxm = ItemTypes.IndexLookup.GetIndex(typeBasename + "x-");
ushort hzp = ItemTypes.IndexLookup.GetIndex(typeBasename + "z+");
ushort hzm = ItemTypes.IndexLookup.GetIndex(typeBasename + "z-");
int realx = OffsetZ + 1;
int realz = -OffsetX;
if(bluetype == hxm)
{
realx = -OffsetZ - 1;
realz = OffsetX;
}
else if(bluetype == hzp)
{
realx = OffsetX;
realz = OffsetZ + 1;
}
else if(bluetype == hzm)
{
realx = -OffsetX;
realz = -OffsetZ - 1;
}
return position.Add(realx, OffsetY, realz);
}
}
}
}
Loading