Search in sources :

Example 91 with IBlockState

use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.

the class ItemCoresample method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (player.isSneaking()) {
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        if (!block.isReplaceable(world, pos))
            pos = pos.offset(side);
        if (stack.stackSize != 0 && player.canPlayerEdit(pos, side, stack) && world.canBlockBePlaced(IEContent.blockStoneDevice, pos, false, side, null, stack)) {
            IBlockState toolbox = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.CORESAMPLE.getMeta());
            if (world.setBlockState(pos, toolbox, 3)) {
                IEContent.blockStoneDevice.onIEBlockPlacedBy(world, pos, toolbox, side, hitX, hitY, hitZ, player, stack);
                SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
                world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                --stack.stackSize;
            }
            return EnumActionResult.SUCCESS;
        } else
            return EnumActionResult.FAIL;
    }
    return super.onItemUse(stack, player, world, pos, hand, side, hitX, hitY, hitZ);
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block)

Example 92 with IBlockState

use of net.minecraft.block.state.IBlockState in project NetherEx by LogicTechCorp.

the class EntityObsidianBoat method getBoatGlide.

@Override
public float getBoatGlide() {
    AxisAlignedBB entityBoundingBox = getEntityBoundingBox();
    AxisAlignedBB boundingBox = new AxisAlignedBB(entityBoundingBox.minX, entityBoundingBox.minY - 0.001D, entityBoundingBox.minZ, entityBoundingBox.maxX, entityBoundingBox.minY, entityBoundingBox.maxZ);
    int i = MathHelper.floor(boundingBox.minX) - 1;
    int j = MathHelper.ceil(boundingBox.maxX) + 1;
    int k = MathHelper.floor(boundingBox.minY) - 1;
    int l = MathHelper.ceil(boundingBox.maxY) + 1;
    int i1 = MathHelper.floor(boundingBox.minZ) - 1;
    int j1 = MathHelper.ceil(boundingBox.maxZ) + 1;
    List<AxisAlignedBB> list = Lists.newArrayList();
    float f = 0.0F;
    int k1 = 0;
    BlockPos.PooledMutableBlockPos mutableBlockPos = BlockPos.PooledMutableBlockPos.retain();
    try {
        for (int l1 = i; l1 < j; ++l1) {
            for (int i2 = i1; i2 < j1; ++i2) {
                int j2 = (l1 != i && l1 != j - 1 ? 0 : 1) + (i2 != i1 && i2 != j1 - 1 ? 0 : 1);
                if (j2 != 2) {
                    for (int k2 = k; k2 < l; ++k2) {
                        if (j2 <= 0 || k2 != k && k2 != l - 1) {
                            mutableBlockPos.setPos(l1, k2, i2);
                            IBlockState state = world.getBlockState(mutableBlockPos);
                            state.addCollisionBoxToList(world, mutableBlockPos, boundingBox, list, this, false);
                            if (!list.isEmpty()) {
                                f += state.getBlock().slipperiness;
                                ++k1;
                            }
                            list.clear();
                        }
                    }
                }
            }
        }
    } finally {
        mutableBlockPos.release();
    }
    return f / (float) k1;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Example 93 with IBlockState

use of net.minecraft.block.state.IBlockState in project NetherEx by LogicTechCorp.

the class EventHandler method onCropPreGrow.

@SubscribeEvent
public static void onCropPreGrow(BlockEvent.CropGrowEvent.Pre event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getState();
    if (ConfigHandler.block.soulSand.doesNetherwartUseNewGrowthSystem && state.getBlock() == Blocks.NETHER_WART) {
        if (world.getBlockState(pos.down()) == NetherExBlocks.BLOCK_SAND_SOUL_TILLED.getDefaultState().withProperty(BlockTilledSoulSand.MOISTURE, 7)) {
            event.setResult(Event.Result.ALLOW);
        } else {
            event.setResult(Event.Result.DENY);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 94 with IBlockState

use of net.minecraft.block.state.IBlockState in project NetherEx by LogicTechCorp.

the class EventHandler method onBoneMealUse.

@SubscribeEvent
public static void onBoneMealUse(BonemealEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getBlock();
    EntityPlayer player = event.getEntityPlayer();
    if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == NetherExItems.ITEM_DUST_WITHER) {
        if (state.getBlock() == Blocks.NETHER_WART) {
            int age = state.getValue(BlockNetherWart.AGE);
            if (age < 3) {
                state = state.withProperty(BlockNetherWart.AGE, age + 1);
                world.setBlockState(pos, state);
                event.setResult(Event.Result.ALLOW);
            }
        } else if (state.getBlock() instanceof IGrowable) {
            IGrowable growable = (IGrowable) state.getBlock();
            if (growable.canGrow(world, pos, state, world.isRemote)) {
                growable.grow(world, world.rand, pos, state);
            }
        } else {
            event.setCanceled(true);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 95 with IBlockState

use of net.minecraft.block.state.IBlockState in project NetherEx by LogicTechCorp.

the class EventHandler method onBlockBreak.

@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getState();
    if (!(event.getPlayer() instanceof FakePlayer)) {
        EntityPlayer player = event.getPlayer();
        if (state.getBlock() == Blocks.MAGMA) {
            if (ConfigHandler.block.magma.turnIntoLava) {
                if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) == 0) {
                    world.setBlockState(pos, Blocks.LAVA.getDefaultState(), 3);
                    player.getHeldItemMainhand().damageItem(1, player);
                    event.setCanceled(true);
                }
            }
        }
        if (player.dimension == -1) {
            boolean canSpawn = Arrays.asList(ConfigHandler.entity.nethermite.whitelist).contains(state.getBlock().getRegistryName().toString());
            if (canSpawn && world.rand.nextInt(ConfigHandler.entity.nethermite.chanceOfSpawning) == 0) {
                EntityNethermite nethermite = new EntityNethermite(world);
                nethermite.setPosition((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D);
                world.spawnEntity(nethermite);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityNethermite(nex.entity.monster.EntityNethermite) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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