butcherProducts prevents butchers from hauling meat to stockpile

Started by Nightinggale, October 24, 2017, 09:06:04 AM

Previous topic - Next topic

Nightinggale

When a butcher butches an animal, he/she will haul meat to the freezer and leave leather behind. However if xml contains anything in butcherProducts, the butcher will haul an item from butcherProducts and leave meat to rot. It's quite rare in vanilla, but it affects every single mod, which touches butcherProducts.

The problem appears to be with the method ButcherProducts. It's called in Verse.Corpse and it seems that the butcher will haul the first thing, which is returned with yield return. It returns the output from ButcherProducts in Verse.Pawn. Here it calls ButcherProducts in Verse.Thing, which in turn returns the contents of butcherProducts in xml. After that Verse.Pawn will move on to generating meat and return that.

This means a fix would be to make sure meat will be returned first and the simplest solution I can see is to go into Verse.Pawn and flip the first two pieces of code to generate yield returns, which would be:
foreach (Thing t in base.ButcherProducts(butcher, efficiency))
{
yield return t;
}

if (this.RaceProps.meatDef != null)
{
int meatCount = GenMath.RoundRandom(this.GetStatValue(StatDefOf.MeatAmount, true) * efficiency);
if (meatCount > 0)
{
Thing meat = ThingMaker.MakeThing(this.RaceProps.meatDef, null);
meat.stackCount = meatCount;
yield return meat;
}
}

I haven't directly tested this through modding and doing so would end up with mod incompatibility issues. However working on the bone mod, I removed bones from butcherProducts(xml), attached a butcherProducts(Verse.Pawn) Postfix function using Harmony and then used that one to add bones to the end of the list. Sure enough the butchers went from hauling bones to hauling meat and leaving bones on the floor.

It would be best to always haul the item, which can rot. This means if meat comes first, then butcherProducts(xml) and then the rest of the stuff because this will allow xml modders to pick what is hauled for corpses without meat.
ModCheck - boost your patch loading times and include patchmods in your main mod.

ison

Okay, I've changed the order so the meat will always go first and be hauled. Though ideally everything should always be hauled I think. Though it's not that important for now, thanks for reporting.