public static ItemStack getBannerItemFromBlock(World world, BlockPos pos) { IBlockState blockstate = world.getBlockState(pos); if (blockstate.getBlock() instanceof BlockBanner) { BlockBanner bannerblock = (BlockBanner) blockstate.getBlock(); return bannerblock.getItem(world, pos, blockstate); } return ItemStack.EMPTY; }
private boolean checkSupposedPoweredState() { final ItemStack filter = bannerInventory.getStackInSlot(0); IBlockState blockState = world.getBlockState(pos); EnumFacing facing = blockState.getValue(BlockBannerDetector.FACING); boolean detected = false; BlockPos lastPos = null; if(!filter.isEmpty() && filter.getItem() instanceof ItemBanner) { for (int i = 1; i <= maxdist; i++) { BlockPos nextPos = new BlockPos(pos.offset(facing, i)); lastPos = nextPos; if (world.isBlockLoaded(nextPos)) { IBlockState nextState = world.getBlockState(nextPos); if (nextState.isOpaqueCube()) break; detected = checkBanner(nextPos,filter,BlockBanner.class); if(!detected) detected = checkBanner(nextPos.up(), filter, BlockBanner.BlockBannerHanging.class); if(!detected) detected = checkBanner(nextPos.down(), filter, BlockBanner.BlockBannerStanding.class); if(detected) break; } } if (!detected && maxdist > 0) { List<Entity> entityList = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(this.pos, lastPos.add(1,1,1)), new Predicate<Entity>() { @Override public boolean apply(Entity input) { return BannerUtil.isSameBanner(filter, input); } }); detected = entityList != null && entityList.size() > 0; } } return detected; }
private boolean checkBanner(BlockPos pos, ItemStack filter, Class type) { IBlockState state = world.getBlockState(pos); if (type.isInstance(state.getBlock())) { BlockBanner bannerblock = (BlockBanner) state.getBlock(); ItemStack banner = bannerblock.getItem(world, pos, state); return BannerUtil.isSameBanner(filter,banner); } return false; }