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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations