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;
+ }
+}