Files
zzz_REBIRTH__Utils/Harmony/Inactive/Harmony_XUiC_PowerSourceSlots.cs
2025-06-04 16:44:53 +09:30

85 lines
3.3 KiB
C#

using System.Linq;
namespace Harmony.XUiC_PowerSourceSlotsPatches
{
[HarmonyPatch(typeof(XUiC_PowerSourceSlots))]
[HarmonyPatch("SetSlots")]
public class SetSlotsPatch
{
public static void Postfix(XUiC_PowerSourceSlots __instance, ItemStack[] stacks)
{
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots __instance.tileEntity.isPlayerPlaced: " + __instance.tileEntity.isPlayerPlaced);
if (__instance.tileEntity.isPlayerPlaced)
{
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots IS PLAYER PLACED");
return;
}
int numCells = 0;
for (int i = 0; i < stacks.Length; i++)
{
if (!stacks[i].IsEmpty())
{
numCells++;
}
}
if (numCells > 0)
{
return;
}
GameRandom gameRandom = GameManager.Instance.World.GetGameRandom();
ItemValue itemSolarCell = ItemClass.GetItem("solarCell", false);
int random = gameRandom.RandomRange(1, 7);
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots Quality: " + random);
itemSolarCell.Quality = (ushort)random;
random = gameRandom.RandomRange(0, 6);
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots Position: " + random);
//__instance.tileEntity.ItemSlots[random].itemValue = itemSolarCell;
stacks[random].itemValue = itemSolarCell;
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots stacks[" + random + "].itemValue.IsEmpty(): " + stacks[random].itemValue.IsEmpty());
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots stacks.Length: " + stacks.Length);
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots __instance.tileEntity.ItemSlots.Count: " + __instance.tileEntity.ItemSlots.Count());
/*Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots __instance.tileEntity.activateDirty: " + __instance.tileEntity.activateDirty);
for (int i = 0; i < stacks.Length; i++)
{
Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots __instance.tileEntity.ItemSlots[" + i + "].IsEmpty(): " + __instance.tileEntity.ItemSlots[i].IsEmpty());
if (!__instance.tileEntity.ItemSlots[i].IsEmpty())
{
Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots __instance.tileEntity.ItemSlots[" + i + "].itemValue.Quality: " + __instance.tileEntity.ItemSlots[i].itemValue.Quality);
}
else
{
Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots __instance.tileEntity.ItemSlots[" + i + "].itemValue.Quality: IS EMPTY");
}
}*/
for (int i = 0; i < stacks.Length; i++)
{
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots stacks[" + i + "].itemValue.IsEmpty(): " + stacks[i].itemValue.IsEmpty());
if (!stacks[i].itemValue.IsEmpty())
{
//Log.Out("XUiC_PowerSourceSlotsPatches-SetSlots stacks[" + i + "].itemValue.Quality: " + stacks[i].itemValue.Quality);
}
}
__instance.items = stacks;
__instance.SetStacks(stacks);
}
}
}