Upload from upload_mods.ps1

This commit is contained in:
Nathaniel Cosford
2025-06-04 16:44:53 +09:30
commit f1fbbe67bb
1722 changed files with 165268 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
using Rebirth.RemoteCrafting;
public class BlockDropBoxContainer : BlockSecureLootSigned
{
private float _distance;
private float _updateTime;
public override void Init()
{
base.Init();
_distance = RebirthVariables.broadcastDistance;
Properties.ParseFloat("Distance", ref _distance);
_updateTime = 100UL;
Properties.ParseFloat("UpdateTick", ref _updateTime);
}
public override ulong GetTickRate()
{
return (ulong)_updateTime;
}
public override void OnBlockAdded(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
base.OnBlockAdded(world, _chunk, _blockPos, _blockValue);
if (!world.IsRemote())
{
world.GetWBT().AddScheduledBlockUpdate(0, _blockPos, this.blockID, GetTickRate());
}
}
public override bool UpdateTick(WorldBase world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue,
bool _bRandomTick, ulong _ticksIfLoaded, GameRandom _rnd)
{
var tileLootContainer = (TileEntityLootContainer)world.GetTileEntity(_clrIdx, _blockPos);
if (tileLootContainer == null) return false;
if (!tileLootContainer.IsUserAccessing())
{
var primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
foreach (var itemStack in tileLootContainer.GetItems())
{
if (itemStack.IsEmpty()) continue;
// If we successfully added, clear the stack.
if (RemoteCraftingUtils.AddToNearbyContainer(primaryPlayer, itemStack, _distance))
itemStack.Clear();
}
tileLootContainer.bTouched = true;
tileLootContainer.SetModified();
}
world.GetWBT().AddScheduledBlockUpdate(0, _blockPos, this.blockID, GetTickRate());
return true;
}
}

View File

@@ -0,0 +1,49 @@
//copy of NetPackageAddFirePosition
public class NetPackageAddBroadcastPosition : NetPackage
{
private Vector3i position;
private int entityThatCausedIt;
public NetPackageAddBroadcastPosition Setup(Vector3i _position, int _entityThatCausedIt)
{
this.position = _position;
this.entityThatCausedIt = _entityThatCausedIt;
return this;
}
public override void read(PooledBinaryReader _br)
{
this.position = new Vector3i((float)_br.ReadInt32(), (float)_br.ReadInt32(), (float)_br.ReadInt32());
this.entityThatCausedIt = _br.ReadInt32();
}
public override void write(PooledBinaryWriter _bw)
{
base.write(_bw);
_bw.Write((int)this.position.x);
_bw.Write((int)this.position.y);
_bw.Write((int)this.position.z);
_bw.Write(this.entityThatCausedIt);
}
public override int GetLength()
{
return 20;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (_world == null)
{
return;
}
if (!_world.IsRemote())
{
return;
}
Broadcastmanager.Instance.add(position);
}
}

View File

@@ -0,0 +1,49 @@
//copy of NetPackageRemoveFirePosition
public class NetPackageRemoveBroadcastPosition : NetPackage
{
private Vector3i position;
private int entityThatCausedIt;
public NetPackageRemoveBroadcastPosition Setup(Vector3i _position, int _entityThatCausedIt)
{
this.position = _position;
this.entityThatCausedIt = _entityThatCausedIt;
return this;
}
public override void read(PooledBinaryReader _br)
{
this.position = new Vector3i((float)_br.ReadInt32(), (float)_br.ReadInt32(), (float)_br.ReadInt32());
this.entityThatCausedIt = _br.ReadInt32();
}
public override void write(PooledBinaryWriter _bw)
{
base.write(_bw);
_bw.Write((int)this.position.x);
_bw.Write((int)this.position.y);
_bw.Write((int)this.position.z);
_bw.Write(this.entityThatCausedIt);
}
public override int GetLength()
{
return 20;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (_world == null)
{
return;
}
if (!_world.IsRemote())
{
return;
}
Broadcastmanager.Instance.remove(position);
}
}

View File

@@ -0,0 +1,281 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using System.Linq;
namespace Rebirth.RemoteCrafting
{
[UsedImplicitly]
public class RemoteCraftingUtils
{
public static List<TileEntity> GetTileEntities(EntityAlive player)
{
var distance = 150f;
var tileEntities = RebirthUtilities.GetTileEntities(player, distance);
return tileEntities;
}
public static bool DisableSender(IEnumerable<string> value, TileEntity tileEntity)
{
if (tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage))
{
if (value.All(x => x.Trim() != storage.lootListName))
{
return true;
}
}
else
{
return false;
}
return false;
}
private static bool BindToWorkstation(string value, EntityAlive player, TileEntity tileEntity)
{
var result = false;
if (player is not EntityPlayerLocal playerLocal) return false;
if (!tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage)) return false;
// TODO: we want to refactor this to remove the complex LinQ.
// what could be easier than linq?
// bind storage to workstation
if (value.Split(';').Where(x =>
x.Split(':')[0].Split(',').Any(ws => ws.Trim() == playerLocal.PlayerUI.xui.currentWorkstation))
.Any(x => x.Split(':')[1].Split(',').Any(y => y == storage.lootListName))) result = true;
// bind storage to other workstations if allowed
if (value.Split(';').Any(x =>
x.Split(':')[0].Split(',').Any(ws => ws.Trim() == playerLocal.PlayerUI.xui.currentWorkstation)))
return result;
{
if (value.Split(';').Any(x => x.Split(':')[1].Split(',').Any(y => y == storage.lootListName)))
{
result = false;
}
else
{
result = true;
}
}
return result;
}
private static bool NotToWorkstation(string value, EntityAlive player, TileEntity tileEntity)
{
var result = false;
if (player is not EntityPlayerLocal playerLocal) return false;
if (!tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage)) return false;
foreach (var bind in value.Split(';'))
{
var workstation = bind.Split(':')[0].Split(',');
var disablebinding = bind.Split(':')[1].Split(',');
if ((workstation.Any(ws => ws.Trim() == playerLocal.PlayerUI.xui.currentWorkstation)) &&
(disablebinding.Any(x => x.Trim() == storage.lootListName))) result = true;
}
return result;
}
public static List<ItemStack> SearchNearbyContainers(EntityAlive player)
{
var items = new List<ItemStack>();
var tileEntities = GetTileEntities(player);
foreach (var tileEntity in tileEntities)
{
if (!tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage)) continue;
if (storage.IsUserAccessing()) continue;
items.AddRange(storage.items);
}
return items;
}
public static List<ItemStack> SearchNearbyContainers(EntityAlive player, ItemValue itemValue)
{
var item = new List<ItemStack>();
var items = new List<ItemStack>();
var tileEntities = GetTileEntities(player);
foreach (var tileEntity in tileEntities)
{
if (!tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage)) continue;
// If the container is open, don't use it.
if (storage.IsUserAccessing()) continue;
item.AddRange(storage.items);
}
foreach (var t in item)
{
if ((!t.itemValue.HasModSlots || !t.itemValue.HasMods()) &&
t.itemValue.type == itemValue.type)
{
items.Add(t);
}
}
return items;
}
public static List<ItemStack> SearchNearbyContainers(EntityAlive player, ItemValue itemValue, float distance)
{
var item = new List<ItemStack>();
var items = new List<ItemStack>();
var tileEntities = RebirthUtilities.GetTileEntities(player, distance);
foreach (var tileEntity in tileEntities)
{
if (tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage))
{
if (storage.IsUserAccessing()) continue;
item.AddRange(storage.items);
}
}
foreach (var t in item)
{
if ((!t.itemValue.HasModSlots || !t.itemValue.HasMods()) &&
t.itemValue.type == itemValue.type)
{
items.Add(t);
}
}
return items;
}
public static bool AddToNearbyContainer(EntityAlive player, ItemStack itemStack, float distance)
{
var tileEntities = RebirthUtilities.GetTileEntities(player, distance);
foreach (var tileEntity in tileEntities)
{
if (!tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage)) continue;
// If the container is open, don't include it.
if (storage.IsUserAccessing()) continue;
// Don't try to add to a drop box.
if (storage.blockValue.Block.Properties.Values.ContainsKey("DropBox")) continue;
// Can we quickly find a incomplete stack?
//if (lootTileEntity.TryStackItem(0, itemStack)) return true;
var result = storage.TryStackItem(0, itemStack);
if (result.allMoved) return true;
var matchingItem = false;
// Loop through the items and see if we have any matching items.
foreach (var item in storage.items)
{
// We match with something.
if (item.itemValue.type != itemStack.itemValue.type) continue;
matchingItem = true;
break;
}
// If we don't match, don't try to add.
if (!matchingItem) continue;
// We added a full stack! No need to keep processing.
if (storage.AddItem(itemStack)) return true;
}
return false;
}
public static void ConsumeItem(IEnumerable<ItemStack> itemStacks, EntityPlayerLocal localPlayer, int multiplier, IList<ItemStack> _removedItems, Bag bag, Inventory toolbelt)
{
var tileEntities = GetTileEntities(localPlayer);
var enumerable = itemStacks as ItemStack[] ?? itemStacks.ToArray();
for (var i = 0; i < enumerable.Count(); i++)
{
// Grab from the backpack first.
var num = enumerable[i].count * multiplier;
if (bag != null)
{
num -= bag.DecItem(enumerable[i].itemValue, num, true, _removedItems);
if (num > 0)
{
// Check tool belt
if (toolbelt != null)
{
num -= toolbelt.DecItem(enumerable[i].itemValue, num, true, _removedItems);
}
}
}
// We've met our goals for this.
if (num <= 0) continue;
// check storage boxes
foreach (var tileEntity in tileEntities)
{
if (num <= 0) break;
if (!tileEntity.TryGetSelfOrFeature(out ITileEntityLootable storage)) continue;
// If someone is using the tool account, skip it.
if (storage.IsUserAccessing()) continue;
// If there's no items in this container, skip.
if (!storage.HasItem(enumerable[i].itemValue)) continue;
for (var y = 0; y < storage.items.Length; y++)
{
var item = storage.items[y];
if (item.IsEmpty()) continue;
if (item.itemValue.ItemClass != enumerable[i].itemValue.ItemClass) continue;
// If we can completely satisfy the result, let's do that.
if (item.count >= num)
{
item.count -= num;
// Add the item to the removed items list so we can return it.
_removedItems.Add(new ItemStack(item.itemValue.Clone(), num));
num = 0;
}
else
{
// Otherwise, let's just count down until we meet the requirement.
while (num >= 0)
{
item.count--;
num--;
if (item.count <= 0)
{
_removedItems.Add(new ItemStack(item.itemValue.Clone(), num));
break;
}
}
}
//Update the slot on the container, and do the Setmodified(), so that the dedis can get updated.
if (item.count < 1)
{
// Add it to the removed list.
_removedItems.Add(item.Clone());
storage.UpdateSlot(y, ItemStack.Empty.Clone());
}
else
{
storage.UpdateSlot(y, item);
}
}
storage.SetModified();
}
}
}
}
}

View File

@@ -0,0 +1,89 @@
// Code from Laydor slightly modified
public class XUiC_BroadcastButton : XUiController
{
private XUiV_Button _button;
public override void Init()
{
base.Init();
_button = viewComponent as XUiV_Button;
OnPress += Grab_OnPress;
}
public override void Update(float dt)
{
base.Update(dt);
if (!IsDirty) return;
IsDirty = false;
SetupButton();
}
public override void OnOpen()
{
base.OnOpen();
IsDirty = true;
}
private void Grab_OnPress(XUiController sender, int mouseButton)
{
//Check if Broadcastmanager is running
if (!Broadcastmanager.HasInstance) return;
if (Broadcastmanager.Instance.Check(xui.lootContainer.ToWorldPos()))
{
//Unselect button
_button.Selected = true;
// Remove from Broadcastmanager dictionary
Broadcastmanager.Instance.remove(xui.lootContainer.ToWorldPos());
}
else
{
//Select button
_button.Selected = false;
// Add to Broadcastmanager dictionary
Broadcastmanager.Instance.add(xui.lootContainer.ToWorldPos());
}
}
private void SetupButton()
{
//Log.Out("XUiC_BroadcastButton-SetupButton START");
//Unselect button and disable it
_button.Enabled = false;
_button.Selected = false;
_button.IsVisible = false;
if (xui.lootContainer != null)
{
Entity entity = GameManager.Instance.World.GetEntity(xui.lootContainer.EntityId) as Entity;
//Log.Out("XUiC_BroadcastButton-SetupButton entity: " + entity.EntityClass.entityClassName);
//Log.Out("XUiC_BroadcastButton-SetupButton entity is EntityAliveV2: " + (entity is EntityAliveV2));
if (entity is EntityAliveV2)
{
return;
}
}
if (xui.lootContainer == null || !Broadcastmanager.HasInstance ||
xui.vehicle != null ||
(xui.lootContainer != null && GameManager.Instance.World.GetEntity(xui.lootContainer.EntityId) is EntityDrone))
{
//Log.Out("XUiC_BroadcastButton-SetupButton xui.lootContainer == null: " + (xui.lootContainer == null));
//Log.Out("XUiC_BroadcastButton-SetupButton !Broadcastmanager.HasInstance: " + (!Broadcastmanager.HasInstance));
//Log.Out("XUiC_BroadcastButton-SetupButton xui.vehicle != null: " + (xui.vehicle != null));
//Log.Out("XUiC_BroadcastButton-SetupButton EntityNPCRebirth: " + ((xui.lootContainer != null && GameManager.Instance.World.GetEntity(xui.lootContainer.entityId)) is EntityNPCRebirth));
//Log.Out("XUiC_BroadcastButton-SetupButton EntityDrone: " + ((xui.lootContainer != null && GameManager.Instance.World.GetEntity(xui.lootContainer.entityId) is EntityDrone)));
return;
}
//Enable button and set if button is selected
_button.IsVisible = true;
_button.Enabled = true;
_button.Selected = !Broadcastmanager.Instance.Check(xui.lootContainer.ToWorldPos());
//Log.Out("XUiC_BroadcastButton-SetupButton END");
}
}