001/* 002 * This file is part of Baritone. 003 * 004 * Baritone is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Lesser General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * Baritone is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License 015 * along with Baritone. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package baritone.api.utils; 019 020import net.minecraft.block.Block; 021import net.minecraft.block.state.IBlockState; 022import net.minecraft.item.ItemStack; 023 024import java.util.Arrays; 025import java.util.List; 026import java.util.stream.Stream; 027 028public class BlockOptionalMetaLookup { 029 030 private final BlockOptionalMeta[] boms; 031 032 public BlockOptionalMetaLookup(BlockOptionalMeta... boms) { 033 this.boms = boms; 034 } 035 036 public BlockOptionalMetaLookup(Block... blocks) { 037 this.boms = Stream.of(blocks) 038 .map(BlockOptionalMeta::new) 039 .toArray(BlockOptionalMeta[]::new); 040 } 041 042 public BlockOptionalMetaLookup(List<Block> blocks) { 043 this.boms = blocks.stream() 044 .map(BlockOptionalMeta::new) 045 .toArray(BlockOptionalMeta[]::new); 046 } 047 048 public BlockOptionalMetaLookup(String... blocks) { 049 this.boms = Stream.of(blocks) 050 .map(BlockOptionalMeta::new) 051 .toArray(BlockOptionalMeta[]::new); 052 } 053 054 public boolean has(Block block) { 055 for (BlockOptionalMeta bom : boms) { 056 if (bom.getBlock() == block) { 057 return true; 058 } 059 } 060 061 return false; 062 } 063 064 public boolean has(IBlockState state) { 065 for (BlockOptionalMeta bom : boms) { 066 if (bom.matches(state)) { 067 return true; 068 } 069 } 070 071 return false; 072 } 073 074 public boolean has(ItemStack stack) { 075 for (BlockOptionalMeta bom : boms) { 076 if (bom.matches(stack)) { 077 return true; 078 } 079 } 080 081 return false; 082 } 083 084 public List<BlockOptionalMeta> blocks() { 085 return Arrays.asList(boms); 086 } 087 088 @Override 089 public String toString() { 090 return String.format( 091 "BlockOptionalMetaLookup{%s}", 092 Arrays.toString(boms) 093 ); 094 } 095}