From 4e7b46c5268636f25062dca046adeff088bd7c9c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 17 Nov 2018 21:31:57 +0100 Subject: [PATCH] Made the altar oredict-based Closes #10 --- .../naturesaura/blocks/multi/Multiblock.java | 43 ++++++++++++++----- .../naturesaura/blocks/multi/Multiblocks.java | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblock.java b/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblock.java index 9021064c..30644298 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblock.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblock.java @@ -3,12 +3,16 @@ package de.ellpeck.naturesaura.blocks.multi; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; import vazkii.patchouli.api.PatchouliAPI; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.BiFunction; @@ -94,14 +98,14 @@ public class Multiblock { Matcher matcher = matchers.get(this.rawPattern[x][y][z]); if (matcher == null) throw new IllegalStateException(); - if (!matcher.isWildcard) + if (matcher.check != null) this.matchers.put(new BlockPos(x, y, z), matcher); } for (int i = 1; i < rawMatchers.length; i += 2) { if (rawMatchers[i] instanceof Matcher) { Matcher matcher = (Matcher) rawMatchers[i]; - if (matcher.isWildcard) + if (matcher.check == null) rawMatchers[i] = PatchouliAPI.instance.anyMatcher(); else rawMatchers[i] = PatchouliAPI.instance.predicateMatcher(matcher.defaultState, @@ -144,18 +148,10 @@ public class Multiblock { public final IBlockState defaultState; public final IMatcher check; - public final boolean isWildcard; public Matcher(IBlockState defaultState, IMatcher check) { this.defaultState = defaultState; this.check = check; - this.isWildcard = false; - } - - public Matcher(IBlockState defaultState) { - this.defaultState = defaultState; - this.check = null; - this.isWildcard = true; } public static Matcher state(IBlockState state) { @@ -169,7 +165,32 @@ public class Multiblock { } public static Matcher wildcard() { - return new Matcher(Blocks.AIR.getDefaultState()); + return new Matcher(Blocks.AIR.getDefaultState(), null); + } + + public static Matcher oreDict(Block defaultBlock, String name) { + return new Matcher(defaultBlock.getDefaultState(), new IMatcher() { + private List states; + + @Override + public boolean matches(World world, BlockPos start, BlockPos offset, BlockPos pos, IBlockState state, char c) { + if (this.states == null) { + this.states = new ArrayList<>(); + for (ItemStack stack : OreDictionary.getOres(name)) { + Block block = Block.getBlockFromItem(stack.getItem()); + if (block != null && block != Blocks.AIR) { + int damage = stack.getItemDamage(); + if (damage == OreDictionary.WILDCARD_VALUE) + this.states.addAll(block.getBlockState().getValidStates()); + else + this.states.add(block.getStateFromMeta(damage)); + } + } + } + + return this.states.isEmpty() || this.states.contains(state); + } + }); } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblocks.java index 0824940f..710938a4 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblocks.java @@ -21,7 +21,7 @@ public final class Multiblocks { {" ", " WBW ", " WBW ", " WWCWCWW ", " BBW WBB ", " WWCWCWW ", " WBW ", " WBW ", " "}}, 'C', Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.CHISELED), 'B', Blocks.STONEBRICK.getDefaultState(), - 'W', Blocks.PLANKS, + 'W', Matcher.oreDict(Blocks.PLANKS, "plankWood"), 'M', Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.MOSSY), '0', ModBlocks.NATURE_ALTAR, ' ', Matcher.wildcard());