~williewillus/violet-moon

botania: Make Crafty Crate pattern items usable in a dispenser v1 PROPOSED

Vincent Lee: 1
 Make Crafty Crate pattern items usable in a dispenser

 2 files changed, 47 insertions(+), 0 deletions(-)
#1076186 linux.yml success
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/45722/mbox | git am -3
Learn more about email & git

[PATCH botania] Make Crafty Crate pattern items usable in a dispenser Export this patch

Allows dynamic switching of the crafty crate mode

---
A separate problem that needs solving is adding a pattern item for
clearing the pattern (all blanks). Not hard but would involve me editing
textures which I don't want to do right now. So someone else can do it.

 Xplat/src/main/java/vazkii/botania/common/block/BotaniaBlocks.java                                |  10 ++
 Xplat/src/main/java/vazkii/botania/common/block/dispenser/CraftyCratePatternDispenseBehavior.java |  37 ++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/Xplat/src/main/java/vazkii/botania/common/block/BotaniaBlocks.java b/Xplat/src/main/java/vazkii/botania/common/block/BotaniaBlocks.java
--- a/Xplat/src/main/java/vazkii/botania/common/block/BotaniaBlocks.java
+++ b/Xplat/src/main/java/vazkii/botania/common/block/BotaniaBlocks.java
@@ -1630,6 +1630,16 @@
			}
		});

		Item[] patternItems = {
				BotaniaItems.craftPattern1_1, BotaniaItems.craftPattern1_2, BotaniaItems.craftPattern1_3,
				BotaniaItems.craftPattern2_1, BotaniaItems.craftPattern2_2, BotaniaItems.craftPattern2_3,
				BotaniaItems.craftPattern3_1, BotaniaItems.craftPattern3_2, BotaniaItems.craftPatternDonut,
		};
		behavior = new CraftyCratePatternDispenseBehavior();
		for (Item item : patternItems) {
			DispenserBlock.registerBehavior(item, behavior);
		}

		SeedBehaviors.init();
	}

diff --git a/Xplat/src/main/java/vazkii/botania/common/block/dispenser/CraftyCratePatternDispenseBehavior.java b/Xplat/src/main/java/vazkii/botania/common/block/dispenser/CraftyCratePatternDispenseBehavior.java
new file mode 100644
--- /dev/null
+++ b/Xplat/src/main/java/vazkii/botania/common/block/dispenser/CraftyCratePatternDispenseBehavior.java
@@ -0,0 +1,37 @@
package vazkii.botania.common.block.dispenser;

import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockSource;
import net.minecraft.core.Direction;
import net.minecraft.core.dispenser.OptionalDispenseItemBehavior;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.block.state.BlockState;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.api.state.BotaniaStateProperties;
import vazkii.botania.api.state.enums.CraftyCratePattern;
import vazkii.botania.common.block.BotaniaBlocks;
import vazkii.botania.common.item.CraftingPatternItem;

public class CraftyCratePatternDispenseBehavior extends OptionalDispenseItemBehavior {
	@NotNull
	@Override
	protected ItemStack execute(BlockSource source, ItemStack stack) {
		Level level = source.getLevel();
		Direction facing = level.getBlockState(source.getPos()).getValue(DispenserBlock.FACING);
		BlockPos pos = source.getPos().relative(facing);
		BlockState state = level.getBlockState(pos);
		CraftyCratePattern pattern = ((CraftingPatternItem) stack.getItem()).pattern;

		if (!state.is(BotaniaBlocks.craftCrate) || state.getValue(BotaniaStateProperties.CRATE_PATTERN) == pattern) {
			setSuccess(false);
		} else {
			level.setBlockAndUpdate(pos, state.setValue(BotaniaStateProperties.CRATE_PATTERN, pattern));
			setSuccess(true);
		}
		return stack;
	}
}
botania/patches/linux.yml: SUCCESS in 18m40s

[Make Crafty Crate pattern items usable in a dispenser][0] from [Vincent Lee][1]

[0]: https://lists.sr.ht/~williewillus/violet-moon/patches/45722
[1]: mailto:vincent@vincent-lee.net

✓ #1076186 SUCCESS botania/patches/linux.yml https://builds.sr.ht/~williewillus/job/1076186