Made the altar oredict-based

Closes #10
This commit is contained in:
Ellpeck 2018-11-17 21:31:57 +01:00
parent 0a53d0b824
commit 4e7b46c526
2 changed files with 33 additions and 12 deletions

View file

@ -3,12 +3,16 @@ package de.ellpeck.naturesaura.blocks.multi;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import vazkii.patchouli.api.PatchouliAPI; import vazkii.patchouli.api.PatchouliAPI;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -94,14 +98,14 @@ public class Multiblock {
Matcher matcher = matchers.get(this.rawPattern[x][y][z]); Matcher matcher = matchers.get(this.rawPattern[x][y][z]);
if (matcher == null) if (matcher == null)
throw new IllegalStateException(); throw new IllegalStateException();
if (!matcher.isWildcard) if (matcher.check != null)
this.matchers.put(new BlockPos(x, y, z), matcher); this.matchers.put(new BlockPos(x, y, z), matcher);
} }
for (int i = 1; i < rawMatchers.length; i += 2) { for (int i = 1; i < rawMatchers.length; i += 2) {
if (rawMatchers[i] instanceof Matcher) { if (rawMatchers[i] instanceof Matcher) {
Matcher matcher = (Matcher) rawMatchers[i]; Matcher matcher = (Matcher) rawMatchers[i];
if (matcher.isWildcard) if (matcher.check == null)
rawMatchers[i] = PatchouliAPI.instance.anyMatcher(); rawMatchers[i] = PatchouliAPI.instance.anyMatcher();
else else
rawMatchers[i] = PatchouliAPI.instance.predicateMatcher(matcher.defaultState, rawMatchers[i] = PatchouliAPI.instance.predicateMatcher(matcher.defaultState,
@ -144,18 +148,10 @@ public class Multiblock {
public final IBlockState defaultState; public final IBlockState defaultState;
public final IMatcher check; public final IMatcher check;
public final boolean isWildcard;
public Matcher(IBlockState defaultState, IMatcher check) { public Matcher(IBlockState defaultState, IMatcher check) {
this.defaultState = defaultState; this.defaultState = defaultState;
this.check = check; 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) { public static Matcher state(IBlockState state) {
@ -169,7 +165,32 @@ public class Multiblock {
} }
public static Matcher wildcard() { 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<IBlockState> 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);
}
});
} }
} }

View file

@ -21,7 +21,7 @@ public final class Multiblocks {
{" ", " WBW ", " WBW ", " WWCWCWW ", " BBW WBB ", " WWCWCWW ", " WBW ", " WBW ", " "}}, {" ", " WBW ", " WBW ", " WWCWCWW ", " BBW WBB ", " WWCWCWW ", " WBW ", " WBW ", " "}},
'C', Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.CHISELED), 'C', Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.CHISELED),
'B', Blocks.STONEBRICK.getDefaultState(), 'B', Blocks.STONEBRICK.getDefaultState(),
'W', Blocks.PLANKS, 'W', Matcher.oreDict(Blocks.PLANKS, "plankWood"),
'M', Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.MOSSY), 'M', Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.MOSSY),
'0', ModBlocks.NATURE_ALTAR, '0', ModBlocks.NATURE_ALTAR,
' ', Matcher.wildcard()); ' ', Matcher.wildcard());