Search in sources :

Example 1 with ClientboundWorldPositionInformationPacket

use of com.almuradev.almura.feature.complex.item.almanac.network.ClientboundWorldPositionInformationPacket in project Almura by AlmuraDev.

the class FarmersAlmanacItem method onItemUse.

@SuppressWarnings("ConstantConditions")
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        final Player spongePlayer = (Player) player;
        if (!spongePlayer.hasPermission("almura.item.farmers_almanac")) {
            spongePlayer.sendMessage(Text.of("Access denied, missing permission: ", TextColors.AQUA, "almura.item.farmers_" + "almanac", TextColors.WHITE, "."));
            return EnumActionResult.FAIL;
        }
        final Block block = world.getBlockState(pos).getBlock();
        if (block instanceof BlockFarmland | block instanceof BlockCrops) {
            final Biome biome = world.getBiome(pos);
            final float biomeTemperature = biome.getTemperature(pos);
            final float biomeRainfall = biome.getRainfall();
            final int blockLight = world.getLightFor(EnumSkyBlock.BLOCK, pos);
            final int skyLight = world.getLightFor(EnumSkyBlock.SKY, pos) - world.getSkylightSubtracted();
            player.swingArm(hand);
            network.sendTo(spongePlayer, new ClientboundWorldPositionInformationPacket(pos.getX(), pos.getY(), pos.getZ(), hitX, hitY, hitZ, biome.getRegistryName().toString(), biomeTemperature, biomeRainfall, blockLight, skyLight));
        } else {
            spongePlayer.sendMessage(Text.of("The ", TextColors.AQUA, "Farmer's Almanac", TextColors.WHITE, " can only be " + "used on crops or farmland."));
        }
    }
    return EnumActionResult.PASS;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ClientboundWorldPositionInformationPacket(com.almuradev.almura.feature.complex.item.almanac.network.ClientboundWorldPositionInformationPacket) BlockFarmland(net.minecraft.block.BlockFarmland) BlockCrops(net.minecraft.block.BlockCrops) Biome(net.minecraft.world.biome.Biome) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock)

Aggregations

ClientboundWorldPositionInformationPacket (com.almuradev.almura.feature.complex.item.almanac.network.ClientboundWorldPositionInformationPacket)1 Block (net.minecraft.block.Block)1 BlockCrops (net.minecraft.block.BlockCrops)1 BlockFarmland (net.minecraft.block.BlockFarmland)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumSkyBlock (net.minecraft.world.EnumSkyBlock)1 Biome (net.minecraft.world.biome.Biome)1 Player (org.spongepowered.api.entity.living.player.Player)1