~williewillus/violet-moon

botania: Clean up how items are tagged as "in-world recipe spawned" v1 APPLIED

Artemis System: 1
 Clean up how items are tagged as "in-world recipe spawned"

 6 files changed, 41 insertions(+), 63 deletions(-)
#1086298 linux.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~williewillus/violet-moon/patches/46303/mbox | git am -3
Learn more about email & git

[PATCH botania] Clean up how items are tagged as "in-world recipe spawned" Export this patch

This leads to some changes:
- Runic altar and mana pools no longer store a cooldown, just a boolean. Meaning items will never re-enter the pool/altar before being picked up if they happen to land on top of it again.
- Hopperhocks' 5 tick pickup delay now applies to items spawned from alfheim portals and petal apothecaries, not just altars and mana pools.
---
 .../AlfheimPortalBlockEntity.java             |  5 +-
 .../PetalApothecaryBlockEntity.java           |  2 -
 .../block_entity/RunicAltarBlockEntity.java   |  6 +-
 .../mana/ManaPoolBlockEntity.java             |  4 +-
 .../functional/HopperhockBlockEntity.java     | 10 +--
 .../internal_caps/ItemFlagsComponent.java     | 77 ++++++++-----------
 6 files changed, 41 insertions(+), 63 deletions(-)

diff --git a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/AlfheimPortalBlockEntity.java b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/AlfheimPortalBlockEntity.java
index 699348de2..74342c594 100644
--- a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/AlfheimPortalBlockEntity.java
+++ b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/AlfheimPortalBlockEntity.java
@@ -112,7 +112,6 @@ public TriPredicate<BlockGetter, BlockPos, BlockState> getStatePredicate() {
	private static final String TAG_TICKS_SINCE_LAST_ITEM = "ticksSinceLastItem";
	private static final String TAG_STACK_COUNT = "stackCount";
	private static final String TAG_STACK = "portalStack";
	public static final String TAG_PORTAL_FLAG = "_elvenPortal";

	private final List<ItemStack> stacksIn = new ArrayList<>();
	private final List<BlockPos> cachedPylonPositions = new ArrayList<>();
@@ -156,7 +155,7 @@ public static void commonTick(Level level, BlockPos worldPosition, BlockState bl
					}

					ItemStack stack = item.getItem();
					if (XplatAbstractions.INSTANCE.itemFlagsComponent(item).alfPortalSpawned) {
					if (XplatAbstractions.INSTANCE.itemFlagsComponent(item).elvenPortalSpawned) {
						continue;
					}

@@ -300,7 +299,7 @@ private void resolveRecipes() {

	private void spawnItem(ItemStack stack) {
		ItemEntity item = new ItemEntity(level, worldPosition.getX() + 0.5, worldPosition.getY() + 1.5, worldPosition.getZ() + 0.5, stack);
		XplatAbstractions.INSTANCE.itemFlagsComponent(item).alfPortalSpawned = true;
		XplatAbstractions.INSTANCE.itemFlagsComponent(item).elvenPortalSpawned = true;
		level.addFreshEntity(item);
		ticksSinceLastItem = 0;
	}
diff --git a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/PetalApothecaryBlockEntity.java b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/PetalApothecaryBlockEntity.java
index 2d92fb9af..db3923722 100644
--- a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/PetalApothecaryBlockEntity.java
+++ b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/PetalApothecaryBlockEntity.java
@@ -56,8 +56,6 @@ public class PetalApothecaryBlockEntity extends SimpleInventoryBlockEntity imple
	private static final int SET_KEEP_TICKS_EVENT = 0;
	private static final int CRAFT_EFFECT_EVENT = 1;

	public static final String ITEM_TAG_APOTHECARY_SPAWNED = "ApothecarySpawned";

	private List<ItemStack> lastRecipe = null;
	private Ingredient lastReagent = Ingredient.EMPTY;
	private int recipeKeepTicks = 0;
diff --git a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/RunicAltarBlockEntity.java b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/RunicAltarBlockEntity.java
index 052a4b7b0..54a2368f6 100644
--- a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/RunicAltarBlockEntity.java
+++ b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/RunicAltarBlockEntity.java
@@ -155,7 +155,7 @@ public static void serverTick(Level level, BlockPos worldPosition, BlockState st
			List<ItemEntity> items = level.getEntitiesOfClass(ItemEntity.class, new AABB(worldPosition, worldPosition.offset(1, 1, 1)));
			for (ItemEntity item : items) {
				if (item.isAlive() && !item.getItem().isEmpty() && !item.getItem().is(BotaniaBlocks.livingrock.asItem())
						&& XplatAbstractions.INSTANCE.itemFlagsComponent(item).getRunicAltarCooldown() == 0) {
						&& !XplatAbstractions.INSTANCE.itemFlagsComponent(item).runicAltarSpawned) {
					ItemStack stack = item.getItem();
					if (self.addItem(null, stack, null)) {
						EntityHelper.syncItem(item);
@@ -265,7 +265,7 @@ public boolean onUsedByWand(@Nullable Player player, ItemStack wand, Direction s
				receiveMana(-mana);
				ItemStack output = recipe.assemble(getItemHandler(), getLevel().registryAccess());
				ItemEntity outputItem = new ItemEntity(level, worldPosition.getX() + 0.5, worldPosition.getY() + 1.5, worldPosition.getZ() + 0.5, output);
				XplatAbstractions.INSTANCE.itemFlagsComponent(outputItem).markAltarOutput();
				XplatAbstractions.INSTANCE.itemFlagsComponent(outputItem).runicAltarSpawned = true;
				level.addFreshEntity(outputItem);
				currentRecipe = null;
				level.blockEvent(getBlockPos(), BotaniaBlocks.runeAltar, CRAFT_EFFECT_EVENT, 0);
@@ -276,7 +276,7 @@ public boolean onUsedByWand(@Nullable Player player, ItemStack wand, Direction s
					if (!stack.isEmpty()) {
						if (stack.getItem() instanceof RuneItem && (player == null || !player.getAbilities().instabuild)) {
							ItemEntity outputRune = new ItemEntity(level, getBlockPos().getX() + 0.5, getBlockPos().getY() + 1.5, getBlockPos().getZ() + 0.5, stack.copy());
							XplatAbstractions.INSTANCE.itemFlagsComponent(outputRune).markAltarOutput();
							XplatAbstractions.INSTANCE.itemFlagsComponent(outputRune).runicAltarSpawned = true;
							level.addFreshEntity(outputRune);
						}

diff --git a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/mana/ManaPoolBlockEntity.java b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/mana/ManaPoolBlockEntity.java
index 79ad17994..2ecc15198 100644
--- a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/mana/ManaPoolBlockEntity.java
+++ b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/mana/ManaPoolBlockEntity.java
@@ -164,7 +164,7 @@ public boolean collideEntityItem(ItemEntity item) {
			dissolvable.onDissolveTick(this, item);
		}

		if (XplatAbstractions.INSTANCE.itemFlagsComponent(item).getManaInfusionCooldown() > 0) {
		if (XplatAbstractions.INSTANCE.itemFlagsComponent(item).manaInfusionSpawned) {
			return false;
		}

@@ -180,7 +180,7 @@ public boolean collideEntityItem(ItemEntity item) {
				item.setOnGround(false); //Force entity collision update to run every tick if crafting is in progress

				ItemEntity outputItem = new ItemEntity(level, worldPosition.getX() + 0.5, worldPosition.getY() + 1.5, worldPosition.getZ() + 0.5, output);
				XplatAbstractions.INSTANCE.itemFlagsComponent(outputItem).markNewlyInfused();
				XplatAbstractions.INSTANCE.itemFlagsComponent(outputItem).manaInfusionSpawned = true;
				level.addFreshEntity(outputItem);

				craftingEffect(true);
diff --git a/Xplat/src/main/java/vazkii/botania/common/block/flower/functional/HopperhockBlockEntity.java b/Xplat/src/main/java/vazkii/botania/common/block/flower/functional/HopperhockBlockEntity.java
index 56c50cc5f..3a09a7829 100644
--- a/Xplat/src/main/java/vazkii/botania/common/block/flower/functional/HopperhockBlockEntity.java
+++ b/Xplat/src/main/java/vazkii/botania/common/block/flower/functional/HopperhockBlockEntity.java
@@ -82,15 +82,9 @@ public void tickFlower() {
			final ItemFlagsComponent flags = XplatAbstractions.INSTANCE.itemFlagsComponent(item);

			// Flat 5 tick delay for newly infused items
			final int runicAltarCooldown = flags.getRunicAltarCooldown();
			if (runicAltarCooldown > 0) {
				return runicAltarCooldown <= ItemFlagsComponent.INITIAL_RUNIC_ALTAR_COOLDOWN - 5;
			if (flags.spawnedByInWorldRecipe()) {
				return flags.timeCounter >= 5;
			}
			var manaInfusionCooldown = flags.getManaInfusionCooldown();
			if (manaInfusionCooldown > 0) {
				return manaInfusionCooldown <= ItemFlagsComponent.INITIAL_MANA_INFUSION_COOLDOWN - 5;
			}

			return DelayHelper.canInteractWith(this, item);
		};
		List<ItemEntity> items = getLevel().getEntitiesOfClass(ItemEntity.class, new AABB(inPos.offset(-range, -range, -range), inPos.offset(range + 1, range + 1, range + 1)), shouldPickup);
diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java
index 7bc807e3a..3e7d5b5fd 100644
--- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java
+++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java
@@ -10,13 +10,12 @@

import net.minecraft.nbt.CompoundTag;

import vazkii.botania.common.block.block_entity.AlfheimPortalBlockEntity;
import vazkii.botania.common.block.block_entity.PetalApothecaryBlockEntity;

// Component for misc internal Botania flags
public class ItemFlagsComponent extends SerializableComponent {
	public boolean alfPortalSpawned = false;
	public boolean elvenPortalSpawned = false;
	public boolean apothecarySpawned = false;
	public boolean manaInfusionSpawned = false;
	public boolean runicAltarSpawned = false;
	/**
	 * Similar to the age field on the actual entity, but always increases by 1 every tick,
	 * no magic values like vanilla -32768, etc.
@@ -24,59 +23,47 @@ public class ItemFlagsComponent extends SerializableComponent {
	 * than zero in certain scenarios.
	 */
	public int timeCounter = 0;
	/**
	 * Set to {@link #INITIAL_MANA_INFUSION_COOLDOWN} when an item is output by the pool then cools off to 0.
	 * Used so certain mechanics don't interact with items immediately after they're produced.
	 */
	private int manaInfusionCooldown = 0;
	/**
	 * Similar to {@link #manaInfusionCooldown} but for the Runic Altar.
	 */
	private int runicAltarCooldown = 0;
	public static final int INITIAL_MANA_INFUSION_COOLDOWN = 25;
	public static final int INITIAL_RUNIC_ALTAR_COOLDOWN = 25;

	private static final String TAG_PORTAL_SPAWNED = "ElvenPortalSpawned";
	private static final String TAG_APOTHECARY_SPAWNED = "ApothecarySpawned";
	private static final String TAG_INFUSION_SPAWNED = "ManaInfusionSpawned";
	private static final String TAG_ALTAR_SPAWNED = "RunicAltarSpawned";

	private static final String TAG_TIME_COUNTER = "timeCounter";

	@Override
	public void readFromNbt(CompoundTag tag) {
		alfPortalSpawned = tag.getBoolean(AlfheimPortalBlockEntity.TAG_PORTAL_FLAG);
		apothecarySpawned = tag.getBoolean(PetalApothecaryBlockEntity.ITEM_TAG_APOTHECARY_SPAWNED);
		timeCounter = tag.getInt("timeCounter");
		manaInfusionCooldown = tag.getInt("manaInfusionCooldown");
		runicAltarCooldown = tag.getInt("runicAltarCooldown");
		elvenPortalSpawned = tag.getBoolean(TAG_PORTAL_SPAWNED);
		apothecarySpawned = tag.getBoolean(TAG_APOTHECARY_SPAWNED);
		manaInfusionSpawned = tag.getBoolean(TAG_INFUSION_SPAWNED);
		runicAltarSpawned = tag.getBoolean(TAG_ALTAR_SPAWNED);
		timeCounter = tag.getInt(TAG_TIME_COUNTER);
		// legacy tags
		if (tag.getBoolean("_elvenPortal")) {
			elvenPortalSpawned = true;
		}
		if (tag.getInt("manaInfusionCooldown") > 0) {
			manaInfusionSpawned = true;
		}
		if (tag.getInt("runicAltarCooldown") > 0) {
			runicAltarSpawned = true;
		}
	}

	@Override
	public void writeToNbt(CompoundTag tag) {
		tag.putBoolean(AlfheimPortalBlockEntity.TAG_PORTAL_FLAG, alfPortalSpawned);
		tag.putBoolean(PetalApothecaryBlockEntity.ITEM_TAG_APOTHECARY_SPAWNED, apothecarySpawned);
		tag.putInt("timeCounter", timeCounter);
		tag.putInt("manaInfusionCooldown", manaInfusionCooldown);
		tag.putInt("runicAltarCooldown", runicAltarCooldown);
		tag.putBoolean(TAG_PORTAL_SPAWNED, elvenPortalSpawned);
		tag.putBoolean(TAG_APOTHECARY_SPAWNED, apothecarySpawned);
		tag.putBoolean(TAG_INFUSION_SPAWNED, runicAltarSpawned);
		tag.putBoolean(TAG_ALTAR_SPAWNED, manaInfusionSpawned);
		tag.putInt(TAG_TIME_COUNTER, timeCounter);
	}

	public void tick() {
		timeCounter++;
		if (manaInfusionCooldown > 0) {
			manaInfusionCooldown--;
		}
		if (runicAltarCooldown > 0) {
			runicAltarCooldown--;
		}
	}

	public int getManaInfusionCooldown() {
		return manaInfusionCooldown;
	}

	public void markNewlyInfused() {
		manaInfusionCooldown = INITIAL_MANA_INFUSION_COOLDOWN;
	}

	public int getRunicAltarCooldown() {
		return runicAltarCooldown;
	}

	public void markAltarOutput() {
		runicAltarCooldown = INITIAL_RUNIC_ALTAR_COOLDOWN;
	public boolean spawnedByInWorldRecipe() {
		return elvenPortalSpawned || apothecarySpawned || runicAltarSpawned || manaInfusionSpawned;
	}
}
-- 
2.39.3 (Apple Git-145)
botania/patches/linux.yml: FAILED in 1m5s

[Clean up how items are tagged as "in-world recipe spawned"][0] from [Artemis System][1]

[0]: https://lists.sr.ht/~williewillus/violet-moon/patches/46303
[1]: mailto:theartemissystem@gmail.com

✗ #1086298 FAILED botania/patches/linux.yml https://builds.sr.ht/~williewillus/job/1086298
Artemis System <theartemissystem@gmail.com> writes: