118 lines
4.3 KiB
C#
118 lines
4.3 KiB
C#
using Audio;
|
|
|
|
namespace Harmony.BlockLightPatches
|
|
{
|
|
[HarmonyPatch(typeof(BlockLight))]
|
|
[HarmonyPatch("Init")]
|
|
public class InitPatch
|
|
{
|
|
public static void Postfix(BlockLight __instance)
|
|
{
|
|
bool isEditor = GameModeEditWorld.TypeName.Equals(GamePrefs.GetString(EnumGamePrefs.GameMode));
|
|
|
|
if (isEditor)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Array.Resize<BlockActivationCommand>(ref __instance.cmds, 4);
|
|
__instance.cmds[0] = new BlockActivationCommand("light", "electric_switch", true, false);
|
|
__instance.cmds[1] = new BlockActivationCommand("edit", "tool", true, false);
|
|
__instance.cmds[2] = new BlockActivationCommand("trigger", "wrench", true, false);
|
|
__instance.cmds[3] = new BlockActivationCommand("take", "hand", false, false);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockLight))]
|
|
[HarmonyPatch("GetBlockActivationCommands")]
|
|
public class GetBlockActivationCommandsPatch
|
|
{
|
|
public static void Postfix(BlockLight __instance, ref BlockActivationCommand[] __result, WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing
|
|
)
|
|
{
|
|
if (_world.IsEditor())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//__instance.cmds[0].enabled = true;
|
|
__instance.cmds[3].enabled = true;
|
|
__instance.cmds[4].enabled = true;
|
|
__result = __instance.cmds;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockLight))]
|
|
[HarmonyPatch("HasBlockActivationCommands")]
|
|
public class HasBlockActivationCommandsPatch
|
|
{
|
|
public static bool Prefix(BlockLight __instance, ref bool __result, WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing,
|
|
bool ___CanPickup
|
|
)
|
|
{
|
|
__result = true;
|
|
|
|
bool optionProtectTrader = RebirthVariables.customProtectTraderArea;
|
|
bool cantLoot = !optionProtectTrader && ((World)_world).IsWithinTraderArea(_blockPos);
|
|
|
|
if (cantLoot)
|
|
{
|
|
__result = false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockLight))]
|
|
[HarmonyPatch("OnBlockActivated")]
|
|
public class OnBlockActivatedPatch
|
|
{
|
|
public static void Postfix(BlockLight __instance, string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
if (_world.IsEditor())
|
|
{
|
|
return;
|
|
}
|
|
|
|
float takeDelay = RebirthVariables.takeDelay;
|
|
string replacementBlockName = "";
|
|
int numBlocks = 1;
|
|
bool isReplacementItem = false;
|
|
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
bool optionProtectTrader = RebirthVariables.customProtectTraderArea;
|
|
|
|
if (optionProtectTrader)
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (__instance.Properties.Contains("TakeDelay"))
|
|
{
|
|
__instance.Properties.ParseFloat("TakeDelay", ref takeDelay);
|
|
}
|
|
if (__instance.Properties.Contains("ReplacementBlockName"))
|
|
{
|
|
__instance.Properties.ParseString("ReplacementBlockName", ref replacementBlockName);
|
|
}
|
|
if (__instance.Properties.Contains("numBlocks"))
|
|
{
|
|
__instance.Properties.ParseInt("numBlocks", ref numBlocks);
|
|
}
|
|
if (__instance.Properties.Contains("isReplacementItem"))
|
|
{
|
|
__instance.Properties.ParseBool("isReplacementItem", ref isReplacementItem);
|
|
}
|
|
if (_commandName == "take")
|
|
{
|
|
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, takeDelay, null, replacementBlockName, numBlocks, isReplacementItem);
|
|
}
|
|
}
|
|
}
|
|
}
|