This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
forked from Aetherial-Labs/ACulinaryArtillery
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathACulinaryArtillery.cs
133 lines (112 loc) · 5.69 KB
/
ACulinaryArtillery.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using ACulinaryArtillery.Util;
using HarmonyLib;
using System;
using System.Reflection;
using Vintagestory.API.Common;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.GameContent;
namespace ACulinaryArtillery
{
public class ACulinaryArtillery : ModSystem
{
private static Harmony harmony;
public static ILogger logger;
public override void Start(ICoreAPI api)
{
//base.Start(api);
api.RegisterBlockClass("BlockMeatHooks", typeof(BlockMeatHooks));
api.RegisterBlockEntityClass("MeatHooks", typeof(BlockEntityMeatHooks));
api.RegisterBlockClass("BlockBottleRack", typeof(BlockBottleRack));
api.RegisterBlockEntityClass("BottleRack", typeof(BlockEntityBottleRack));
api.RegisterBlockClass("BlockMixingBowl", typeof(BlockMixingBowl));
api.RegisterBlockEntityClass("MixingBowl", typeof(BlockEntityMixingBowl));
api.RegisterBlockClass("BlockBottle", typeof(BlockBottle));
api.RegisterBlockEntityClass("Bottle", typeof(BlockEntityBottle));
api.RegisterBlockClass("BlockSpile", typeof(BlockSpile));
api.RegisterBlockEntityClass("Spile", typeof(BlockEntitySpile));
api.RegisterBlockClass("BlockSaucepan", typeof(BlockSaucepan));
api.RegisterBlockEntityClass("Saucepan", typeof(BlockEntitySaucepan));
api.RegisterBlockClass("BlockExpandedClayOven", typeof(BlockExpandedClayOven));
api.RegisterBlockEntityClass("ExpandedOven", typeof(BlockEntityExpandedOven));
api.RegisterItemClass("SuperFood", typeof(ItemSuperFood));
api.RegisterItemClass("EggCrack", typeof(ItemEggCrack));
api.RegisterItemClass("ExpandedRawFood", typeof(ItemExpandedRawFood));
api.RegisterItemClass("ExpandedFood", typeof(ItemExpandedFood));
api.RegisterItemClass("TransFix", typeof(ItemTransFix));
api.RegisterItemClass("TransLiquid", typeof(ItemTransLiquid));
api.RegisterItemClass("ExpandedLiquid", typeof(ItemExpandedLiquid));
api.RegisterItemClass("ExpandedDough", typeof(ItemExpandedDough));
//Check for Existing Config file, create one if none exists
try
{
var Config = api.LoadModConfig<ACulinaryArtilleryConfig>("aculinaryartillery.json");
if (Config != null)
{
api.Logger.Notification("Mod Config successfully loaded.");
ACulinaryArtilleryConfig.Current = Config;
}
else
{
api.Logger.Notification("No Mod Config specified. Falling back to default settings");
ACulinaryArtilleryConfig.Current = ACulinaryArtilleryConfig.GetDefault();
}
}
catch
{
ACulinaryArtilleryConfig.Current = ACulinaryArtilleryConfig.GetDefault();
api.Logger.Error("Failed to load custom mod configuration. Falling back to default settings!");
}
finally
{
api.StoreModConfig(ACulinaryArtilleryConfig.Current, "aculinaryartillery.json");
}
harmony ??= new Harmony("com.jakecool19.efrecipes.cookingoverhaul");
logger = api.Logger;
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
public override void Dispose()
{
harmony.UnpatchAll(harmony.Id);
//base.Dispose();
}
public override void StartServerSide(ICoreServerAPI api)
{
//base.StartServerSide(api);
api.RegisterCommand("efremap", "Remaps items in Expanded Foods", "",
//This can't possibly work XD
(IServerPlayer player, int groupId, CmdArgs args) =>
{
api.World.BlockAccessor.WalkBlocks(player.Entity.ServerPos.AsBlockPos.AddCopy(-10), player.Entity.ServerPos.AsBlockPos.AddCopy(10), (block, posX, posY, posZ) => {
BottleFix(new BlockPos(posX, posY, posZ), block, api.World);
});
}, Privilege.chat);
}
public void BottleFix(BlockPos pos, Block block, IWorldAccessor world)
{
BlockEntityContainer bc;
if (block.Code.Path.Contains("bottle") && !block.Code.Path.Contains("burned") && !block.Code.Path.Contains("raw"))
{
Block replacement = world.GetBlock(new AssetLocation(block.Code.Domain + ":bottle-" + block.FirstCodePart(1) + "-burned"));
if (replacement != null) world.BlockAccessor.SetBlock(replacement.BlockId, pos);
}
else if ((bc = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer) != null)
{
foreach (ItemSlot slot in bc.Inventory)
{
if (slot.Itemstack?.Block != null && slot.Itemstack.Block.Code.Path.Contains("bottle") && !slot.Itemstack.Block.Code.Path.Contains("burned") && !slot.Itemstack.Block.Code.Path.Contains("raw"))
{
Block replacement = world.GetBlock(new AssetLocation(slot.Itemstack.Block.Code.Domain + ":bottle-" + slot.Itemstack.Block.FirstCodePart(1) + "-burned"));
if (replacement != null)
{
slot.Itemstack = new ItemStack(replacement, slot.Itemstack.StackSize);
}
}
}
}
}
internal static void LogError(string message) {
logger.Error("(ACulinaryArtillery): {0}", message);
}
}
}