Search in sources :

Example 1 with PacketFXSignal

use of forestry.core.network.packets.PacketFXSignal in project ForestryMC by ForestryMC.

the class TreeRoot method plantSapling.

@Override
public boolean plantSapling(World world, ITree tree, GameProfile owner, BlockPos pos) {
    BlockRegistryArboriculture blocks = ModuleArboriculture.getBlocks();
    IBlockState state = blocks.saplingGE.getDefaultState().withProperty(BlockSapling.TREE, tree.getGenome().getPrimary());
    boolean placed = world.setBlockState(pos, state);
    if (!placed) {
        return false;
    }
    IBlockState blockState = world.getBlockState(pos);
    Block block = blockState.getBlock();
    if (blocks.saplingGE != block) {
        return false;
    }
    TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
    if (sapling == null) {
        world.setBlockToAir(pos);
        return false;
    }
    sapling.setTree(tree.copy());
    sapling.getOwnerHandler().setOwner(owner);
    PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState);
    NetworkUtil.sendNetworkPacket(packet, pos, world);
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockRegistryArboriculture(forestry.arboriculture.blocks.BlockRegistryArboriculture) Block(net.minecraft.block.Block) PacketFXSignal(forestry.core.network.packets.PacketFXSignal) TileSapling(forestry.arboriculture.tiles.TileSapling)

Example 2 with PacketFXSignal

use of forestry.core.network.packets.PacketFXSignal in project ForestryMC by ForestryMC.

the class ItemButterflyGE method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    ItemStack stack = player.getHeldItem(hand);
    IButterfly flutter = ButterflyManager.butterflyRoot.getMember(stack);
    IBlockState blockState = world.getBlockState(pos);
    if (type == EnumFlutterType.COCOON) {
        pos = ButterflyManager.butterflyRoot.plantCocoon(world, pos, flutter, player.getGameProfile(), getAge(stack), true);
        if (pos != BlockPos.ORIGIN) {
            PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, world.getBlockState(pos));
            NetworkUtil.sendNetworkPacket(packet, pos, world);
            if (!player.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.PASS;
        }
    } else if (type == EnumFlutterType.CATERPILLAR) {
        IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(player.getGameProfile(), world, pos, true);
        if (nursery != null) {
            if (!nursery.canNurse(flutter)) {
                return EnumActionResult.PASS;
            }
            nursery.setCaterpillar(flutter);
            PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
            NetworkUtil.sendNetworkPacket(packet, pos, world);
            if (!player.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    } else {
        return EnumActionResult.PASS;
    }
}
Also used : IButterflyNursery(forestry.api.lepidopterology.IButterflyNursery) IButterfly(forestry.api.lepidopterology.IButterfly) IBlockState(net.minecraft.block.state.IBlockState) PacketFXSignal(forestry.core.network.packets.PacketFXSignal) ItemStack(net.minecraft.item.ItemStack)

Example 3 with PacketFXSignal

use of forestry.core.network.packets.PacketFXSignal in project ForestryMC by ForestryMC.

the class CropBasicGrowthCraft method harvestBlock.

@Override
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
    Block block = blockState.getBlock();
    NonNullList<ItemStack> harvest = NonNullList.create();
    harvest.addAll(block.getDrops(world, pos, blockState, 0));
    if (harvest.size() > 1) {
        // Hops have rope as first drop.
        harvest.remove(0);
    }
    PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
    NetworkUtil.sendNetworkPacket(packet, pos, world);
    if (isGrape) {
        world.setBlockToAir(pos);
    } else {
        world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNC);
    }
    if (isRice) {
        // TODO: GrowthCraft for MC 1.9. Don't use meta, get the actual block state.
        world.setBlockState(pos.down(), block.getStateFromMeta(7), Constants.FLAG_BLOCK_SYNC);
    }
    return harvest;
}
Also used : Block(net.minecraft.block.Block) PacketFXSignal(forestry.core.network.packets.PacketFXSignal) ItemStack(net.minecraft.item.ItemStack)

Example 4 with PacketFXSignal

use of forestry.core.network.packets.PacketFXSignal in project ForestryMC by ForestryMC.

the class CropDestroy method harvestBlock.

@Override
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
    Block block = blockState.getBlock();
    NonNullList<ItemStack> harvested = NonNullList.create();
    harvested.addAll(block.getDrops(world, pos, blockState, 0));
    float chance = ForgeEventFactory.fireBlockHarvesting(harvested, world, pos, blockState, 0, 1.0F, false, null);
    boolean removedSeed = germling.isEmpty();
    Iterator<ItemStack> dropIterator = harvested.iterator();
    while (dropIterator.hasNext()) {
        ItemStack next = dropIterator.next();
        if (world.rand.nextFloat() <= chance) {
            if (!removedSeed && ItemStackUtil.isIdenticalItem(next, germling)) {
                next.shrink(1);
                if (next.isEmpty()) {
                    dropIterator.remove();
                }
                removedSeed = true;
            }
        } else {
            dropIterator.remove();
        }
    }
    PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
    NetworkUtil.sendNetworkPacket(packet, pos, world);
    if (replantState != null) {
        world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC);
    } else {
        world.setBlockToAir(pos);
    }
    return harvested;
}
Also used : Block(net.minecraft.block.Block) PacketFXSignal(forestry.core.network.packets.PacketFXSignal) ItemStack(net.minecraft.item.ItemStack)

Example 5 with PacketFXSignal

use of forestry.core.network.packets.PacketFXSignal in project ForestryMC by ForestryMC.

the class FarmableRusticSapling method plantSaplingAt.

@Override
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
    if (world.setBlockState(pos, germlingBlock.getStateFromMeta(germling.getItemDamage()))) {
        PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, germlingBlock.getStateFromMeta(germling.getItemDamage()));
        NetworkUtil.sendNetworkPacket(packet, pos, world);
        return true;
    }
    return false;
}
Also used : PacketFXSignal(forestry.core.network.packets.PacketFXSignal)

Aggregations

PacketFXSignal (forestry.core.network.packets.PacketFXSignal)15 ItemStack (net.minecraft.item.ItemStack)8 IBlockState (net.minecraft.block.state.IBlockState)5 Block (net.minecraft.block.Block)4 EnumActionResult (net.minecraft.util.EnumActionResult)2 ICheckPollinatable (forestry.api.genetics.ICheckPollinatable)1 IFruitBearer (forestry.api.genetics.IFruitBearer)1 IPollinatable (forestry.api.genetics.IPollinatable)1 IButterfly (forestry.api.lepidopterology.IButterfly)1 IButterflyNursery (forestry.api.lepidopterology.IButterflyNursery)1 BlockRegistryArboriculture (forestry.arboriculture.blocks.BlockRegistryArboriculture)1 TileSapling (forestry.arboriculture.tiles.TileSapling)1 ActionResult (net.minecraft.util.ActionResult)1