Skip to content

Commit bd9a6e0

Browse files
authored
Release v3.4.0
**NOTICE:** Potentially volatile update, which is why the minor version change, I'm using a new hook which may be a little more viable but I'm not entirely sure how often it's run on a populated server, and may conflict with other plugins using the hook (but really shouldn't.) - Fixed attachments being removed when moving to an empty slot. - Fixed more attachment shenanigans. - Water goes poof less often. (Reminder though that you can't stack things containing water. If you want this limit hardcoded so water won't stack with a config option let me know.) - Moved CanStackItem functionality into CanMoveItem, and removed CanStackItem functionality. Should increase compatibility and stability. However there may be new plugin conflicts or performance issues potentially, please report anything you notice.
2 parents f780862 + 77791a9 commit bd9a6e0

1 file changed

Lines changed: 31 additions & 58 deletions

File tree

StackSizeController.cs

Lines changed: 31 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Oxide.Plugins
99
{
10-
[Info("Stack Size Controller", "AnExiledGod", "3.3.1")]
10+
[Info("Stack Size Controller", "AnExiledGod", "3.4.0")]
1111
[Description("Allows configuration of most items max stack size.")]
1212
class StackSizeController : CovalencePlugin
1313
{
@@ -638,112 +638,83 @@ private void ListCategoryItemsCommand(IPlayer player, string command, string[] a
638638

639639
#region Hooks
640640

641-
// TODO: Investigate merging CanStackItem into CanMoveItem and potential performance issues
642641
object CanMoveItem(Item item, PlayerInventory playerLoot, uint targetContainer, int targetSlot, int amount)
643642
{
644643
if (_config.DisableDupeFixAndLeaveWeaponMagsAlone)
645644
{
646645
return null;
647646
}
648647

648+
Item targetItem = playerLoot.FindContainer(targetContainer).GetSlot(targetSlot);
649+
ItemContainer container = playerLoot.FindContainer(targetContainer);
650+
651+
if (targetItem.IsNull<Item>())
652+
{
653+
return null;
654+
}
655+
649656
if (item.contents?.itemList.Count > 0)
650657
{
651658
foreach (Item containedItem in item.contents.itemList)
652659
{
653-
item.parent.AddItem(containedItem.info, containedItem.amount, containedItem.skin);
654-
}
660+
if (containedItem.info.itemType == ItemContainer.ContentsType.Liquid) { continue; }
655661

656-
item.contents.Clear();
662+
container.AddItem(containedItem.info, containedItem.amount, containedItem.skin);
663+
containedItem.Remove();
664+
}
657665
}
658666

659-
Item targetItem = item.parent.GetSlot(targetSlot);
660-
661667
// Return contents
662-
if (targetItem?.contents?.itemList.Count > 0)
668+
if (targetItem.info.itemid == item.info.itemid && targetItem.contents?.itemList.Count > 0)
663669
{
664670
foreach (Item containedItem in targetItem.contents.itemList)
665671
{
666-
targetItem.parent.AddItem(containedItem.info, containedItem.amount, containedItem.skin);
667-
}
668-
669-
targetItem.contents.Clear();
670-
}
672+
if (containedItem.info.itemType == ItemContainer.ContentsType.Liquid) { continue; }
671673

672-
return null;
673-
}
674-
675-
private object CanStackItem(Item item, Item targetItem)
676-
{
677-
if (_config.DisableDupeFixAndLeaveWeaponMagsAlone ||
678-
(item.GetOwnerPlayer().IsUnityNull() && targetItem.GetOwnerPlayer().IsUnityNull())
679-
)
680-
{
681-
return null;
682-
}
683-
684-
// Duplicating all game checks since we're overriding them by returning true
685-
if (
686-
item == targetItem ||
687-
item.info.stackable <= 1 ||
688-
targetItem.info.stackable <= 1 ||
689-
item.info.itemid != targetItem.info.itemid ||
690-
!item.IsValid() ||
691-
item.IsBlueprint() && item.blueprintTarget != targetItem.blueprintTarget ||
692-
targetItem.hasCondition && (targetItem.condition < targetItem.info.condition.max - 5) ||
693-
(_config.PreventStackingDifferentSkins && item.skin != targetItem.skin)
694-
)
695-
{
696-
return false;
697-
}
698-
699-
if (item.info.amountType == ItemDefinition.AmountType.Genetics ||
700-
targetItem.info.amountType == ItemDefinition.AmountType.Genetics)
701-
{
702-
if ((item.instanceData?.dataInt ?? -1) != (targetItem.instanceData?.dataInt ?? -1))
703-
{
704-
return false;
674+
container.AddItem(containedItem.info, containedItem.amount, containedItem.skin);
675+
containedItem.Remove();
705676
}
706677
}
707678

708-
BaseProjectile.Magazine itemMag =
709-
targetItem.GetHeldEntity()?.GetComponent<BaseProjectile>()?.primaryMagazine;
710-
679+
BaseProjectile.Magazine itemMag =
680+
item.GetHeldEntity()?.GetComponent<BaseProjectile>()?.primaryMagazine;
681+
711682
// Return ammo
712683
if (itemMag != null)
713684
{
714685
if (itemMag.contents > 0)
715686
{
716-
item.parent.AddItem(itemMag.ammoType, itemMag.contents);
687+
container.AddItem(itemMag.ammoType, itemMag.contents);
717688

718689
itemMag.contents = 0;
719690
}
720691
}
721-
692+
722693
if (targetItem.GetHeldEntity() is FlameThrower)
723694
{
724-
FlameThrower flameThrower = targetItem.GetHeldEntity().GetComponent<FlameThrower>();
695+
FlameThrower flameThrower = item.GetHeldEntity().GetComponent<FlameThrower>();
725696

726697
if (flameThrower.ammo > 0)
727698
{
728-
item.parent.AddItem(flameThrower.fuelType, flameThrower.ammo);
699+
container.AddItem(flameThrower.fuelType, flameThrower.ammo);
729700

730701
flameThrower.ammo = 0;
731702
}
732703
}
733-
704+
734705
if (targetItem.GetHeldEntity() is Chainsaw)
735706
{
736-
Chainsaw chainsaw = targetItem.GetHeldEntity().GetComponent<Chainsaw>();
707+
Chainsaw chainsaw = item.GetHeldEntity().GetComponent<Chainsaw>();
737708

738709
if (chainsaw.ammo > 0)
739710
{
740-
item.parent.AddItem(chainsaw.fuelType, chainsaw.ammo);
711+
container.AddItem(chainsaw.fuelType, chainsaw.ammo);
741712

742713
chainsaw.ammo = 0;
743714
}
744715
}
745-
746-
return true;
716+
717+
return null;
747718
}
748719

749720
private Item OnItemSplit(Item item, int amount)
@@ -787,6 +758,8 @@ private Item OnItemSplit(Item item, int amount)
787758
{
788759
foreach (Item containedItem in item.contents.itemList)
789760
{
761+
if (containedItem.info.itemType == ItemContainer.ContentsType.Liquid) { continue; }
762+
790763
containedItem.Remove();
791764
}
792765
}

0 commit comments

Comments
 (0)