@Override public IBlockState getTextureBlockState( ItemStack is ) { ItemStack baseItemStack = this.getTextureItem( is ); if( baseItemStack.isEmpty() ) { return Blocks.GLASS.getDefaultState(); } Block block = Block.getBlockFromItem( baseItemStack.getItem() ); if( block == Blocks.AIR ) { return Blocks.GLASS.getDefaultState(); } int metadata = baseItemStack.getItem().getMetadata( baseItemStack ); try { return block.getStateFromMeta( metadata ); } catch( Exception e ) { AELog.warn( "Block %s has broken getStateFromMeta method for meta %d", block.getRegistryName().toString(), baseItemStack.getItemDamage() ); return Blocks.GLASS.getDefaultState(); } }
@Override public int damageDropped(IBlockState state) { return state.getBlock().getMetaFromState(state); }
private boolean canReplace( World w, IBlockState state, Block block, BlockPos pos ) { return block.isReplaceable( w, pos ) && !( block instanceof IFluidBlock ) && !( block instanceof BlockLiquid ) && !state.getMaterial().isLiquid(); }
@Override public Map<String, ? extends Property<?>> getProperties(BlockType blockType) { Map<String, Property<?>> map = new TreeMap<>(); Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId()) .getDefaultState() .getPropertyKeys(); for (IProperty<?> key : propertyKeys) { map.put(key.getName(), ForgeAdapter.adaptProperty(key)); } return map; }
BlockPos pos = new BlockPos(x, y, z); IBlockState old = chunk.getBlockState(pos); Block mcBlock = Block.getBlockFromName(block.getBlockType().getId()); IBlockState newState = mcBlock.getDefaultState(); Map<Property<?>, Object> states = block.getStates(); newState = applyProperties(mcBlock.getBlockState(), newState, states); IBlockState successState = chunk.setBlockState(pos, newState); boolean successful = successState != null;
protected void placeTrunk(World world, BlockPos pos, int height) { while(height >= 0) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos)) { this.setBlockAndMetadata(world, pos, log); } pos = pos.up(); height--; } }
final Block block = Block.getBlockFromItem( itemStack.getItem() ); if( block == Blocks.AIR || itemStack.hasTagCompound() ) try blockState = block.getStateFromMeta( metadata ); AELog.debug( e, "Cannot create a facade for " + block.getRegistryName() ); return ItemStack.EMPTY; final boolean isModel = blockState.getRenderType() == EnumBlockRenderType.MODEL; final IBlockState defaultState = block.getDefaultState(); final boolean isTileEntity = block.hasTileEntity( defaultState ); final boolean isFullCube = block.isFullCube( defaultState );
else if(Item.getItemFromBlock(state.getBlock()) == Items.AIR) continue; int[] ids = OreDictionary.getOreIDs(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state))); for(int id : ids) if(validBlocks.contains(OreDictionary.getOreName(id))) { BlockPos pos_ = pos.offset(dir); Block block_ = world.getBlockState(pos_).getBlock(); if(block_.isAir(world.getBlockState(pos_), world, pos_) || block_.isReplaceable(world, pos_) || block_ instanceof BlockFlower && !(block_ instanceof ISpecialFlower) || block_ == Blocks.DOUBLE_PLANT) { airBlocks.add(pos_); if(!world.isRemote) for(CoordsWithBlock block : blocks) world.setBlockState(block, block.block.getDefaultState());
public InWorldToolOperationIngredient( final Block blk, final boolean b ) { this.state = blk.getDefaultState(); this.blockOnly = b; }
protected void imc(Block block) { if(block != null) { FMLInterModComms.sendMessage(modid, "ignoreblocklogic", block.getRegistryName()); } } }
final RayTraceResult mop = block.collisionRayTrace( world.getBlockState( pos ), world, pos, dir.getA(), dir.getB() ); final RayTraceResult mop = block.collisionRayTrace( world.getBlockState( pos ), world, pos, dir.getA(), dir.getB() ); if( blkID != null && !blkID.isReplaceable( world, pos ) ) final boolean canMultiPartBePlaced = maybeMultiPartBlock.get().canPlaceBlockAt( world, te_pos ); world, te_pos, side, 0.5f, 0.5f, 0.5f, maybeMultiPartBlock.get().getDefaultState() ) ) if( blkID == null || blkID.isReplaceable( world, te_pos ) || host != null ) final RayTraceResult mop = state.getBlock().collisionRayTrace( state, world, pos, dir.getA(), dir.getB() ); final SoundType ss = multiPartBlock.getSoundType( state, world, pos, player );
IBlockState state = world.getBlockState(pos_); Block block = state.getBlock(); if(!block.isAir(state, world, pos_) && !block.isReplaceable(world, pos_) && !(block instanceof BlockFalling) && (!(block instanceof ILaputaImmobile) || ((ILaputaImmobile) block).canMove(world, pos_)) && state.getBlockHardness(world, pos_) != -1) { TileEntity tile = world.getTileEntity(pos_); TileEntity newTile = block.createTileEntity(world, state); world.setTileEntity(pos_, newTile); world.playEvent(2001, pos_, Block.getStateId(state)); ItemNBTHelper.setInt(copyLens, TAG_META, block.getMetaFromState(state)); NBTTagCompound cmp = new NBTTagCompound(); if(tile != null)
@Override public void onUpdate() { super.onUpdate(); if(supertile.getWorld().isRemote || redstoneSignal > 0) return; if(ticksExisted % 30 == 0 && mana >= COST) { BlockPos pos = new BlockPos( supertile.getPos().getX() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1), supertile.getPos().getY() + RANGE, supertile.getPos().getZ() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1) ); BlockPos up = pos.up(); for(int i = 0; i < RANGE * 2; i++) { IBlockState stateAbove = supertile.getWorld().getBlockState(up); Block blockAbove = stateAbove.getBlock(); if((supertile.getWorld().isAirBlock(up) || blockAbove.isReplaceable(supertile.getWorld(), up)) && stateAbove.getMaterial() != Material.WATER && ModBlocks.flower.canPlaceBlockAt(supertile.getWorld(), up)) { EnumDyeColor color = EnumDyeColor.byMetadata(supertile.getWorld().rand.nextInt(16)); IBlockState state = ModBlocks.flower.getDefaultState().withProperty(BotaniaStateProps.COLOR, color); if(ConfigHandler.blockBreakParticles) supertile.getWorld().playEvent(2001, up, Block.getStateId(state)); supertile.getWorld().setBlockState(up, state, 1 | 2); mana -= COST; sync(); break; } up = pos; pos = pos.down(); } } }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); if(!entity.world.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit); Block blockAt = entity.world.getBlockState(pos.getBlockPos()).getBlock(); Block blockAt_ = entity.world.getBlockState(pos_).getBlock(); if(blockAt == ModBlocks.manaFlame) entity.world.setBlockState(pos.getBlockPos(), Blocks.AIR.getDefaultState()); else if(blockAt_.isAir(entity.world.getBlockState(pos_), entity.world, pos_) || blockAt_.isReplaceable(entity.world, pos_)) { entity.world.setBlockState(pos_, ModBlocks.manaFlame.getDefaultState()); TileEntity tile = entity.world.getTileEntity(pos_); if(tile instanceof TileManaFlame) ((TileManaFlame) tile).setColor(burst.getColor()); } } return dead; }
@Override public final @Nonnull <B extends Block> B apply(@Nonnull B blockIn) { blockIn.setUnlocalizedName(getUnlocalisedName()); blockIn.setRegistryName(getRegistryName()); return blockIn; }
if(side != EnumFacing.DOWN && world.getBlockState(pos.up()).getBlock().isAir(world.getBlockState(pos.up()), world, pos.up()) && (block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.GRASS_PATH)) { Block block1 = Blocks.GRASS_PATH; if(block == block1) block1 = Blocks.FARMLAND; world.playSound(null, pos, block1.getSoundType().getStepSound(), SoundCategory.BLOCKS, (block1.getSoundType().getVolume() + 1.0F) / 2.0F, block1.getSoundType().getPitch() * 0.8F); world.setBlockState(pos, block1.getDefaultState()); ToolCommons.damageItem(stack, 1, player, MANA_PER_DAMAGE); return EnumActionResult.SUCCESS;
@Override public void onAvatarUpdate(IAvatarTile tile, ItemStack stack) { TileEntity te = (TileEntity) tile; World world = te.getWorld(); if(!world.isRemote && tile.getCurrentMana() >= COST && tile.getElapsedFunctionalTicks() % 4 == 0 && world.rand.nextInt(8) == 0 && tile.isEnabled()) { BlockPos pos = ((TileEntity) tile).getPos().offset(tile.getAvatarFacing()); IBlockState state = world.getBlockState(pos); if(state.getBlock().isAir(state, world, pos)) { world.setBlockState(pos, Blocks.DIRT.getDefaultState()); world.playEvent(2001, pos, Block.getStateId(Blocks.DIRT.getDefaultState())); tile.recieveMana(-COST); } } }
public PureDaisyRecipeWrapper(RecipePureDaisy recipe) { if(recipe.getInput() instanceof String) { inputs = ImmutableList.copyOf(OreDictionary.getOres((String) recipe.getInput())); } else if(recipe.getInput() instanceof Block || recipe.getInput() instanceof IBlockState) { IBlockState state = recipe.getInput() instanceof IBlockState ? (IBlockState) recipe.getInput() : ((Block) recipe.getInput()).getDefaultState(); Block b = state.getBlock(); if(FluidRegistry.lookupFluidForBlock(b) != null) { fluidInput = new FluidStack(FluidRegistry.lookupFluidForBlock(b), 1000); } else { inputs = ImmutableList.of(new ItemStack(b, 1, b.getMetaFromState(state))); } } Block outBlock = recipe.getOutputState().getBlock(); if(FluidRegistry.lookupFluidForBlock(outBlock) != null) { fluidOutput = new FluidStack(FluidRegistry.lookupFluidForBlock(outBlock), 1000); } else { output = new ItemStack(outBlock, 1, outBlock.getMetaFromState(recipe.getOutputState())); } }
public ToolEntropyManipulator() { super( AEConfig.instance().getEntropyManipulatorBattery() ); this.heatUp = new HashMap<>(); this.coolDown = new HashMap<>(); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.STONE.getDefaultState() ), new InWorldToolOperationResult( Blocks.COBBLESTONE.getDefaultState() ) ); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.STONEBRICK.getDefaultState() ), new InWorldToolOperationResult( Blocks.STONEBRICK.getStateFromMeta( 2 ) ) ); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.LAVA, true ), new InWorldToolOperationResult( Blocks.OBSIDIAN.getDefaultState() ) ); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.FLOWING_LAVA, true ), new InWorldToolOperationResult( Blocks.OBSIDIAN.getDefaultState() ) ); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.GRASS, true ), new InWorldToolOperationResult( Blocks.DIRT.getDefaultState() ) ); final List<ItemStack> snowBalls = new ArrayList<>(); snowBalls.add( new ItemStack( Items.SNOWBALL ) ); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.FLOWING_WATER, true ), new InWorldToolOperationResult( null, snowBalls ) ); this.coolDown.put( new InWorldToolOperationIngredient( Blocks.WATER, true ), new InWorldToolOperationResult( Blocks.ICE.getDefaultState() ) ); this.heatUp.put( new InWorldToolOperationIngredient( Blocks.ICE.getDefaultState() ), new InWorldToolOperationResult( Blocks.WATER.getDefaultState() ) ); this.heatUp.put( new InWorldToolOperationIngredient( Blocks.FLOWING_WATER, true ), new InWorldToolOperationResult() ); this.heatUp.put( new InWorldToolOperationIngredient( Blocks.WATER, true ), new InWorldToolOperationResult() ); this.heatUp.put( new InWorldToolOperationIngredient( Blocks.SNOW, true ), new InWorldToolOperationResult( Blocks.FLOWING_WATER.getStateFromMeta( 7 ) ) ); }
public static InWorldToolOperationResult getBlockOperationResult( final ItemStack[] items ) { final List<ItemStack> temp = new ArrayList<>(); IBlockState b = null; for( final ItemStack l : items ) { if( b == null ) { final Block bl = Block.getBlockFromItem( l.getItem() ); if( bl != null && !( bl instanceof BlockAir ) ) { b = bl.getDefaultState(); continue; } } temp.add( l ); } return new InWorldToolOperationResult( b, temp ); }