Search in sources :

Example 66 with IBlockState

use of net.minecraft.block.state.IBlockState in project Railcraft by Railcraft.

the class TileTankWater method placeWaterTank.

public static void placeWaterTank(World world, BlockPos pos, int water) {
    MultiBlockPattern pattern = TileTankWater.patterns.get(0);
    Map<Character, IBlockState> blockMapping = new HashMap<Character, IBlockState>();
    blockMapping.put('B', EnumMachineAlpha.TANK_WATER.getDefaultState());
    TileEntity tile = pattern.placeStructure(world, pos, blockMapping);
    if (tile instanceof TileTankWater) {
        TileTankWater master = (TileTankWater) tile;
        master.tank.setFluid(Fluids.WATER.get(water));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) MultiBlockPattern(mods.railcraft.common.blocks.machine.MultiBlockPattern)

Example 67 with IBlockState

use of net.minecraft.block.state.IBlockState in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method breakAndUseEnergy.

/**
     * @return True if the break was successful, false otherwise
     */
@Nonnull
private BlockResult breakAndUseEnergy(@Nonnull World worldIn, @Nonnull BlockPos blockPos, @Nonnull IEnergyStorage energy, EntityPlayerMP player, int efficiency, int unbreaking) {
    IBlockState state = worldIn.getBlockState(blockPos);
    if (!player.capabilities.isCreativeMode) {
        float hardness = state.getBlockHardness(worldIn, blockPos);
        if (hardness < 0) {
            return BlockResult.FAIL_UNBREAKABLE;
        }
        float floatBreakCost = getBreakCost(hardness, efficiency, unbreaking, getDistance(player, blockPos));
        if (Float.isInfinite(floatBreakCost) || Float.isNaN(floatBreakCost))
            return BlockResult.FAIL_ENERGY;
        int breakCost = Math.round(floatBreakCost);
        if (breakCost < 0 || energy.getEnergyStored() < breakCost) {
            return BlockResult.FAIL_ENERGY;
        }
    }
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldIn, blockPos, state, player);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled())
        return BlockResult.FAIL_REMOVE;
    boolean result = PlayerInteractionUtil.tryHarvestBlock(player, worldIn, blockPos);
    return result ? BlockResult.SUCCESS : BlockResult.FAIL_REMOVE;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockEvent(net.minecraftforge.event.world.BlockEvent) Nonnull(javax.annotation.Nonnull)

Example 68 with IBlockState

use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.

the class TileEntitySprinkler method irrigate.

/**
     * Depending on the block type either irrigates farmland or forces plant
     * GROWTH (based on chance)
     */
private void irrigate(BlockPos pos, boolean farmlandOnly) {
    IBlockState state = this.getWorld().getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof BlockFarmland && block.getMetaFromState(state) < 7) {
        // irrigate farmland
        int flag = counter == 0 ? 2 : 6;
        worldObj.setBlockState(pos, block.getStateFromMeta(7), flag);
    } else if (!farmlandOnly && ((block instanceof IPlantable) || (block instanceof IGrowable))) {
        // X1 chance to force GROWTH tick on plant every Y1 ticks
        if (counter == 0 && worldObj.rand.nextDouble() <= AgriCraftConfig.sprinklerGrowthChancePercent) {
            block.updateTick(this.getWorld(), pos, state, worldObj.rand);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockFarmland(net.minecraft.block.BlockFarmland) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block)

Example 69 with IBlockState

use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.

the class CustomWoodType method getIcon.

@SideOnly(Side.CLIENT)
@Nonnull
public TextureAtlasSprite getIcon() {
    if (texture == null) {
        try {
            IBlockState state = block.getStateFromMeta(meta);
            texture = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);
        } catch (Exception e) {
            AgriCore.getLogger("agricraft").debug("Unable to load texture for custom wood block {0}!", block.getLocalizedName());
            AgriCore.getLogger("agricraft").trace(e);
            texture = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
        }
    }
    return texture;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 70 with IBlockState

use of net.minecraft.block.state.IBlockState in project Overloaded by CJ-MC-Mods.

the class PlayerInteractionUtil method tryHarvestBlock.

public static boolean tryHarvestBlock(EntityPlayerMP player, World world, BlockPos pos) {
    int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, player.interactionManager.getGameType(), player, pos);
    if (exp == -1) {
        return false;
    } else {
        IBlockState iblockstate = world.getBlockState(pos);
        TileEntity tileentity = world.getTileEntity(pos);
        Block block = iblockstate.getBlock();
        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
            world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
            return false;
        } else {
            world.playEvent(null, 2001, pos, Block.getStateId(iblockstate));
            boolean flag1;
            if (player.capabilities.isCreativeMode) {
                flag1 = removeBlock(world, pos, player, false);
                player.connection.sendPacket(new SPacketBlockChange(world, pos));
            } else {
                ItemStack itemstack1 = player.getHeldItemMainhand();
                ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                boolean flag = iblockstate.getBlock().canHarvestBlock(world, pos, player);
                itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                flag1 = removeBlock(world, pos, player, flag);
                if (flag1 && flag) {
                    iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                }
            }
            // Drop experience
            if (!player.isCreative() && flag1 && exp > 0) {
                iblockstate.getBlock().dropXpOnBlockBreak(world, player.getPosition(), exp);
            }
            return flag1;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) BlockStructure(net.minecraft.block.BlockStructure) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2979 BlockPos (net.minecraft.util.math.BlockPos)1194 Block (net.minecraft.block.Block)797 ItemStack (net.minecraft.item.ItemStack)517 EnumFacing (net.minecraft.util.EnumFacing)420 TileEntity (net.minecraft.tileentity.TileEntity)339 World (net.minecraft.world.World)255 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)171 EntityPlayer (net.minecraft.entity.player.EntityPlayer)136 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)126 ArrayList (java.util.ArrayList)125 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)121 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)95 Entity (net.minecraft.entity.Entity)94 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)93 ItemBlock (net.minecraft.item.ItemBlock)89 BlockPos (net.minecraft.util.BlockPos)84 Random (java.util.Random)82 Vec3d (net.minecraft.util.math.Vec3d)81 RayTraceResult (net.minecraft.util.math.RayTraceResult)76