127 lines
4.8 KiB
C#
127 lines
4.8 KiB
C#
using Audio;
|
|
|
|
namespace Harmony.BlockPoweredLightPatches
|
|
{
|
|
[HarmonyPatch(typeof(BlockPoweredLight))]
|
|
[HarmonyPatch("Init")]
|
|
public class InitPatch
|
|
{
|
|
public static void Postfix(BlockPoweredLight __instance, ref BlockActivationCommand[] ___cmds)
|
|
{
|
|
bool isEditor = GameModeEditWorld.TypeName.Equals(GamePrefs.GetString(EnumGamePrefs.GameMode));
|
|
|
|
if (isEditor)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Array.Resize<BlockActivationCommand>(ref ___cmds, 2);
|
|
___cmds[0] = new BlockActivationCommand("light", "electric_switch", true, false);
|
|
___cmds[1] = new BlockActivationCommand("take", "hand", true, false);
|
|
//___cmds[2] = new BlockActivationCommand("edit", "tool", true, false);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockPoweredLight))]
|
|
[HarmonyPatch("HasBlockActivationCommands")]
|
|
public class HasBlockActivationCommandsPatch
|
|
{
|
|
public static bool Prefix(BlockPoweredLight __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(BlockPoweredLight))]
|
|
[HarmonyPatch("GetBlockActivationCommands")]
|
|
public class GetBlockActivationCommandsPatch
|
|
{
|
|
public static void Postfix(BlockPoweredLight __instance, ref BlockActivationCommand[] __result, WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, global::EntityAlive _entityFocusing,
|
|
BlockActivationCommand[] ___cmds
|
|
)
|
|
{
|
|
if (_world.IsEditor())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//___cmds[0].enabled = true;
|
|
___cmds[1].enabled = true;
|
|
//___cmds[2].enabled = true;
|
|
__result = ___cmds;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockPoweredLight))]
|
|
[HarmonyPatch("OnBlockActivated")]
|
|
[HarmonyPatch(new Type[] { typeof(string), typeof(WorldBase), typeof(int), typeof(Vector3i), typeof(BlockValue), typeof(EntityPlayerLocal) })]
|
|
public class OnBlockActivatedPatch
|
|
{
|
|
public static void Postfix(BlockPoweredLight __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);
|
|
}
|
|
/*else if (_commandName == "edit")
|
|
{
|
|
TileEntityLight tileEntity = (TileEntityLight)_world.GetTileEntity(_cIdx, _blockPos);
|
|
if (_world.IsEditor())
|
|
{
|
|
XUiC_LightEditor.Open(_player.PlayerUI, tileEntity, _blockPos, _world as World, _cIdx, __instance);
|
|
}
|
|
}*/
|
|
}
|
|
}
|
|
}
|