~williewillus/violet-moon

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

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

Details
Message ID
<87cyxfadus.fsf@vincent-lee.net>
DKIM signature
missing
Download raw message
Patch: +47 -0
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] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CW99PYKK5ORA.2S1PWS82S3ECE@cirno2>
In-Reply-To
<87cyxfadus.fsf@vincent-lee.net> (view parent)
DKIM signature
missing
Download raw message
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]: vincent@vincent-lee.net

✓ #1076186 SUCCESS botania/patches/linux.yml https://builds.sr.ht/~williewillus/job/1076186
Reply to thread Export thread (mbox)