Java Code Examples for net.minecraft.block.Block#getStateFromMeta()
The following examples show how to use
net.minecraft.block.Block#getStateFromMeta() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OreGenerator.java From EmergingTechnology with MIT License | 6 votes |
public void addOreSpawn(Block block, byte blockMeta, Block targetBlock, World world, Random random, int blockXPos, int blockZPos, int minVeinSize, int maxVeinSize, int chancesToSpawn, int minY, int maxY, boolean restrictBiome) { WorldGenMinable minable = new WorldGenMinable(block.getStateFromMeta(blockMeta), (minVeinSize + random.nextInt(maxVeinSize - minVeinSize + 1)), BlockStateMatcher.forBlock(targetBlock)); for (int i = 0; i < chancesToSpawn; i++) { int posX = blockXPos + random.nextInt(16); int posY = minY + random.nextInt(maxY - minY); int posZ = blockZPos + random.nextInt(16); BlockPos plannedPosition = new BlockPos(posX, posY, posZ); Biome blockBiome = world.getBiome(plannedPosition); for (Biome biome : validBiomes) { if (biome == blockBiome || !restrictBiome) { minable.generate(world, random, new BlockPos(posX, posY, posZ)); break; } } } }
Example 2
Source File: OreConfigUtils.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public static List<IBlockState> getOreDictBlocks(String oreDictName) { List<ItemStack> allOres = OreDictUnifier.getAllWithOreDictionaryName(oreDictName); ArrayList<IBlockState> allBlocks = new ArrayList<>(); for (ItemStack oreStack : allOres) { Block itemStackBlock = Block.getBlockFromItem(oreStack.getItem()); if (itemStackBlock == Blocks.AIR) continue; int placementMetadata = oreStack.getItem().getMetadata(oreStack.getMetadata()); IBlockState placementState = itemStackBlock.getStateFromMeta(placementMetadata); allBlocks.add(placementState); } if (allBlocks.isEmpty()) { throw new IllegalArgumentException("Couldn't find any blocks matching " + oreDictName + " oredict tag"); } return allBlocks; }
Example 3
Source File: TileEntityPhysicsInfuser.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@SideOnly(Side.CLIENT) public AxisAlignedBB getRenderBoundingBox() { // Use the tile entity specific methods here instead of World for consistency with other tile entities. Block blockType = getBlockType(); int blockMeta = getBlockMetadata(); // Only check this after we've gotten the block meta to avoid a data race. if (blockType instanceof BlockPhysicsInfuser) { IBlockState blockState = blockType.getStateFromMeta(blockMeta); EnumFacing sideFacing = ((BlockPhysicsInfuser) blockType) .getDummyStateFacing(blockState); // First make the aabb for the main block, then include the dummy block, then include the bits coming out the top. return new AxisAlignedBB(getPos()) .expand(-sideFacing.getXOffset(), -sideFacing.getYOffset(), -sideFacing.getZOffset()) .expand(0, .3, 0); } // Default in case broken. return super.getRenderBoundingBox(); }
Example 4
Source File: EntityBlock.java From OpenModsLib with MIT License | 6 votes |
@Override @SuppressWarnings("deprecation") protected void readEntityFromNBT(NBTTagCompound tag) { if (tag.hasKey(TAG_BLOCK_STATE_ID)) { final int blockStateId = tag.getInteger(TAG_BLOCK_STATE_ID); this.blockState = Block.getStateById(blockStateId); } else { int meta = tag.getByte(TAG_BLOCK_META) & 255; final ResourceLocation blockId = NbtUtils.readResourceLocation(tag.getCompoundTag(TAG_BLOCK_ID)); final Block block = Block.REGISTRY.getObject(blockId); this.blockState = block.getStateFromMeta(meta); } if (tag.hasKey(TAG_TILE_ENTITY, Constants.NBT.TAG_COMPOUND)) this.tileEntity = tag.getCompoundTag(TAG_TILE_ENTITY); else this.tileEntity = null; }
Example 5
Source File: SyncableBlockState.java From OpenModsLib with MIT License | 6 votes |
@SuppressWarnings("deprecation") @Override public void readFromNBT(NBTTagCompound nbt, String name) { state = Blocks.AIR.getDefaultState(); if (nbt.hasKey(name, Constants.NBT.TAG_COMPOUND)) { final NBTTagCompound tag = nbt.getCompoundTag(name); if (tag.hasKey(TAG_BLOCK_ID, Constants.NBT.TAG_STRING)) { final ResourceLocation blockId = new ResourceLocation(tag.getString(TAG_BLOCK_ID)); final Block block = Block.REGISTRY.getObject(blockId); int meta = tag.getByte(TAG_BLOCK_META) & 255; state = block.getStateFromMeta(meta); } } }
Example 6
Source File: FacadeHelper.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static IBlockState lookupBlockForItemUnsafe(ItemStack itemStack) { if (!(itemStack.getItem() instanceof ItemBlock)) { return null; } Block block = ((ItemBlock) itemStack.getItem()).getBlock(); int blockMetadata = itemStack.getItem().getMetadata(itemStack); try { return block.getStateFromMeta(blockMetadata); } catch (Throwable e) { return null; } }
Example 7
Source File: OreGenerator.java From YouTubeModdingTutorial with MIT License | 5 votes |
public void addOreSpawn(Block block, byte blockMeta, Block targetBlock, World world, Random random, int blockXPos, int blockZPos, int minVeinSize, int maxVeinSize, int chancesToSpawn, int minY, int maxY) { WorldGenMinable minable = new WorldGenMinable(block.getStateFromMeta(blockMeta), (minVeinSize + random.nextInt(maxVeinSize - minVeinSize + 1)), BlockMatcher.forBlock(targetBlock)); for (int i = 0 ; i < chancesToSpawn ; i++) { int posX = blockXPos + random.nextInt(16); int posY = minY + random.nextInt(maxY - minY); int posZ = blockZPos + random.nextInt(16); minable.generate(world, random, new BlockPos(posX, posY, posZ)); } }
Example 8
Source File: SchematicHelper.java From ForgeHax with MIT License | 5 votes |
@SubscribeEvent public void onRender(RenderEvent event) { if (!SchematicaHelper.isSchematicaPresent()) return; final ItemStack heldStack = MC.player.getHeldItemMainhand(); if (heldStack.isEmpty()) { return; } if (!(heldStack.getItem() instanceof ItemBlock)) { return; } final Block block = ((ItemBlock) heldStack.getItem()).getBlock(); final int metaData = heldStack.getMetadata(); // using metadata is gay and not 1.13 compatible but dont know a better way to get blockstate from itemstack final IBlockState heldBlockState = block.getStateFromMeta(metaData); getBlockPlacePos().ifPresent(pos -> getColor(pos, heldBlockState).ifPresent(color -> { event.getBuffer().begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); GlStateManager.glLineWidth(line_width.get()); GeometryTessellator.drawCuboid(event.getBuffer(), pos, GeometryMasks.Line.ALL, color); event.getTessellator().draw(); }) ); }
Example 9
Source File: BlockDrawingHelper.java From malmo with MIT License | 5 votes |
protected void DrawPrimitive( DrawSign s, World w ) throws Exception { String sType = s.getType().value(); BlockType bType = BlockType.fromValue(sType); // Safe - SignType is a subset of BlockType XMLBlockState blockType = new XMLBlockState(bType, s.getColour(), s.getFace(), s.getVariant()); BlockPos pos = new BlockPos( s.getX(), s.getY(), s.getZ() ); setBlockState(w, pos, blockType ); if (blockType.type == BlockType.STANDING_SIGN && s.getRotation() != null) { IBlockState placedBlockState = w.getBlockState(pos); if (placedBlockState != null) { Block placedBlock = placedBlockState.getBlock(); if (placedBlock != null) { IBlockState rotatedBlock = placedBlock.getStateFromMeta(s.getRotation()); w.setBlockState(pos, rotatedBlock); } } } TileEntity tileentity = w.getTileEntity(pos); if (tileentity instanceof TileEntitySign) { TileEntitySign sign = (TileEntitySign)tileentity; if (s.getLine1() != null) sign.signText[0] = new TextComponentString(s.getLine1()); if (s.getLine2() != null) sign.signText[1] = new TextComponentString(s.getLine2()); if (s.getLine3() != null) sign.signText[2] = new TextComponentString(s.getLine3()); if (s.getLine4() != null) sign.signText[3] = new TextComponentString(s.getLine4()); } }
Example 10
Source File: BarrelModeCompost.java From ExNihiloAdscensio with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Override public void readFromNBT(NBTTagCompound tag) { fillAmount = tag.getFloat("fillAmount"); this.color = new Color(tag.getInteger("color")); if (tag.hasKey("originalColor")) this.originalColor = new Color(tag.getInteger("originalColor")); this.progress = tag.getFloat("progress"); if (tag.hasKey("block")) { Block block = Block.REGISTRY.getObject(new ResourceLocation(tag.getString("block"))); compostState = block.getStateFromMeta(tag.getInteger("meta")); } }
Example 11
Source File: OreConfig.java From TFC2 with GNU General Public License v3.0 | 5 votes |
public OreConfig(VeinType v, Block b, int m, String ore, int wMin, int wMax, int hMin, int hMax) { state = b.getStateFromMeta(m); veinWidthMax = wMax; veinHeightMax = hMax; veinWidthMin = wMin; veinHeightMin = hMin; vType = v; oreName = ore; }
Example 12
Source File: NBTUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Nullable public static IBlockState readBlockStateFromTag(NBTTagCompound tag) { Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("name"))); if (block != null && block != Blocks.AIR) { return block.getStateFromMeta(tag.getByte("meta")); } return null; }
Example 13
Source File: BakedSmallVesselModel.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public static TextureAtlasSprite getTextureFromBlock(Block block, int meta) { IBlockState state = block.getStateFromMeta(meta); return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state); }
Example 14
Source File: BakedPitKilnModel.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public static TextureAtlasSprite getTextureFromBlock(Block block, int meta) { IBlockState state = block.getStateFromMeta(meta); return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state); }
Example 15
Source File: BakedAnvilModel.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public static TextureAtlasSprite getTextureFromBlock(Block block, int meta) { IBlockState state = block.getStateFromMeta(meta); return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state); }
Example 16
Source File: ItemDolly.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
private boolean tryPlaceDownBlock(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side) { pos = pos.offset(side); if (this.isCarryingBlock(stack) == false || world.isBlockModifiable(player, pos) == false) { return false; } NBTTagCompound tagCarrying = NBTUtils.getCompoundTag(stack, "Carrying", false); String name = tagCarrying.getString("Block"); int meta = tagCarrying.getByte("Meta"); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name)); try { if (block != null && block != Blocks.AIR && world.mayPlace(block, pos, false, side, player)) { @SuppressWarnings("deprecation") IBlockState state = block.getStateFromMeta(meta); EnumFacing pickupFacing = EnumFacing.byIndex(tagCarrying.getByte("PickupFacing")); EnumFacing currentFacing = EntityUtils.getHorizontalLookingDirection(player); Rotation rotation = PositionUtils.getRotation(pickupFacing, currentFacing); state = state.withRotation(rotation); if (world.setBlockState(pos, state)) { TileEntity te = world.getTileEntity(pos); if (te != null && tagCarrying.hasKey("te", Constants.NBT.TAG_COMPOUND)) { NBTTagCompound nbt = tagCarrying.getCompoundTag("te"); TileUtils.createAndAddTileEntity(world, pos, nbt, rotation, Mirror.NONE); } NBTUtils.removeCompoundTag(stack, null, "Carrying"); return true; } } } catch (Exception e) { EnderUtilities.logger.warn("Failed to place down a block from the Dolly", e); } return false; }